[Tip] How to get people who does not follow you on twitter

3 views
Skip to first unread message

Bruno Rocha

unread,
Nov 3, 2010, 8:59:18 AM11/3/10
to web...@googlegroups.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




Michele Comitini

unread,
Nov 3, 2010, 4:18:41 PM11/3/10
to web...@googlegroups.com
Don't you think some components using this on web2py.com home page
would be nice?

2010/11/3 Bruno Rocha <rocha...@gmail.com>:

rochacbruno

unread,
Nov 3, 2010, 5:06:59 PM11/3/10
to web...@googlegroups.com
Do you mean showing who follows @web2py?

I think it is a good idea, even to create some kind of web2pyers network based on twitter.

Enviado via iPhone

Albert Abril

unread,
Nov 3, 2010, 5:15:31 PM11/3/10
to web...@googlegroups.com
Meanwhile, and only If you want, send me or post here your nicknames of twitter and I'll make a web2py twitter-list.
my twitter is @desmondo. 
Reply all
Reply to author
Forward
0 new messages