forked from arvid220u/invandringsbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainbot.py
executable file
·58 lines (45 loc) · 1.74 KB
/
mainbot.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
#!/usr/bin/python
# Import the twythonaccess
import twythonaccess
from twython import Twython
# import the setup file
import setup
# import the streamer
from massinvandring_streamer import MassinvandringStreamer
# import the apikeys to be able to authenticate
import apikeys
import time
import random
import content
import setup
import setproctitle
# the main function will be called when this script is called in terminal
# the bash command "python3 mainbot.py" will call this function
def main():
setproctitle.setproctitle('invandringsbot')
# check if bot has enough followers_count
while True:
try:
while (twythonaccess.get_followers_count() < 501) or setup.on_probation:
twythonaccess.post_content()
twythonaccess.follow_a_user()
time.sleep(60 + (300* random.random()))
twythonaccess.follow_a_user()
time.sleep((30*60) + (30 * 60 * random.random()))
# start the streamer, and detect for instances of massinvandring in all Swedish tweets
streamer = MassinvandringStreamer(apikeys.CONSUMER_KEY, apikeys.CONSUMER_SECRET, apikeys.ACCESS_TOKEN, apikeys.ACCESS_TOKEN_SECRET)
streamer.statuses.filter(track = setup.trigger_words, language = "en")
except Exception, e:
print "Exception in main()"
print e
try:
if streamer is not None:
streamer.dump_blocks()
except Exception, e:
pass
print "sleeping"
time.sleep(60*16 + (60 * random.random()))
print "continuing..."
# if called directly (as in "python3 mainbot.py"), then call main() function
if __name__ == "__main__":
main()