Don't you think some components using this on web2py.com home page
would be nice?



2010/11/3 Bruno Rocha <rochacbr...@gmail.com>:
> Maybe it can be usefull for someone building a twitter app with web2py,
> I take this form an example posted by @gwidion on twitter.
> <code>
> # -*- coding: utf-8 -*-
> import urllib, json
> # Author: João S. O. Bueno
> # License: LGPL V 3.0
> def get_people_set(method, id, update=None):
>     url = "http://api.twitter.com/1/statuses/%s/%s.json";  % (method, id)
>     people = set()
>     cursor = "-1"
>     while True:
>         data = json.loads(urllib.urlopen(url + "?cursor=%s" %
> cursor).read())
>         cursor = data["next_cursor"]
>         if update:
>             update(cursor)
>         these_people = set(person["screen_name"] for person in
> data["users"])
>         people.update(these_people)
>         if not cursor  or not these_people :
>             break
>     return people
> </code>
> As it returns a set, it is easy to get its intersection/union and rest.
> <code>
> friends = get_people_set("friends", id, self.status)
> followers = get_people_set("followers", id, self.status)
> </code>
> To get who does not follow you, simple do:
> <code>
> noFollowers = sorted(friends - followers)
> </code>
> I am building my own twitter client, using @michelecomitini example,
> including some more options as this one.
>
> Bruno Rocha
> http://flavors.me/rochacbruno
>
>
>
>

Reply via email to