-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·426 lines (405 loc) · 16.8 KB
/
main.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from signal import signal, SIGINT
from time import sleep
from os import system, getcwd
from importlib import reload
import credentials
from random import choice
from sys import argv
from re import sub
# functions
def writeFile(variableName, mode): # save data into file
if mode == "post":
with open(f"./CreateImage.html", "+w") as fileHandle:
for d in variableName:
fileHandle.write("%s" % d)
fileHandle.close()
elif mode == "story":
with open(f"./CreateStory.html", "+w") as fileHandle:
for d in variableName:
fileHandle.write("%s" % d)
fileHandle.close()
def signal_handler(signal, frame): # Handle Ctrl-C
# system("sudo service apache2 stop")
system(f'rm /tmp/{argv[1]}InstaImage.png')
system(f'rm /tmp/{argv[1]}InstaStory.png')
print("\nClosing the script")
driver.quit()
exit(0)
def login(numberOfAccount): # Login function
global sessionId
driver.get('https://www.instagram.com/accounts/logout/')
sleep(5)
driver.get('https://www.instagram.com/accounts/login/')
sleep(10)
driver.find_element(
By.NAME, 'username').send_keys(credentials.account[numberOfAccount][0])
sleep(2)
driver.find_element(
By.NAME, 'password').send_keys(credentials.account[numberOfAccount][1], Keys.RETURN)
sleep(10)
print(f"Logged in with {credentials.account[numberOfAccount][0]}")
# Get session id
cookies = driver.get_cookies()
for row in cookies:
if row['name'] == 'sessionid':
sessionId = row['value']
break
print(sessionId)
def follow(username):
errors = 0
driver.get(f"https://www.instagram.com/{username}/")
print(f"Going for follow {username}")
sleep(10)
driver.find_element(
By.XPATH, '/html/body/div[1]/section/main/div/header/section/ul/li[2]').click()
sleep(5)
for i in range(1, 16):
try:
driver.find_element(
By.XPATH, f'/html/body/div[4]/div/div/div[2]/ul/div/li[{i}]/div/div[3]/button').click()
sleep(3)
except:
errors += 1
if errors >= 8:
break
if driver.find_elements(By.XPATH, '/html/body/div[5]/div/div/div/div[3]/button[2]'):
driver.find_element(
By.XPATH, '/html/body/div[5]/div/div/div/div[3]/button[2]').click()
sleep(4)
def CreateImage(mode, text, background, color=None):
if text == "failed !" or text == None:
raise Exception("failed to get post")
# Create a HTML file
html = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
@font-face {
font-family: "myFont";
src: url("./webPanel/Tanha.ttf");
}
@font-face {
font-family: "myFont2";
src: url("./webPanel/MyFont.woff2");
}
body {"""+f"""
background-image: url({background});
background-repeat: no-repeat;
overflow-y: hidden;
overflow-x: hidden;
"""+"""}
</style>
</head>
<body>
<div dir="rtl" style="
font-family: myFont;
font-size:3vw;
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
min-width: 500px;"""
if mode == "post":
if color != None:
html += f"""color: {credentials.account[int(argv[1])][4][color]};">"""
else:
html += f"""color: {credentials.account[int(argv[1])][4][0]};">"""
html += f"""{text}</div>
<div style="
font-family: myFont2;
position: absolute;
{credentials.account[int(argv[1])][5][0]}
">
<strong>@{credentials.account[int(argv[1])][0]}</strong>
</div></body></html>"""
# Create image
writeFile(html, "post")
driver.get(f'file:///{getcwd()}/CreateImage.html')
driver.set_window_size(640, 640)
sleep(5)
driver.save_screenshot(f"/tmp/{argv[1]}InstaImage.png")
elif mode == "story":
html += f"""color: {credentials.account[int(argv[1])][4][1]};">{text}</div><div style="font-family: myFont2;position: absolute;{credentials.account[int(argv[1])][5][1]}"><strong>@{credentials.account[int(argv[1])][0]}</strong></div></body></html>"""
# Create image
writeFile(html, "story")
driver.get(f'file:///{getcwd()}/CreateStory.html')
driver.set_window_size(1242, 2208)
sleep(5)
driver.save_screenshot(f"/tmp/{argv[1]}InstaStory.png")
sleep(5)
driver.set_window_size(438, 894)
def pickPost():
# select random Channel
chosen = choice(credentials.channels[credentials.account[int(argv[1])][2]])
print(chosen)
channel = chosen[0]
pattern = chosen[1]
# it will pick a random post from telegram channel which in here is our Post source
driver.get(f"https://t.me/s/{channel}")
# Find last post id
postHref = driver.find_element(
By.XPATH, '/html/body/main/div/section/div[20]/div[1]/div[2]/div[3]/div/span[3]/a').get_attribute("href")
postID = 0
for l in range(1, len(postHref)):
if postHref[-l] != '/':
postID -= 1
else:
postID = postHref[postID:]
break
# Find Text Caption
driver.get(
f"https://t.me/{channel}/{choice(range(int(postID)-10000,int(postID)))}")
sleep(10)
try:
driver.switch_to.frame(
driver.find_element(
By.XPATH,
"/html/body/div[1]/div[2]/div[1]/iframe",
)
)
except:
return "failed !"
postText = driver.find_element(
By.XPATH, '/html/body/div/div[2]/div[2]').text.strip()
try:
if driver.find_element(
By.XPATH, '/html/body/div/div[2]/a/div[1]/video'):
return "failed !"
except:
try:
if driver.find_element(
By.XPATH, '/html/body/div/div[2]/a').get_attribute("style")[37:-3] != '':
return "failed !"
except:
newLineCounter = 0
if pattern == 0:
for l in range(1, len(postText)):
if postText[-l] == '\n':
l -= 1
newLineCounter += 1
if newLineCounter == 2:
break
postText = postText[:-l]
elif pattern == 1:
ch = -24
while abs(ch) != len(postText):
if postText[ch] == '》' or postText[ch] == '×' or postText[ch] == '•' or postText[ch] == '»' or postText[ch] == '*' or postText[ch] == '※' or postText[ch] == '☆':
postText = postText[:ch]
ch -= 1
postText = postText.strip()
ch = -1
while abs(ch) != len(postText):
if postText[ch] == '×' or postText[ch] == '•' or postText[ch] == '*' or postText[ch] == '※' or postText[ch] == '☆':
postText = postText[:ch]
ch -= 1
postText = postText.strip()
# clean the text
postText = sub('\n\n+', '<br><br>',
postText.strip()).replace('\n', '<br>')
if len(postText) <= 10 or len(postText) >= 400:
return "failed !"
# Filter Text for last time
for character in postText:
if character == '@':
return "failed !"
return postText
def sendPost(caption=credentials.captions[int(argv[1])]):
driver.get(
f"https://www.instagram.com/{credentials.account[int(argv[1])][0]}")
sleep(5)
driver.find_element(
By.XPATH, '/html/body/div[1]/section/nav[2]/div/div/div[2]/div/div/div[3]').click()
sleep(1)
driver.find_element(
By.XPATH, '/html/body/div[1]/section/nav[2]/div/div/form/input').send_keys(f'/tmp/{argv[1]}InstaImage.png')
sleep(15)
driver.find_element(
By.XPATH, '//*[@id="react-root"]/section/div[1]/header/div/div[2]/button').click()
sleep(10)
driver.find_element(
By.XPATH, '/html/body/div[1]/section/div[2]/section[1]/div[1]/textarea').send_keys(caption)
driver.find_element(
By.XPATH, '//*[@id="react-root"]/section/div[1]/header/div/div[2]/button').click()
sleep(60)
print("Uploaded Post")
system(f'rm /tmp/{argv[1]}InstaImage.png')
def storyWebsite():
# create email
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
emailAddress = ''
for _ in range(16):
emailAddress += choice(alphabet)
driver.get("https://www.moakt.com/")
print(f"Creating Email {emailAddress}@moakt.cc")
sleep(5)
driver.find_element(
By.XPATH, '/html/body/div/div[1]/div[2]/div/div/form/span[3]/input').send_keys(emailAddress)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '/html/body/div/div[1]/div[2]/div/div/form/input[2]'))).click()
sleep(5)
# Sign up
driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[1])
driver.get("https://app.storrito.com/#/login")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '/html/body/div[1]/div/div[3]/div/div[1]/div[2]/button'))).click()
sleep(1)
driver.find_element(
By.XPATH, '/html/body/div[1]/div/div[3]/div/div[1]/div/input').send_keys(f"{emailAddress}@moakt.cc")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '/html/body/div[1]/div/div[3]/div/div[1]/button'))).click()
sleep(30)
# Get verify link
driver.switch_to.window(driver.window_handles[0])
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '/html/body/div/div[1]/div[2]/div/div[2]/div[1]/a[2]'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '/html/body/div/div[1]/div[2]/div/div[2]/div[2]/div/table/tbody/tr[2]/td[1]/a'))).click()
sleep(2)
driver.switch_to.frame(
driver.find_element(
By.XPATH,
"/html/body/div/div[1]/div[2]/div/div[3]/div[2]/iframe",
)
)
driver.find_element(
By.XPATH, '/html/body/div/table/tbody/tr[2]/td/table/tbody/tr/td/div/table/tbody/tr/td/span/a').click()
# add Instagram account
driver.switch_to.window(driver.window_handles[2])
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '/html/body/div[1]/div/div[2]/div/aside/div/div[1]/a[5]/div'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div/div/div[1]/button[2]'))).click()
sleep(10)
for char in sessionId:
driver.find_element(
By.XPATH, '/html/body/div[1]/div/div[1]/div/div/form/div/input').send_keys(char)
sleep(choice(range(1, 5)))
driver.find_element(
By.XPATH, '/html/body/div[1]/div/div[1]/div/div/form/button[1]').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '/html/body/div[1]/div/div[1]/div/div[2]/button'))).click()
# upload story image
driver.get("https://app.storrito.com/#/gallery")
sleep(20)
driver.find_element(
By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div/div[1]/div[1]/div[1]/div/input').send_keys(f'/tmp/{argv[1]}InstaStory.png')
sleep(60)
driver.find_element(
By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div/div[2]/div/div/div/div[1]/img').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '/html/body/div[1]/div/div[1]/div/div/div[1]/div[2]/div[1]/div/button'))).click()
sleep(10)
driver.find_element(
By.XPATH, f'/html/body/div[1]/div/div[2]/div/div/div/div/div/div[2]/div/div[1]/div[1]/div/div/select/option[text()="{credentials.account[int(argv[1])][0]}"]').click()
sleep(10)
btn = driver.find_element(
By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div/div/div/div[2]/div/div[1]/div[3]/div/div/button')
driver.execute_script("arguments[0].click();", btn)
sleep(20)
print("Uploaded Story")
system(f'rm /tmp/{argv[1]}InstaStory.png')
signal(SIGINT, signal_handler) # Handle Ctrl-C
# Variables
chromedriver = "chromedriver.exe"
TotalRunTime = 10
runtimehour = 0
sessionId = ''
posted = False
followed = False
storied = False
mobileChrome = webdriver.ChromeOptions()
mobileChrome.add_argument("--headless")
mobileChrome.add_argument("--no-sandbox")
mobileChrome.add_argument("--disable-dev-shm-usage")
mobileChrome.add_argument(
"--user-agent=Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Mobile Safari/537.36")
mobileChrome.add_argument("--log-level=3")
mobileChrome.add_argument("--log-level=OFF")
noneMobileChrome = webdriver.ChromeOptions()
noneMobileChrome.add_argument("--headless")
noneMobileChrome.add_argument("--no-sandbox")
noneMobileChrome.add_argument("--disable-dev-shm-usage")
noneMobileChrome.add_argument("--window-size=1920,1080")
noneMobileChrome.add_argument("--disable-extentions")
noneMobileChrome.add_argument("--start-maximized")
noneMobileChrome.add_argument("--ignore-certificate-errors")
noneMobileChrome.add_argument("--log-level=3")
noneMobileChrome.add_argument("--log-level=OFF")
# Main code
while True:
if runtimehour == TotalRunTime:
runtimehour = 0
sleep(57600)
while True:
try:
# Create Image for post
if not posted:
driver = webdriver.Chrome(
"chromedriver", options=mobileChrome)
if credentials.account[int(argv[1])][3] == 1:
with open(f"./userInputs/bgUser{argv[1]}.txt", "r+") as f:
data = int(f.read())
f.seek(0)
CreateImage(
"post", pickPost(), f'./CreateImage/{argv[1]}-{data%2}.png', data % 2)
f.write(str(data + 1))
f.truncate()
else:
CreateImage(
"post", pickPost(), f'./CreateImage/{argv[1]}.png')
# Upload the created image
login(int(argv[1]))
sendPost()
driver.quit()
posted = True
# Upload a new Story
if not storied:
driver = webdriver.Chrome(
"chromedriver", options=mobileChrome)
CreateImage(
"story", pickPost(), f'./CreateImage/s{argv[1]}.png')
driver.quit()
driver = webdriver.Chrome(
"chromedriver", options=noneMobileChrome)
storyWebsite()
driver.quit()
storied = True
# Follow few pages
if not followed:
driver = webdriver.Chrome(
"chromedriver", options=mobileChrome)
login(int(argv[1]))
follow(
choice(credentials.followSource[credentials.account[int(argv[1])][2]]))
driver.quit()
followed = True
# going for the next round
runtimehour += 1
if runtimehour == TotalRunTime:
break
print(f"All done ! {runtimehour}/{TotalRunTime}")
# here you can set the delay time
sleep(choice(range(7100, 7300)))
posted = False
followed = False
storied = False
reload(credentials)
except Exception as excep:
print(excep)
driver.quit()
break