[twitter-dev] Re: a Python api redialer

2009-03-25 Thread ptone

For me this is part of an ajax call - so the user doesn't have
exponential patience - if I can't get it in 3 tries, I pass on to the
user that twitter is too busy...

-P


On Mar 24, 5:52 pm, Cameron Kaiser spec...@floodgap.com wrote:
  This meta-wrapper will try 3 times to do the api call before giving
  up.  Its sort of rough and could be fleshed out with some custom
  exceptions etc.

 You might also consider something like an exponential backoff instead of
 sleeping a second each time.

 --
  personal:http://www.cameronkaiser.com/--
   Cameron Kaiser * Floodgap Systems *www.floodgap.com* ckai...@floodgap.com
 -- Von Herzen, moge es wieder zu Herzen gehen. -- Beethoven 
 ---


[twitter-dev] a Python api redialer

2009-03-24 Thread ptone

So we all know that twitter can get over capacity at times.  I
wanted a way to work around that, but also to be reasonably gentle on
the server.

This meta-wrapper will try 3 times to do the api call before giving
up.  Its sort of rough and could be fleshed out with some custom
exceptions etc.

It is designed to be used with http://mike.verdone.ca/twitter/

if the following gets munged, it can also be viewed here for a time:
http://dpaste.com/18789/

If you are not using it in a class - remove the reference to self.

You call it use it basically like this:

from twitter.api import Twitter, TwitterError
twitter = Twitter('name','pw')
json = self.api_repeater(self.twitter.users.show,user_id=userid)




def api_repeater(self,api_call,**kwargs):

repeat a call to the twitter api when their servers are busy

tries = 0
while True:
try:
return api_call(**kwargs)
except TwitterError, e:
error_s = str(e.args[0]).split(':', 1)[1]
#print error_s
try:
error_dict = json.loads(error_s)
err = error_dict['error']
except:
err = str(e.args[0])
if 'Twitter is over capacity' in err:
if tries  3:
raise RuntimeError Twitter too busy
err = 'Twitter is over capacity. ' + str (tries)
tries =+ 1
print err
time.sleep(1)
else:
raise
except:
print sys.exc_info()[0]
raise



[twitter-dev] explore follower graph via api

2009-03-13 Thread ptone

is screen scraping the only way to explore the follower graph
(multiple descendants) of a users followers?

I can find no methods in the APIs that would allow one to create map
diagrams...

-Preston



[twitter-dev] explore follower graph via api

2009-03-13 Thread ptone

Is screen scraping the only way to map a tree of a user's followers
(including multiple levels of descendants)?

I could find no methods in the API that would provide this...

-Preston