Commit d4717752 by Ewan Klein

removed explicit numbering from demos

parent c69bef2c
......@@ -47,7 +47,7 @@ USERIDS = ['759251', '612473', '15108702', '6017542', '2673523800'] # UserIDs co
HYDRATED = os.path.join(TWITTER, 'rehydrated.json')
DATE = (2015, 4, 20, 16, 40)
# demo 0
@verbose
def twitterclass_demo():
"""
......@@ -62,7 +62,7 @@ def twitterclass_demo():
tw = Twitter()
tw.tweets(follow=['759251', '6017542'], stream=True, limit=10) #public stream
# demo 1
@verbose
def sampletoscreen_demo(limit=20):
"""
......@@ -73,7 +73,7 @@ def sampletoscreen_demo(limit=20):
client.register(TweetViewer(limit=limit))
client.sample()
# demo 2
@verbose
def tracktoscreen_demo(track="taylor swift", limit=10):
"""
......@@ -84,7 +84,7 @@ def tracktoscreen_demo(track="taylor swift", limit=10):
client.register(TweetViewer(limit=limit))
client.filter(track=track)
# demo 3
@verbose
def search_demo(keywords='nltk'):
"""
......@@ -95,7 +95,7 @@ def search_demo(keywords='nltk'):
for tweet in client.search_tweets(keywords=keywords, count=10):
print(tweet['text'])
# demo 4
@verbose
def tweets_by_user_demo(user='NLTK_org', count=200):
oauth = credsfromfile()
......@@ -103,7 +103,7 @@ def tweets_by_user_demo(user='NLTK_org', count=200):
client.register(TweetWriter())
client.user_tweets(user, count)
# demo 5
@verbose
def lookup_by_userid_demo():
"""
......@@ -118,7 +118,7 @@ def lookup_by_userid_demo():
following = info['friends_count']
print("{0}, followers: {1}, following: {2}".format(name, followers, following))
# demo 6
@verbose
def followtoscreen_demo(limit=10):
"""
......@@ -133,7 +133,7 @@ def followtoscreen_demo(limit=10):
client.register(TweetViewer(limit=limit))
client.statuses.filter(follow=USERIDS)
# demo 7
@verbose
def streamtofile_demo(limit=20):
"""
......@@ -144,7 +144,7 @@ def streamtofile_demo(limit=20):
client.register(TweetWriter(limit=limit, repeat=False))
client.statuses.sample()
# demo 8
@verbose
def limit_by_time_demo(limit=20, date_limit=DATE):
"""
......@@ -155,9 +155,9 @@ def limit_by_time_demo(limit=20, date_limit=DATE):
client.register(TweetWriter(limit=limit, date_limit=date_limit))
client.sample()
# demo 9
@verbose
def extract_tweetids_demo(infile, outfile):
def extract_tweetids_demo(infile = TWEETS, outfile = IDS):
"""
Given a list of full tweets in a file (``infile``), write just the
tweetIDs to a new file (`outfile`)
......@@ -166,9 +166,9 @@ def extract_tweetids_demo(infile, outfile):
json2csv(infile, outfile, FIELDS)
print("Writing ids to {0}".format(outfile))
# demo 10
@verbose
def expand_tweetids_demo(infile, outfile):
def expand_tweetids_demo(infile = IDS, outfile = HYDRATED):
"""
Given a list of tweetIDs in a file (``infile``), try to recover the full
('hydrated') tweets from the REST API and write the results to a new file (`outfile`).
......@@ -180,7 +180,7 @@ def expand_tweetids_demo(infile, outfile):
client = Query(**oauth)
client.lookup(infile, outfile)
# demo 11
@verbose
def corpusreader_demo():
"""
......@@ -214,40 +214,18 @@ def corpusreader_demo():
print(toks)
ALL = [twitterclass_demo, sampletoscreen_demo, tracktoscreen_demo,
search_demo, tweets_by_user_demo, lookup_by_userid_demo, followtoscreen_demo,
streamtofile_demo, limit_by_time_demo,
extract_tweetids_demo, expand_tweetids_demo, corpusreader_demo]
ALL = range(12)
DEMOS = ALL[11:]
if __name__ == "__main__":
"""Run selected demo functions."""
if 0 in DEMOS:
twitterclass_demo()
if 1 in DEMOS:
sampletoscreen_demo()
if 2 in DEMOS:
tracktoscreen_demo()
if 3 in DEMOS:
search_demo()
if 4 in DEMOS:
tweets_by_user_demo()
if 5 in DEMOS:
lookup_by_userid_demo()
if 6 in DEMOS:
followtoscreen_demo()
if 7 in DEMOS:
streamtofile_demo()
if 8 in DEMOS:
limit_by_time_demo()
if 9 in DEMOS:
extract_tweetids_demo(TWEETS, IDS)
if 10 in DEMOS:
expand_tweetids_demo(IDS, HYDRATED)
if 11 in DEMOS:
corpusreader_demo()
for demo in DEMOS:
demo()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment