Created
May 29, 2011 12:49
-
-
Save ToQoz/997754 to your computer and use it in GitHub Desktop.
twitter APIから適当にfav取得
This file contains 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 | |
# -*- coding: utf-8 -*- | |
import sys, tweepy, urllib, urllib2, simplejson | |
consumer_key = "" | |
consumer_secret = "" | |
access_key = "" | |
access_secret = "" | |
def getAuth(): | |
auth = tweepy.OAuthHandler(consumer_key,consumer_secret) | |
auth.set_access_token(access_key,access_secret) | |
return auth | |
api = tweepy.API(getAuth()) | |
def getFollowers(): | |
return api.followers(id=sys.argv[1],count=10) | |
def main(id=sys.argv[1]): | |
followers = getFollowers() | |
fav_feed_list = [] | |
for followers_data in followers: | |
fav = api.favorites(id=followers_data.id,count=10) | |
for fav_data in fav: | |
if hasattr(fav_data, "text"): | |
fav_feed_list.append({ | |
"fav_user":followers_data.screen_name, | |
"faved_user":fav_data.user.screen_name, | |
"text":fav_data.text, | |
"created_at":fav_data.created_at | |
}) | |
#print "-----%s-----" % (followers_data.screen_name) | |
if fav_feed_list != {}: | |
for fav_feed in sorted(fav_feed_list, key=lambda x:x["created_at"]): | |
print "%s =>%s: %s %s" % (fav_feed["fav_user"], fav_feed["faved_user"], fav_feed["text"], fav_feed["created_at"]) | |
if __name__=="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment