-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwitter-stream-extract-links.py
executable file
·36 lines (30 loc) · 1.62 KB
/
twitter-stream-extract-links.py
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
#!/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 *
#-----------------------------------------------------------------------
# load our API credentials
#-----------------------------------------------------------------------
config = {}
execfile("config.py", config)
#-----------------------------------------------------------------------
# create twitter API object
#-----------------------------------------------------------------------
auth = OAuth(config["access_key"], config["access_secret"], config["consumer_key"], config["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:
#-----------------------------------------------------------------------
# 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"]