-
Notifications
You must be signed in to change notification settings - Fork 12
/
openseaupload.py
462 lines (389 loc) · 16.7 KB
/
openseaupload.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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
import tkinter
import subprocess
from tkinter import *
from tkinter import filedialog
import os
import sys
import pickle
import time
from numpy import inner
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as ExpectedConditions
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
import os
import sys
import urllib
import pydub
import speech_recognition as sr
import re
from contextlib import contextmanager
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import random
import time
from datetime import datetime
import requests
import json
import stem.process
from stem import Signal
from stem.control import Controller
from selenium.common.exceptions import NoSuchElementException
root = Tk()
root.geometry('500x400')
root.title("NFTs Upload to OpenSea ")
input_save_list = ["NFTs folder :", 0, 0, 0, 0, 0, 0, 0, 0]
main_directory = os.path.join(sys.path[0])
is_polygon = BooleanVar()
is_polygon.set(False)
def open_chrome_profile():
subprocess.Popen(
[
"start",
"chrome",
"--remote-debugging-port=8989",
"--user-data-dir=" + main_directory + "/chrome_profile",
],
shell=True,
)
def save_file_path():
return os.path.join(sys.path[0], "Save_file.cloud")
# ask for directory on clicking button, changes button name.
def upload_folder_input():
global upload_path
upload_path = filedialog.askdirectory()
Name_change_img_folder_button(upload_path)
def Name_change_img_folder_button(upload_folder_input):
upload_folder_input_button["text"] = upload_folder_input
class InputField:
def __init__(self, label, row_io, column_io, pos, master=root):
self.master = master
self.input_field = Entry(self.master)
self.input_field.label = Label(master, text=label)
self.input_field.label.grid(row=row_io, column=column_io)
self.input_field.grid(row=row_io, column=column_io + 1)
try:
with open(save_file_path(), "rb") as infile:
new_dict = pickle.load(infile)
self.insert_text(new_dict[pos])
except FileNotFoundError:
pass
def insert_text(self, text):
self.input_field.delete(0, "end")
self.input_field.insert(0, text)
def save_inputs(self, pos):
input_save_list.insert(pos, self.input_field.get())
with open(save_file_path(), "wb") as outfile:
pickle.dump(input_save_list, outfile)
###input objects###
collection_link_input = InputField("OpenSea Collection Link:", 2, 0, 1)
start_num_input = InputField("Start Number:", 3, 0, 2)
end_num_input = InputField("End Number:", 4, 0, 3)
price = InputField("Price:", 5, 0, 4)
title = InputField("Title:", 6, 0, 5)
description = InputField("Description:", 7, 0, 6)
file_format = InputField("NFT Image Format:", 8, 0, 7)
external_link = InputField("External link:", 9, 0, 8)
###save inputs###
def save():
input_save_list.insert(0, upload_path)
collection_link_input.save_inputs(1)
start_num_input.save_inputs(2)
end_num_input.save_inputs(3)
price.save_inputs(4)
title.save_inputs(5)
description.save_inputs(6)
file_format.save_inputs(7)
external_link.save_inputs(8)
###RECAPTCHA_SOLVE###
# _____MAIN_CODE_____
def main_program_loop():
###START###
project_path = main_directory
file_path = upload_path
collection_link = collection_link_input.input_field.get()
start_num = int(start_num_input.input_field.get())
end_num = int(end_num_input.input_field.get())
loop_price = float(price.input_field.get())
loop_title = title.input_field.get()
loop_file_format = file_format.input_field.get()
loop_external_link = str(external_link.input_field.get())
loop_description = description.input_field.get()
##chromeoptions
opt = Options()
opt.add_experimental_option("debuggerAddress", "localhost:8989")
driver = webdriver.Chrome(
executable_path=project_path + "/chromedriver.exe",
# chrome_options=opt,
options=opt,
)
wait = WebDriverWait(driver, 240)
driver.execute_cdp_cmd("Page.setBypassCSP", {"enabled": True})
###wait for methods
def wait_css_selector(code):
WebDriverWait(driver, 20).until(
ExpectedConditions.presence_of_element_located((By.CSS_SELECTOR, code))
)
def wait_xpath(code):
WebDriverWait(driver,20).until(ExpectedConditions.presence_of_element_located((By.XPATH, code)))
def delay(waiting_time=5):
driver.implicitly_wait(waiting_time)
def check_exists_by_xpath(xpath):
try:
driver.find_element_by_xpath(xpath)
except NoSuchElementException:
return False
return True
def solve_recaptcha():
global displayOk
time.sleep(2)
displayOk = check_exists_by_xpath('/html/body/div[6]/div/div/div/section/div/div')
print(displayOk)
if displayOk:
# time.sleep(100)
# raise TimeoutError
try:
iframes = driver.find_elements_by_tag_name("iframe")
driver.switch_to.frame(iframes[0])
except:
pass
try:
check_button = WebDriverWait(driver, 10).until(ExpectedConditions.presence_of_element_located((By.XPATH,'//*[@id="recaptcha-anchor"]/div[1]')))
time.sleep(random.randint(2,3))
time.sleep(random.randint(2,3))
check_button.click()
except:
pass
try:
driver.switch_to.default_content()
driver.switch_to.frame(iframes[-1])
except:
pass
try:
time.sleep(random.randint(2,3))
time.sleep(random.randint(2,3))
ssd=WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#recaptcha-audio-button")))
ssd.click()
except:
pass
try: # get the mp3 audio file
delay()
src = driver.find_element_by_id("audio-source").get_attribute("src")
print(f"[INFO] Audio src: {src}")
path_to_mp3 = os.path.normpath(os.path.join(os.getcwd(), "sample.mp3"))
path_to_wav = os.path.normpath(os.path.join(os.getcwd(), "sample.wav"))
# download the mp3 audio file from the source
urllib.request.urlretrieve(src, path_to_mp3)
except:
pass
# load downloaded mp3 audio file as .wav
try:
sound = pydub.AudioSegment.from_mp3(path_to_mp3)
sound.export(path_to_wav, format="wav")
sample_audio = sr.AudioFile(path_to_wav)
except Exception:
sys.exit(
"[ERR] Please run program as administrator or download ffmpeg manually, "
"https://blog.gregzaal.com/how-to-install-ffmpeg-on-windows/"
)
try:
# translate audio to text with google voice recognition
delay()
r = sr.Recognizer()
with sample_audio as source:
audio = r.record(source)
key = r.recognize_google(audio)
print(f"[INFO] Recaptcha Passcode: {key}")
# key in results and submit
delay()
driver.find_element_by_id("audio-response").send_keys(key.lower())
time.sleep(random.randint(2,3))
driver.find_element_by_id("audio-response").send_keys(Keys.ENTER)
except:
pass
return False
try:
driver.switch_to.default_content()
except:
pass
displayOk=False
while end_num >= start_num:
global displayOk
displayOk= False
print("Start creating NFT " + loop_title + str(start_num))
driver.get(collection_link)
time.sleep(random.randint(2,3))
print("step 1")
# try:
# for i in range(0,2):
# server_error=WebDriverWait(driver, 1).until(ExpectedConditions.presence_of_element_located((By.XPATH,'/html/body/pre'))).get_attribute('innerHTML')
# if server_error =='Internal Server Error':
# driver.refresh()
# print('server error happend')
# except:
# pass
# wait_xpath('//*[@id="__next"]/div[1]/main/div/div/div[1]/span/a')
# additem = driver.find_element_by_xpath('//*[@id="__next"]/div[1]/main/div/div/div[1]/span/a')
# additem.click()
time.sleep(1)
time.sleep(random.randint(2,3))
try:
print("step 2")
wait_xpath('//*[@id="media"]')
imageUpload = driver.find_element_by_xpath('//*[@id="media"]')
imagePath = os.path.abspath(file_path + "\\" + str(start_num) + "." + loop_file_format) # change folder here
imageUpload.send_keys(imagePath)
except:
driver.refresh()
wait_xpath('//*[@id="media"]')
imageUpload = driver.find_element_by_xpath('//*[@id="media"]')
imagePath = os.path.abspath(file_path + "\\" + str(start_num) + "." + loop_file_format) # change folder here
imageUpload.send_keys(imagePath)
print("step 3")
name = driver.find_element_by_xpath('//*[@id="name"]')
name.send_keys(loop_title + str(start_num)) # +1000 for other folders #change name before "#"
time.sleep(random.randint(1,2))
time.sleep(0.5)
ext_link = driver.find_element_by_xpath('//*[@id="external_link"]')
ext_link.send_keys(loop_external_link)
time.sleep(random.randint(1,2))
time.sleep(0.5)
desc = driver.find_element_by_xpath('//*[@id="description"]')
desc.send_keys(loop_description)
time.sleep(random.randint(1,2))
time.sleep(0.5)
# Select Polygon blockchain if applicable
# if is_polygon.get():
# create = driver.find_element_by_xpath('//*[@id="__next"]/div[1]/main/div/div/section/div[2]/form/div/div[1]/span/button')
# driver.execute_script("arguments[0].click();", create)
# time.sleep(1)
# if is_polygon.get():
# blockchain_button = driver.find_element(By.XPATH, '//*[@id="__next"]/div[1]/main/div/div/section/div/form/div[7]/div/div[2]')
# blockchain_button.click()
# polygon_button_location = '//span[normalize-space() = "Mumbai"]'
# wait.until(ExpectedConditions.presence_of_element_located(
# (By.XPATH, polygon_button_location)))
# polygon_button = driver.find_element(
# By.XPATH, polygon_button_location)
# polygon_button.click()
if is_polygon.get():
create = driver.find_element_by_xpath('//*[@id="__next"]/div[1]/main/div/div/section/div[2]/form/div/div[1]/span/button')
driver.execute_script("arguments[0].click();", create)
create = driver.find_element_by_xpath('//*[@id="__next"]/div[1]/main/div/div/section/div[2]/form/div/div[1]/span/button')
driver.execute_script("arguments[0].click();", create)
time.sleep(random.randint(2,3))
time.sleep(1)
a=solve_recaptcha()
a=solve_recaptcha()
if a==True:
pass
if a==False:
print("waiting")
time.sleep(30)
time.sleep(2)
time.sleep(random.randint(2,3))
try:
wait_css_selector("i[aria-label='Close']")
cross = driver.find_element_by_css_selector("i[aria-label='Close']")
time.sleep(random.randint(2,3))
cross.click()
time.sleep(1)
except:
driver.refresh()
pass
main_page = driver.current_window_handle
try:
wait_xpath('//*[@id="__next"]/div[1]/main/div/div/div[1]/div/span[2]/a')
sell = driver.find_element_by_xpath('//*[@id="__next"]/div[1]/main/div/div/div[1]/div/span[2]/a')
time.sleep(random.randint(2,3))
sell.click()
time.sleep(1)
# time.sleep(random.randint(2,3))
except:
driver.refresh()
wait_xpath('//*[@id="__next"]/div[1]/main/div/div/div[1]/div/span[2]/a')
sell = driver.find_element_by_xpath('//*[@id="__next"]/div[1]/main/div/div/div[1]/div/span[2]/a')
sell.click()
try:
wait_css_selector("input[placeholder='Amount']")
amount = driver.find_element_by_css_selector("input[placeholder='Amount']")
time.sleep(random.randint(2,3))
amount.click()
amount.send_keys(str(loop_price))
time.sleep(1)
time.sleep(random.randint(1,2))
print("step 7")
except:
driver.refresh()
wait_css_selector("input[placeholder='Amount']")
amount = driver.find_element_by_css_selector("input[placeholder='Amount']")
time.sleep(random.randint(2,3))
amount.click()
amount.send_keys(str(loop_price))
time.sleep(1)
print("step 7")
wait_css_selector("button[type='submit']")
listing = driver.find_element_by_css_selector("button[type='submit']")
listing.click()
driver.find_element_by_xpath
time.sleep(2)
# time.sleep(random.randint(2,3))
try:
wait_css_selector("#Body\ react-aria-18 > div > div > button")
sign=driver.find_element_by_css_selector("#Body\ react-aria-18 > div > div > button")
time.sleep(random.randint(2,3))
sign.click()
print("success")
time.sleep(2)
# time.sleep(random.randint(2,3))
except:
print("finding button...")
for i in range(1,40):
try:
ac= check_exists_by_xpath('//*[@id="Body react-aria-'+str(i)+'"]/div/div/button')
if ac == True:
sign = driver.find_element_by_css_selector("#Body\ react-aria-"+str(i)+" > div > div > button")
sign.click()
time.sleep(1)
break
except:
pass
# WebDriverWait(driver, 15).until(lambda driver: len(main_page) != len(driver.window_handles))
for handle in driver.window_handles:
if handle != main_page:
login_page = handle
driver.switch_to.window(login_page)
wait_css_selector("button[data-testid='request-signature__sign']")
sign = driver.find_element_by_css_selector("button[data-testid='request-signature__sign']")
sign.click()
driver.switch_to.window(main_page)
# change the control to signin page
time.sleep(3)
time.sleep(random.randint(2,3))
# change control to main page
start_num = start_num + 1
print('NFT creation completed!')
#####BUTTON ZONE#######
button_save = tkinter.Button(root, width=20, text="Save Form", command=save)
button_save.grid(row=23, column=1)
button_start = tkinter.Button(root, width=20, bg="green", fg="white", text="Start", command=main_program_loop)
button_start.grid(row=25, column=1)
isPolygon = tkinter.Checkbutton(root, text='Polygon Blockchain', var=is_polygon)
isPolygon.grid(row=20, column=0)
open_browser = tkinter.Button(root, width=20, text="Open Chrome Browser", command=open_chrome_profile)
open_browser.grid(row=22, column=1)
upload_folder_input_button = tkinter.Button(root, width=20, text="Add NFTs Upload Folder", command=upload_folder_input)
upload_folder_input_button.grid(row=21, column=1)
try:
with open(save_file_path(), "rb") as infile:
new_dict = pickle.load(infile)
global upload_path
Name_change_img_folder_button(new_dict[0])
upload_path = new_dict[0]
except FileNotFoundError:
pass
#####BUTTON ZONE END#######
root.mainloop()