This blog post is a code example that I also recorded a live video of which programatically selects a winner to a recent Data Skeptic contest run in collaboration with DataSciGuide.com.
In [21]:
import os
from twython import Twython
import ConfigParser
import random
import bitlyapi
from IPython.core.display import HTML
In [4]:
propertiesFile = "my.properties"
cp = ConfigParser.ConfigParser()
cp.readfp(open(propertiesFile))
APP_KEY = cp.get('Params', 'app_key')
APP_SECRET = cp.get('Params', 'app_secret')
OAUTH_TOKEN = cp.get('Params', 'oauth_token')
OAUTH_TOKEN_SECRET = cp.get('Params', 'oauth_token_secret')
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
In [5]:
# GET ALL ENTRIES
search = twitter.search(q='#WinDSBook')
In [7]:
tweets=search['statuses']
In [12]:
f = open('/dev/random', 'rb')
truerandom = f.read(1)
f.close()
In [13]:
map(bin, bytearray(truerandom))
Out[13]:
In [14]:
# TEST RUN
i = random.randint(0, len(tweets))
In [15]:
i
Out[15]:
In [16]:
winner = tweets[i]
In [19]:
print winner['user']['name']
print winner['user']['screen_name']
print winner['user']['location']
In [22]:
HTML(Twython.html_for_tweet(winner))
Out[22]:
In [25]:
winner['entities']['urls']
Out[25]:
Congradulations to @01AdamJay for winning the Data Skeptic contest! Please DM me your mailing address so I can ship you off a copy of Cameron's excellent book in print.