Last active
August 13, 2017 16:41
-
-
Save amirulabu/0601851513e6331c7b5a26cefb771eb3 to your computer and use it in GitHub Desktop.
Attempt to use twitter for generating random numbers
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
#no 'string quotes please' | |
[twitter] | |
CONSUMER_KEY=xxxxxxxxxxxx | |
CONSUMER_SECRET=xxxxxxxxxxxx | |
ACCESS_TOKEN=xxxxxxxxxxxx | |
ACCESS_TOKEN_SECRET=xxxxxxxxxxxx |
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
import twitter | |
import configparser | |
import random | |
def twitter_api(): | |
# example twitter_api().GetSearch("#np") | |
#read config file | |
config = configparser.ConfigParser() | |
config.read('config') | |
#initialize the Twitter API | |
api = twitter.Api(consumer_key=config['twitter']['CONSUMER_KEY'], | |
consumer_secret=config['twitter']['CONSUMER_SECRET'], | |
access_token_key=config['twitter']['ACCESS_TOKEN'], | |
access_token_secret=config['twitter']['ACCESS_TOKEN_SECRET']) | |
return api | |
def get_trend(twitter_api=twitter_api(), woeid=23424977): | |
# woeid: the Yahoo! Where On Earth ID for a location. | |
# default is US | |
trend = twitter_api.GetTrendsWoeid(woeid)[0] | |
return trend.query | |
def get_search(twitter_api=twitter_api(), search=get_trend()): | |
search = twitter_api.GetSearch(term=search, count=1, | |
lang='en', result_type='recent') | |
return search[0].text | |
def randomizer(seed=get_search()): | |
random.seed(seed) | |
return random.random() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment