This repository was archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrun.py
More file actions
148 lines (123 loc) · 4.38 KB
/
run.py
File metadata and controls
148 lines (123 loc) · 4.38 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/local/bin/python2.7
import tweepy
from tweepy.auth import OAuthHandler
from tweepy.streaming import StreamListener, Stream
ckey = ''
csecret = ''
atoken = '-'
asecret = ''
auths = OAuthHandler(ckey, csecret)
auths.set_access_token(atoken, asecret)
api = tweepy.API(auths)
#whitelist handles and words
whitelist_acc = []
#banned handles and words
banned_accs = []
banned_words = []
track_words = [] #retweet any tweet with these words
follow_accs = [] #retweet every tweet from this accounts, handles converted to ids
location = [-74.255735,40.496044,-73.7002721,40.9152555] #reteet any tweet with goelocation that matches this box
class listener(StreamListener):
def on_data(self, raw_data):
try:
tweetText = raw_data.lower().split('"text":"')[1].split('","source":"')[0].replace(",", "") # tweet's text
userName = raw_data.lower().split('"screen_name":"')[1].split('","location"')[0].replace(",", "") # tweet's authors screen name
tweetId = raw_data.split('"id":')[1].split('"id_str":')[0].replace(",", "") # tweet's id
if (userWhitelist(userName) or (userBanned(userName) and safeForWork(tweetText))):
like(tweetId)
print("https://twitter.com/" + userName + "/status/" + tweetId)
print("WHITELIST: " + str(userWhitelist(userName)) + " BANNED: " + str(not userBanned(userName)) + " TEXTSAFE: " + str(safeForWork(tweetText)))
print("")
return True
except Exception as e:
print(str(e)) # prints the error msg, if u dont want it comment it out
restart()
pass
def on_error(self, status_code):
print("error " + status_code)
def userWhitelist(userName):
if any(a_acc == userName.lower() for a_acc in whitelist_acc):
return True
return False
def userBanned(userName):
if not any(acc == userName.lower() for acc in banned_accs):
return True
return False
def safeForWork(tweetText):
if not any(word in tweetText.lower() for word in banned_words):
return True
return False
def retweet(tweetId):
try:
api.retweet(tweetId)
except Exception as e:
print(str(e))
pass
def like(tweetId):
try:
api.create_favorite(tweetId)
except Exception as e:
print(str(e))
pass
def tweetPost(tweetText):
try:
api.update_status(status=tweetText)
except Exception as e:
print(str(e))
pass
def getBanWords():
with open("BannedWords.txt") as ins:
for line in ins:
if "#DO_NOT_REMOVE_THIS_LINE#" not in str(line):
banned_words.append(line.strip())
def getBanAccounts():
with open("BannedAccounts.txt") as ins:
for line in ins:
if "#DO_NOT_REMOVE_THIS_LINE#" not in str(line):
banned_accs.append(line.strip())
def getTrackWords():
with open("TrackWords.txt") as ins:
for line in ins:
if "#DO_NOT_REMOVE_THIS_LINE#" not in str(line):
track_words.append(line.strip())
def getFollowAccounts():
with open("FollowAccounts.txt") as ins:
for line in ins:
if "#DO_NOT_REMOVE_THIS_LINE#" not in str(line):
follow_accs.append(line.strip())
def getWhiteListAccounts():
with open("WhitelistAccounts.txt") as ins:
for line in ins:
if "#DO_NOT_REMOVE_THIS_LINE#" not in str(line):
whitelist_acc.append(line.strip())
def restart():
print("Restart....")
startBot()
def startBot():
print("")
print("Initializing....")
getBanAccounts()
print("getting banned accounts....check")
getBanWords()
print("getting banned words....check")
getTrackWords()
print("getting track words....check")
getFollowAccounts()
print("getting follow accounts....check")
getWhiteListAccounts()
print("getting whitelist accounts....check")
print("")
print("""\
_____ _ _ _ _____ _____ _____
|_ _|_ _ _|_| |_| |_ ___ ___| __ | |_ _|
| | | | | | | _| _| -_| _| __ -| | | | |
|_| |_____|_|_| |_| |___|_| |_____|_____| |_|
created by vishwenga
Running.... :) """)
try:
twt = Stream(auths, listener())
twt.filter(track=track_words)
except Exception as e:
print(str(e))
pass
startBot()