Last active
October 20, 2016 22:55
-
-
Save grafuls/8c8c2d2dd36625fdcbc307d7abf8ba0a to your computer and use it in GitHub Desktop.
tweeter listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tweepy import API | |
from tweepy import Stream | |
from tweepy import OAuthHandler | |
from tweepy.streaming import StreamListener | |
import os | |
import re | |
import urllib2 | |
C_KEY = os.environ['C_KEY'] | |
C_SECRET = os.environ['C_SECRET'] | |
A_TOKEN = os.environ['A_TOKEN'] | |
A_SECRET = os.environ['A_SECRET'] | |
USER = os.environ['T_USER'] | |
QUERY = os.environ['QUERY'] | |
class listener(StreamListener): | |
def on_error(self, status): | |
print status | |
def on_status(self, status): | |
url = status._json['entities']['urls'][0]['expanded_url'] | |
html_content = urllib2.urlopen(url).read() | |
matches = re.findall(QUERY, html_content, 0) | |
if len(matches) > 0: | |
print "YOU HAVE BEEN PWND (potentially)" | |
print url | |
if __name__ == "__main__": | |
auth = OAuthHandler(C_KEY, C_SECRET) | |
auth.set_access_token(A_TOKEN, A_SECRET) | |
api = API(auth) | |
user = api.get_user(USER) | |
user_id = str(user.id) | |
twitterStream = Stream(auth, listener()) | |
twitterStream.filter(follow=[user_id]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment