Created
April 18, 2011 13:12
-
-
Save edsu/925289 to your computer and use it in GitHub Desktop.
suggests pinboard users you might want to add to your network based on your twitter friends
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| twitter2pinboard.py is a little hack to help you build your pinboard | |
| network based on your Twitter social network. I imagine pinboard will | |
| be adding something like this shortly since they've got some beta Twitter | |
| support now. So rather than turning this into a full on webapp it's just | |
| a command line tool for now. | |
| twitter2pinboard.py uses the Twitter API to look up your friends (people you | |
| follow) and then looks them up on Pinboard. The big assumption here is that | |
| the screen name on Twitter matches the username on Pinboard. | |
| You'll need to register the script as a Twitter application to get the oauth | |
| credentials that you will be prompted for when you run the script. | |
| https://dev.twitter.com/apps/new | |
| Obviously, you'll need to have Python available, ayou also need to install | |
| Python Twitter Tools: | |
| http://pypi.python.org/pypi/twitter/ | |
| Comments, questions: | |
| Ed Summers <ehs@pobox.com> | |
| """ | |
| import urllib | |
| from twitter import Twitter, OAuth | |
| token = raw_input("Access Token: ") | |
| token_key = raw_input("Access Token Secret: ") | |
| con_key = raw_input("Consumer Key: ") | |
| con_secret = raw_input("Consumer Secret: ") | |
| twitter = Twitter(auth=OAuth(token, token_key, con_key, con_secret)) | |
| def friends(): | |
| user_ids = twitter.friends.ids() | |
| # request profiles 100 at a time | |
| for i in range(0, len(user_ids), 100): | |
| ids = ','.join(map(str, user_ids[i : i + 100])) | |
| for profile in twitter.users.lookup(user_id=ids): | |
| yield profile | |
| def on_pinboard(username): | |
| pinboard_url = "http://pinboard.in/u:%s" % username | |
| u = urllib.urlopen(pinboard_url) | |
| return 'not_found' not in u.url | |
| def main(): | |
| for friend in friends(): | |
| screen_name = friend['screen_name'] | |
| if on_pinboard(screen_name): | |
| print "http://pinboard.in/u:%s" % screen_name | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment