Venkat, You should try Miha's patch here: http://persistent.info/files/twitter_appengine.patch
It patches twitter.py to work with GAE's restrictions. -Mahmoud On Mar 20, 8:19 am, venkat rambotla <[email protected]> wrote: > hey hi tim, > my twitter.py code goes like this > > #!/*usr*/bin/*python > * > > # > > # Copyright 2007 *Google* Inc. All Rights Reserved. > > * > > '''A library that provides a python interface to the Twitter API''' > * > > __author__ = *'[email protected]' > * > > __version__ = *'0.5' > * > > import base64 > > import md5 > > import os > > import *sys > * > > import tempfile > > import time > > import urllib > > import urllib2 > > import urlparse > > import simplejson > > class *TwitterError*(Exception): > * > > **'''Base class for Twitter errors''' > * > > class *Status*(object): > * > > *def *__init__*(*self*, > > created_at=None, > > id=None, > > text=None, > > user=None, > > now=None): > > *'''An object to hold a Twitter status message. > * > > * > > This class is normally instantiated by the twitter.Api class and > > returned in a sequence. > * > > * > > Note: Dates are posted in the form "Sat Jan 27 04:17:38 +0000 2007" > * > > * > > Args: > > created_at: The time this status message was posted > > id: The unique id of this status message > > text: The text of this status message > > relative_created_at: > > A human readable string representing the posting time > > user: > > A twitter.User instance representing the person posting the message > > now: > > The current time, if the client choses to set it. Defaults to the > > wall clock time. > > ''' > * > > *self*.created_at = created_at > > *self*.id = id > > *self*.text = text > > *self*.user = user > > *self*.now = now > > * > > *def *GetCreatedAt*(*self*): > > *'''Get the time this status message was posted. > * > > * > > Returns: > > The time this status message was posted > > ''' > * > > return *self*._created_at > > * > > *def *SetCreatedAt*(*self*, created_at): > > *'''Set the time this status message was posted. > * > > * > > Args: > > created_at: The time this status message was created > > ''' > * > > *self*._created_at = created_at > > * > > *created_at = property(GetCreatedAt, SetCreatedAt, > > doc=*'The time this status message was posted.'*) > > * > > *def *GetCreatedAtInSeconds*(*self*): > > *'''Get the time this status message was posted, in seconds since the epoch. > * > > * > > Returns: > > The time this status message was posted, in seconds since the epoch. > > ''' > * > > return time.mktime(time.strptime(*self*.created_at, *'%a %b %d %H:%M:%S > +0000 %Y'*)) > > * > > *created_at_in_seconds = property(GetCreatedAtInSeconds, > > doc=*"The time this status message was " > * > > *"posted, in seconds since the epoch"*) > > * > > *def *GetId*(*self*): > > *'''Get the unique id of this status message. > * > > * > > Returns: > > The unique id of this status message > > ''' > * > > return *self*._id > > * > > *def *SetId*(*self*, id): > > *'''Set the unique id of this status message. > * > > * > > Args: > > id: The unique id of this status message > > ''' > * > > *self*._id = id > > * > > *id = property(GetId, SetId, > > doc=*'The unique id of this status message.'*) > > * > > *def *GetText*(*self*): > > *'''Get the text of this status message. > * > > * > > Returns: > > The text of this status message. > > ''' > * > > return *self*._text > > * > > *def *SetText*(*self*, text): > > *'''Set the text of this status message. > * > > * > > Args: > > text: The text of this status message > > ''' > * > > *self*._text = text > > * > > *text = property(GetText, SetText, > > doc=*'The text of this status message'*) > > * > > *def *GetRelativeCreatedAt*(*self*): > > *'''Get a human redable string representing the posting time > * > > * > > Returns: > > A human readable string representing the posting time > > ''' > * > > fudge = 1.25 > > delta = int(*self*.now) - int(*self*.created_at_in_seconds) > > if delta < (1 * fudge): > * > > *return *'about a second ago' > * > > elif delta < (60 * (1/fudge)): > * > > *return *'about %d seconds ago'* % (delta) > > elif delta < (60 * fudge): > * > > *return *'about a minute ago' > * > > elif delta < (60 * 60 * (1/fudge)): > * > > *return *'about %d minutes ago'* % (delta / 60) > > elif delta < (60 * 60 * fudge): > * > > *return *'about an hour ago' > * > > elif delta < (60 * 60 * 24 * (1/fudge)): > * > > *return *'about %d hours ago'* % (delta / (60 * 60)) > > elif delta < (60 * 60 * 24 * fudge): > * > > *return *'about a day ago' > * > > else: > * > > *return *'about %d days ago'* % (delta / (60 * 60 * 24)) > > * > > *relative_created_at = property(GetRelativeCreatedAt, > > doc=*'Get a human readable string representing' > * > > *'the posting time'*) > > * > > *def *GetUser*(*self*): > > *'''Get a twitter.User reprenting the entity posting this status message. > * > > * > > Returns: > > A twitter.User reprenting the entity posting this status message > > ''' > * > > return *self*._user > > * > > *def *SetUser*(*self*, user): > > *'''Set a twitter.User reprenting the entity posting this status message. > * > > * > > Args: > > user: A twitter.User reprenting the entity posting this status message > > ''' > * > > *self*._user = user > > * > > *user = property(GetUser, SetUser, > > doc=*'A twitter.User reprenting the entity posting this ' > * > > *'status message'*) > > * > > *def *GetNow*(*self*): > > *'''Get the wallclock time for this status message. > * > > * > > Used to calculate relative_created_at. Defaults to the time > > the object was instantiated. > * > > * > > Returns: > > Whatever the status instance believes the current time to be, > > in seconds since the epoch. > > ''' > * > > if *self*._now is None: > * > > **self*._now = time.mktime(time.gmtime()) > > return *self*._now > > * > > *def *SetNow*(*self*, now): > > *'''Set the wallclock time for this status message. > * > > * > > Used to calculate relative_created_at. Defaults to the time > > the object was instantiated. > * > > * > > Args: > > now: The wallclock time for this instance. > > ''' > * > > *self*._now = now > > * > > *now = property(GetNow, SetNow, > > doc=*'The wallclock time for this status instance.'*) > > * > > *def *__ne__*(*self*, other): > > return not *self*.__eq__(other) > > * > > *def *__eq__*(*self*, other): > > try: > * > > *return other and \ > > *self*.created_at == other.created_at and \ > > *self*.id == other.id and \ > > *self*.text == other.text and \ > > *self*.user == other.user > > except AttributeError: > * > > *return False > > * > > *def *__str__*(*self*): > > *'''A string representation of this twitter.Status instance. > * > > * > > The return value is the same as the JSON string representation. > * > > * > > Returns: > > A string representation of this twitter.Status instance. > > ''' > * > > return *self*.AsJsonString() > > * > > *def *AsJsonString*(*self*): > > *'''A JSON string representation of this twitter.Status instance. > * > > * > > Returns: > > A JSON string representation of this twitter.Status instance > > ''' > * > > return simplejson.dumps(*self*.AsDict(), sort_keys=True) > > * > > *def *AsDict*(*self*): > > *'''A dict representation of this twitter.Status instance. > * > > * > > The return value uses the same key names as the JSON representation. > * > > * > > Return: > > A dict representing this twitter.Status instance > > ''' > * > > data = {} > > if *self*.created_at: > * > > *data[*'created_at'*] = *self*.created_at > > if *self*.id: > * > > *data[*'id'*] = *self*.id > > if *self*.text: > * > > *data[*'text'*] = *self*.text > > if *self*.user: > * > > *data[*'user'*] = *self*.user.AsDict() > > return data > > * > > *...@staticmethod > ** > > *def *NewFromJsonDict*(data): > > *'''Create a new instance based on a JSON dict. > * > > * > > Args: > > data: A JSON dict, as converted from the JSON in the twitter API > > Returns: > > A twitter.Status instance > > ''' > * > > if *'user'* in data: > * > > *user = User.NewFromJsonDict(data[*'user'*]) > > else: > * > > *user = None > > return Status(created_at=data.get(*'created_at'*, None), > > id=data.get(*'id'*, None), > > text=data.get(*'text'*, None), > > user=user) > > class *User*(object): > * > > **'''A class representing the User structure used by the twitter API. > * > > * > > The User structure exposes the following properties: > * > > * > > user.id > > user.name > > user.screen_name > > user.location > > user.description > > user.profile_image_url > > user.url > > user.status > > ''' > ** > > *def *__init__*(*self*, > > id=None, > > name=None, > > screen_name=None, > > location=None, > > description=None, > > profile_image_url=None, > > url=None, > > status=None): > > *self*.id = id > > *self*.name = name > > *self*.screen_name = screen_name > > *self*.location = location > > *self*.description = description > > *self*.profile_image_url = profile_image_url > > *self*.url = url > > *self*.status = status > > * > > *def *GetId*(*self*): > > *'''Get the unique id of this user. > * > > * > > Returns: > > The unique id of this user > > ''' > * > > return *self*._id > > * > > *def *SetId*(*self*, id): > > *'''Set the unique id of this user. > * > > * > > Args: > > id: The unique id of this user. > > ''' > * > > *self*._id = id > > * > > *id = property(GetId, SetId, > > doc=*'The unique id of this user.'*) > > * > > *def *GetName*(*self*): > > *'''Get the real name of this user. > * > > * > > Returns: > > The real name of this user > > ''' > * > > return *self*._name > > * > > *def *SetName*(*self*, name): > > *'''Set the real name of this user. > * > > * > > Args: > > name: The real name of this user > > ''' > * > > *self*._name = name > > * > > *name = property(GetName, SetName, > > doc=*'The real name of this user.'*) > > * > > *def *GetScreenName*(*self*): > > *'''Get the short username of this user. > * > > * > > Returns: > > The short username of this user > > ''' > * > > return *self*._screen_name > > * > > *def *SetScreenName*(*self*, screen_name): > > *'''Set the short username of this user. > * > > * > > Args: > > screen_name: the short username of this user > > ''' > * > > *self*._screen_name = screen_name > > * > > *screen_name = property(GetScreenName, SetScreenName, > > doc=*'The short username of this user.'*) > > * > > *def *GetLocation*(*self*): > > *'''Get the geographic location of this user. > * > > * > > Returns: > > The geographic location of this user > > ''' > * > > return *self*._location > > * > > *def *SetLocation*(*self*, location): > > *'''Set the geographic location of this user. > * > > * > > Args: > > location: The geographic location of this user > > ''' > *... > > read more » --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
