Last active
December 18, 2015 18:59
-
-
Save elleryq/5830053 to your computer and use it in GitHub Desktop.
Using python_twitter to get trend.
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 | |
| # -*- coding: utf-8 -*- | |
| """My app""" | |
| import sys | |
| import os | |
| from twitter import oauth_dance | |
| from twitter import read_token_file | |
| from twitter import OAuth | |
| from twitter import Twitter | |
| # You need to create application in dev.twitter.com. | |
| # Then you'll get the CONSUMER_KEY and CONSUMER_SECRET | |
| CONSUMER_KEY = '' | |
| CONSUMER_SECRET = '' | |
| def main(arg): | |
| MY_TWITTER_CREDS = os.path.expanduser('~/.config/my_app_credentials') | |
| if not os.path.exists(MY_TWITTER_CREDS): | |
| oauth_dance("My App Name", CONSUMER_KEY, CONSUMER_SECRET, | |
| MY_TWITTER_CREDS) | |
| oauth_token, oauth_secret = read_token_file(MY_TWITTER_CREDS) | |
| twitter = Twitter(domain='api.twitter.com', api_version='1.1', auth=OAuth( | |
| oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET)) | |
| # Now work with Twitter | |
| results = twitter.trends.place(_id='1') | |
| for result in results: | |
| for trend in result['trends']: | |
| print(trend['name'].encode('utf-8')) | |
| if __name__ == "__main__": | |
| main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment