-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwitterListener.py
32 lines (25 loc) · 1014 Bytes
/
TwitterListener.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
from tweepy import StreamListener
from tweepy import Stream
import TelegramBot
import tweepy
import json
class TwitterListener(StreamListener):
def __init__(self, twitter_name):
self.twitter_name = twitter_name
def on_data(self, data):
# process stream data here
#TelegramBot.sendToTelebot(data[0]['text'])
#TODO REMOVE SPECIAL CHARACTERS
tweet = json.loads(data)
try:
if 'user' in tweet.keys():
screen_name = tweet['user']['screen_name'].lower()
if screen_name in self.twitter_name :
print(screen_name + 'is in the list ->')
# CHECK Retweet
if not 'RT' in tweet['text'][:3] and not '@' in tweet['text'][:3] :
TelegramBot.sendToTelebot(tweet['user']['name'] + '\n' + tweet['text'])
except json.decoder.JSONDecodeError as jsonError:
print(jsonError)
def on_error(self, status):
print(status)