-
Notifications
You must be signed in to change notification settings - Fork 30
/
ilcbot.py
169 lines (129 loc) · 5.45 KB
/
ilcbot.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"""
insta-likecom-bot v.3.0.5
Automates likes and comments on an instagram account or tag
Author: Shine Jayakumar
Github: https://github.com/shine-jayakumar
Copyright (c) 2023 Shine Jayakumar
LICENSE: MIT
"""
import time
import sys
from modules.insta import Insta
from modules.stats import Stats
from modules.applogger import AppLogger
from modules.argparsing import parser
from modules.profile import Profile
from modules.instaworkflows import Followers, Story, Post, Reel
from modules.exceptions import *
from modules.helpers import display_intro, create_dirs
from modules.constants import LOGS_DIR, STATS_DIR, LOCATORS_DIR
create_dirs([LOGS_DIR, STATS_DIR, LOCATORS_DIR])
args = parser.parse_args()
logger = AppLogger('ilcbot').getlogger()
try:
profile = Profile(args=args)
except Exception as ex:
logger.error('Script ended with error')
logger.error(f'{ex.__class__.__name__}: {str(ex)}')
sys.exit(1)
insta:Insta = None
stats = Stats(profile.limits)
try:
start = time.time()
display_intro()
logger.info("Script started")
logger.info(f"Downloading webdriver for your version of {profile.browser.capitalize()}")
logger.info("Loading Instagram")
insta = Insta(
username=profile.username,
password=profile.password,
timeout=profile.eltimeout,
browser=profile.browser,
headless=profile.headless,
profile=profile.brprofile
)
if profile.headless:
logger.info('Running in headless mode')
logger.info(f'Delay: {profile.delay[0]}{"-" + str(profile.delay[1]) if len(profile.delay) > 1 else ""} secs')
if profile.matchtags:
logger.info(f'Match tags: {profile.matchtags}')
if profile.matchtagnum:
total_tags = len(profile.matchtags)
if profile.matchtagnum > total_tags:
logger.warning('No. of tags to match is greater than total tags specified')
logger.info(f'Setting tags to match to: {total_tags}')
profile.matchtagnum = total_tags
else:
logger.info(f'Match at least: {profile.matchtagnum} tags')
if profile.ignoretags:
logger.info(f'Ignore tags: {profile.ignoretags}')
if profile.likecomments:
logger.info(f'Max. comments to like: {profile.likecomments}')
if profile.mostrecent:
logger.info('Targetting most recent posts')
if profile.inlast:
logger.info(f'Filtering posts posted within last {profile.inlast}')
# if browser profile was specified
if profile.brprofile:
logger.info(f'Using profile: {profile.brprofile}')
logger.info('Launching Instagram')
insta.launch_insta()
logger.info('Checking if user is already logged in')
# check if already logged in
if not insta.validate_login():
logger.info('User not logged in. Attempting to login')
if not insta.login(validate=False):
raise LoginFailedError('Failed to login to Instagram')
if insta.is_2factor_present():
logger.info('Script paused for 10 seconds (waiting for code)')
time.sleep(10)
logger.info('Validating login')
if not insta.validate_login():
raise LoginFailedError("Failed to login. Incorrect username/password, or 2 factor verification is active.")
logger.info('Logged in successfully')
logger.info('Attempting to save login information')
# attempt to save login info
if not insta.save_login_info():
raise Exception('Could not find Save Login Info dialog box')
logger.info('Login information saved for the profile')
time.sleep(2)
# attempt to login in only if profile wasn't loaded
# in which case, script will save the Login Info
else:
logger.info(f"Attempting to log in with {profile.username}")
if not insta.login():
raise LoginFailedError("Failed to login. Incorrect username/password, or 2 factor verification is active.")
logger.info("Login successful")
# Extracting followers
target_list = Followers(insta, profile, logger).get_targets(stats)
for target in target_list:
# setting target
logger.info(f'Setting target to: {target}')
insta.target(target)
# opening target
logger.info(f"[target: {target}] Opening target")
if not insta.open_target():
logger.error(f'[target: {target}] Invalid tag or account')
continue
stats.accounts += 1
# check if account is private
private_account = insta.is_private()
if private_account:
stats.private_accounts += 1
logger.info(f'[target: {target}] Private account')
Story(insta, profile, is_private=private_account, logger=logger).interact(target, stats)
Post(insta, profile, logger).interact(target, private_account, stats)
Reel(insta, profile, logger).interact(target, private_account, stats)
stats.save()
logger.info("Script finished successfully")
stats.log()
print(stats)
except Exception as ex:
logger.error(f"Script ended with error")
logger.error(f'Error: [{ex.__class__.__name__}] - {str(ex)}',exc_info=1)
finally:
if insta:
insta.quit()
timediff = time.time() - start
logger.info(f"Total time taken: {round(timediff, 4)} seconds")
sys.exit()