Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@morris555
Created January 14, 2012 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morris555/1610537 to your computer and use it in GitHub Desktop.
Save morris555/1610537 to your computer and use it in GitHub Desktop.
#!/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