Created
January 14, 2012 06:30
-
-
Save morris555/1610537 to your computer and use it in GitHub Desktop.
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 tweepy | |
import sys | |
def get_oauth(): | |
consumer_key = '' | |
consumer_secret = '' | |
access_key = '' | |
access_secret = '' | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_key, access_secret) | |
return auth | |
def get_trends(api, woeid): | |
trend = api.trends_location(woeid)[0] | |
trends = trend['trends'] | |
print(u"場所:{0}".format(trend["locations"][0]["name"])) | |
print(u"トレンド:") | |
for i in range(len(trends)): | |
print(u"\t{0}".format(trends[i]["name"])) | |
def main(): | |
auth = get_oauth() | |
api = tweepy.API(auth_handler=auth) | |
if len(sys.argv) >= 2: | |
woeid = int(sys.argv[1]) | |
else: | |
woeid = 23424856 | |
try: | |
get_trends(api, woeid) | |
except tweepy.error.TweepError: | |
print('おそらく指定された場所のデータはありません。') | |
exit() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment