-
Notifications
You must be signed in to change notification settings - Fork 323
/
twitter-stream-extract-links.py
executable file
·41 lines (34 loc) · 1.68 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
37
38
39
40
41
#!/usr/bin/env python3
#-----------------------------------------------------------------------
# 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
#-----------------------------------------------------------------------
import sys
sys.path.append(".")
import config
#-----------------------------------------------------------------------
# create twitter streaming 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/streaming/overview
#-----------------------------------------------------------------------
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"])