forked from jesstess/TwitterAPI
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtwitter_functions.py
More file actions
60 lines (48 loc) · 1.55 KB
/
twitter_functions.py
File metadata and controls
60 lines (48 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import twitter
import util
from config import *
BOSTON_WOEID = 2367105
PORTLAND_WOEID = 2475687
def search(searchTerm):
"""
Print recent tweets containing `searchTerm`.
To test this function, at the command line run:
python twitter_api.py --search=<search term>
For example,
python twitter_api.py --search=python
"""
tweets = api.GetSearch(searchTerm)
for tweet in tweets:
util.safe_print(tweet.GetText())
def trendingTopics():
"""
Print the currently trending topics.
To test this function, at the command line run:
python twitter_api.py -t
"""
trending_topics = api.GetTrendsWoeid(BOSTON_WOEID)
for topic in trending_topics:
util.safe_print(topic.name)
def userTweets(username):
"""
Print recent tweets by `username`.
You may find the twitter.Api() function GetUserTimeline() helpful.
To test this function, at the command line run:
python twitter_api.py -u <username>
For example,
python twitter_api.py -u bostonpython
"""
user_tweets = api.GetUserTimeline(username)
for tweet in user_tweets:
util.safe_print(tweet.GetText())
def trendingTweets():
"""
Print tweets for all the trending topics.
To test this function, at the command line run:
python twitter_api.py -w
"""
trending_topics = api.GetTrendsWoeid(PORTLAND_WOEID)
for topic in trending_topics:
trending_tweets = api.GetSearch(topic.name)
for tweet in trending_tweets:
util.safe_print(tweet.GetText())