-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.py
129 lines (101 loc) · 3.29 KB
/
listener.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from Crypto.Hash import SHA256
import tweepy, time, sys
from tweepy.streaming import StreamListener
from tweepy import Stream
from tweepy import OAuthHandler
hashlist = []
wholemessage =[]
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''
#____________________ Clases
#__________ message
class MyMessageListener(tweepy.StreamListener):
def __init__(self, api=None):
super(MyMessageListener, self).__init__()
self.num_tweets = 0
def on_error(self, status):
print(status)
def filtermessage(self,message):
a = message.find("#")
wholemessage.append(message[0:a-1])
def hashcomparison(self,newhash,message):
global hashlist
if newhash == str(hashlist[0]):
self.num_tweets += 1
print ">>>>> found Message <<<<<"
print ">>>>>>>>>>>>>>>>>>>"+str(message)+"<<<<<<<<<<<<<<<<<<<<<<<<"
self.filtermessage(message)
else:
print ">> not the Message <<"
def decrypt(self,message):
hash = SHA256.new()
hash.update(message.encode('ascii', 'ignore'))
self.hashcomparison(hash.hexdigest(),message)
def on_status(self, status):
if self.num_tweets < 1:
print (status.text)
self.decrypt(status.text)
return True
else:
return False
#__________ hash
class MyHashListener(tweepy.StreamListener):
def __init__(self, api=None):
super(MyHashListener, self).__init__()
self.num_tweets = 0
def on_status(self, status):
del hashlist[:] #cleans old hash
print (status.text)
hashlist.append(status.text)
return False
def on_error(self, status):
print(status)
#____________________ mainfunctions
#_____________calling Messagelisterner
def startlistneruser():
global CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET
l = MyMessageListener()
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
stream = Stream(auth, l)
try:
">>>>> start listening to stream <<<<<"
stream.filter(track=['yolo'])
api.update_status(status = Message)
except:
print ">>>>> disconect this stream <<<<<"
stream.disconnect()
#_____________calling hashlisterner
def starthashlistener():
global CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET
a = MyHashListener()
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
stream = Stream(auth, a)
try:
print ">>>>> start catching hash <<<<<"
stream.filter(follow=['4091042235'])
api.update_status(status = Message)
except:
print ">>>>> disconect this stream <<<<<"
stream.disconnect()
def printmessage():
global wholemessage
b=""
d = b.join(wholemessage)
print ">>>>>>>>>>>>>>>>>>> current message : "+d+"<<<<<<<<<<<<<<<<<<<<<<<<"
print ""
print ""
print "Chaffing and winnowing Twitter 0.01"
print "Listner Program"
while True:
starthashlistener()
print ">> change stream / 20 seconds <<"
time.sleep(18)
startlistneruser()
print ">> change stream / 20 seconds <<"
time.sleep(18)
printmessage()
pass