forked from tunelko/python-twitter-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter-stream-links.py
More file actions
executable file
·32 lines (26 loc) · 1.28 KB
/
twitter-stream-links.py
File metadata and controls
executable file
·32 lines (26 loc) · 1.28 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
#!/usr/bin/python
#-----------------------------------------------------------------------
# twitter-stream:
# - ultra-real-time stream of twitter's public timeline
# prints live results containing a URL link and the #OWS tag
#-----------------------------------------------------------------------
from twitter import *
# these tokens are necessary for user authentication
consumer_key = "XxXxXxxXXXxxxxXXXxXX"
consumer_secret = "xXXXXXXXXxxxxXxXXxxXxxXXxXxXxxxxXxXXxxxXXx"
access_key = "XXXXXXXX-xxXXxXXxxXxxxXxXXxXxXxXxxxXxxxxXxXXxXxxXX"
access_secret = "XxXXXXXXXXxxxXXXxXXxXxXxxXXXXXxXxxXXXXx"
# create twitter API object
auth = OAuth(access_key, access_secret, consumer_key, consumer_secret)
stream = TwitterStream(auth = auth, secure = True)
# iterate over tweets matching this filter text
# IMPORTANT! this is not quite the same as a standard twitter search
# - see https://dev.twitter.com/docs/streaming-api
tweet_iter = stream.statuses.filter(track = "social")
for tweet in tweet_iter:
# check whether this is a valid tweet
if tweet.get('text'):
# yes it is! print out the contents, and any URLs found inside
print "(%s) @%s %s" % (tweet["created_at"], tweet["user"]["screen_name"], tweet["text"])
for url in tweet["entities"]["urls"]:
print " - found URL: %s" % url["expanded_url"]