-
Notifications
You must be signed in to change notification settings - Fork 43
/
instabot.py
84 lines (67 loc) · 2.45 KB
/
instabot.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
import datalayer
import operation
import period
import content
import instafollow
import instalike
import instaactivity
import configuration
import time
class InstaBot:
def __init__(self):
self.configuration = configuration.Configuration()
self.operation = operation.Operations()
def initialize(self):
if(not self.configuration.initialize()):
return False
self.repository = datalayer.InstalikeSQLDAO()
self.content_manager = content.ContentManager(self.operation, self.repository, self.configuration)
self.period_randomizer = period.PeriodRandomizer(self.configuration)
# bots
self.follow_bot = instafollow.InstaFollow(self.operation, self.repository, self.content_manager, self.configuration)
self.like_bot = instalike.InstaLike(self.operation, self.repository, self.content_manager, self.configuration)
self.activity_bot = instaactivity.InstaActivity(self.operation, self.repository, self.content_manager)
# timing
self.next_frame = 0
self.start_time = time.time()
self.end_time = self.start_time + (self.configuration.bot_stop_after_minutes * 60)
if(not self.configuration.validate()):
return False
# generate 'random' periods of time
self.period_randomizer.randomize()
self.period_randomizer.info()
return True
def log_in(self):
self.log('Trying to log in ...')
response = self.operation.log_in(self.configuration.instagram_username, self.configuration.instagram_password)
if (response):
self.log('Logged in')
return True
else:
self.log('Oops! could not log in.')
return False
def log(self, text):
print(text)
def start(self):
if(not self.initialize()):
return False
while(not self.log_in()):
self.log('failed to log in wait for 5min')
time.sleep(5 * 60)
while(True):
if (self.period_randomizer.is_active()):
if(self.period_randomizer.should_relog()):
if(self.log_in()):
self.period_randomizer.logged()
if(self.operation.has_error()):
if(self.log_in()):
self.operation.clear_error()
if(self.configuration.enable_instalike):
self.like_bot.act()
if(self.configuration.enable_instafollow):
self.follow_bot.act()
self.activity_bot.act()
if(time.time() > self.end_time and self.configuration.bot_stop_after_minutes > 0):
self.log('Shuting down after {0} minute(s) of work'.format(self.configuration.bot_stop_after_minutes))
break;
time.sleep(1 / 60)