def tw_show(id, format='json'): """ Show a status id -- the tweet id to show format -- format of the resulting request """ client = pytwitter(username=settings.TWITTER_ACCOUNT, password=settings.TWITTER_PASSWORD, format=format) return client.statuses_show(id=id)
def tw_timeline(format='json'): """ Get the user timeline, documentation here: http://apiwiki.twitter.com/REST+API+Documentation#usertimeline format -- format of the resulting request """ if format != 'json' and format != 'xml': raise TwitterError('incorrect twitter API format output') client = pytwitter(username=settings.TWITTER_ACCOUNT, password=settings.TWITTER_PASSWORD, format=format) return client.statuses_user_timeline(id=settings.TWITTER_ACCOUNT)
def tw_post(update, format='json'): """ Post a twitter update update -- update content format -- format of the resulting request """ if format != 'json' and format != 'xml': raise TwitterError('incorrect twitter API format output') if len(update) > 140: raise TwitterError('The tweet is to big... we only accept 140 chars per tweet :)') client = pytwitter(username=settings.TWITTER_ACCOUNT, password=settings.TWITTER_PASSWORD, format=format) return client.statuses_update(status=update)
def handle_noargs(self, **options): updated_users = 0 api = pytwitter.pytwitter() twitter_users = TwitterUser.objects.all().order_by('updated_on') for twitter_user in twitter_users: print "Checking user: %s" % twitter_user.screen_name try: user_details_json = api.users_show(id=twitter_user.screen_name) twitter_user.update_from_twitter(simplejson.loads(user_details_json)) # TODO: this should check to see if the user really needs to be saved again twitter_user.save() updated_users += 1 except pytwitter.TwitterError, e: if e.code == 404: pass # FIXME!! # GETTING EXCEPTION: # AttributeError: 'TwitterUser' object has no attribute 'statuses' # print "Deleting hidden user or suspended user (%s): %s" % (e.error, twitter_user.screen_name) # twitter_user.statuses.all().delete() # twitter_user.delete() else: print "Exception for %s: %s" % (twitter_user.screen_name.encode('utf-8', 'xmlcharrefreplace'), e)
#!/usr/bin/env python import sys """To use: $ echo "I ate too much" | ./Update_friedcode.py """ U = 'friedcode' P = <something something> import pytwitter client = pytwitter.pytwitter(username=U, password=P) status_update = sys.stdin.read().strip()[:140] client.statuses_update(status=status_update)