Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def destroyFavorite(self, id):
if self.authenticated is True:
try:
return simplejson.load(self.opener.open("http://twitter.com/favorites/destroy/" + id + ".json", ""))
except HTTPError, e:
raise TangoError("destroyFavorite() failed with a %s error code." % `e.code`, e.code)
else:
raise TangoError("destroyFavorite() requires you to be authenticated.")
def destroyDirectMessage(self, id):
if self.authenticated is True:
try:
return self.opener.open("http://twitter.com/direct_messages/destroy/%s.json" % id, "")
except HTTPError, e:
raise TangoError("destroyDirectMessage() failed with a %s error code." % `e.code`, e.code)
else:
raise TangoError("You must be authenticated to destroy a direct message.")
def getSavedSearches(self):
if self.authenticated is True:
try:
return simplejson.load(self.opener.open("http://twitter.com/saved_searches.json"))
except HTTPError, e:
raise TangoError("getSavedSearches() failed with a %s error code." % `e.code`, e.code)
else:
raise TangoError("getSavedSearches() requires you to be authenticated.")
def getPublicTimeline(self):
try:
return simplejson.load(urllib2.urlopen("http://twitter.com/statuses/public_timeline.json"))
except HTTPError, e:
raise TangoError("getPublicTimeline() failed with a %s error code." % `e.code`)
def updateProfileBackgroundImage(self, filename, tile="true"):
if self.authenticated is True:
try:
files = [("image", filename, open(filename).read())]
fields = []
content_type, body = self.encode_multipart_formdata(fields, files)
headers = {'Content-Type': content_type, 'Content-Length': str(len(body))}
r = urllib2.Request("http://twitter.com/account/update_profile_background_image.json?tile=" + tile, body, headers)
return self.opener.open(r).read()
except HTTPError, e:
raise TangoError("updateProfileBackgroundImage() failed with a %s error code." % `e.code`, e.code)
else:
raise TangoError("You realize you need to be authenticated to change a background image, right?")
if useAmpersands is True:
updateProfileQueryString += "&email=" + email
else:
updateProfileQueryString += "email=" + email
useAmpersands = True
else:
raise TangoError("Twitter has a character limit of 40 for all email addresses, and the email address must be valid. Try again.")
if url is not None:
if len(list(url)) < 100:
if useAmpersands is True:
updateProfileQueryString += "&" + urllib.urlencode({"url": url})
else:
updateProfileQueryString += urllib.urlencode({"url": url})
useAmpersands = True
else:
raise TangoError("Twitter has a character limit of 100 for all urls. Try again.")
if location is not None:
if len(list(location)) < 30:
if useAmpersands is True:
updateProfileQueryString += "&" + urllib.urlencode({"location": location})
else:
updateProfileQueryString += urllib.urlencode({"location": location})
useAmpersands = True
else:
raise TangoError("Twitter has a character limit of 30 for all locations. Try again.")
if description is not None:
if len(list(description)) < 160:
if useAmpersands is True:
updateProfileQueryString += "&" + urllib.urlencode({"description": description})
else:
updateProfileQueryString += urllib.urlencode({"description": description})
else:
def getWeeklyTrends(self, date = None, exclude = False):
apiURL = "http://search.twitter.com/trends/daily.json"
questionMarkUsed = False
if date is not None:
apiURL += "?date=" + date
questionMarkUsed = True
if exclude is True:
if questionMarkUsed is True:
apiURL += "&exclude=hashtags"
else:
apiURL += "?exclude=hashtags"
try:
return simplejson.load(urllib.urlopen(apiURL))
except HTTPError, e:
raise TangoError("getWeeklyTrends() failed with a %s error code." % `e.code`, e.code)
def showStatus(self, id):
try:
if self.authenticated is True:
return simplejson.load(self.opener.open("http://twitter.com/statuses/show/%s.json" % id))
else:
return simplejson.load(urllib2.urlopen("http://twitter.com/statuses/show/%s.json" % id))
except HTTPError, e:
raise TangoError("Failed with a %s error code. Does this user hide/protect their updates? You'll need to authenticate and be friends to get their timeline."
% `e.code`, e.code)
def updateDeliveryDevice(self, device_name = "none"):
if self.authenticated is True:
try:
return self.opener.open("http://twitter.com/account/update_delivery_device.json?", urllib.urlencode({"device": device_name}))
except HTTPError, e:
raise TangoError("updateDeliveryDevice() failed with a %s error code." % `e.code`, e.code)
else:
raise TangoError("updateDeliveryDevice() requires you to be authenticated.")
def notificationLeave(self, id = None, user_id = None, screen_name = None):
if self.authenticated is True:
apiURL = ""
if id is not None:
apiURL = "http://twitter.com/notifications/leave/" + id + ".json"
if user_id is not None:
apiURL = "http://twitter.com/notifications/leave/leave.json?user_id=" + user_id
if screen_name is not None:
apiURL = "http://twitter.com/notifications/leave/leave.json?screen_name=" + screen_name
try:
return simplejson.load(self.opener.open(apiURL, ""))
except HTTPError, e:
raise TangoError("notificationLeave() failed with a %s error code." % `e.code`, e.code)
else:
raise TangoError("notificationLeave() requires you to be authenticated.")