-
Notifications
You must be signed in to change notification settings - Fork 1
/
opensea_bot.py
236 lines (201 loc) · 8.73 KB
/
opensea_bot.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
import tkinter
import subprocess
from tkinter import *
from tkinter import filedialog
import os
import sys
import pickle
import time
import getpip
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
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)
# _____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,
)
wait = WebDriverWait(driver, 60)
###wait for methods
def wait_css_selector(code):
wait.until(
ExpectedConditions.presence_of_element_located((By.CSS_SELECTOR, code))
)
def wait_css_selectorTest(code):
wait.until(
ExpectedConditions.elementToBeClickable((By.CSS_SELECTOR, code))
)
def wait_xpath(code):
wait.until(ExpectedConditions.presence_of_element_located((By.XPATH, code)))
while end_num >= start_num:
print("Start creating NFT " + loop_title + str(start_num))
driver.get(collection_link)
# time.sleep(3)
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)
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)
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(0.5)
ext_link = driver.find_element_by_xpath('//*[@id="external_link"]')
ext_link.send_keys(loop_external_link)
time.sleep(0.5)
desc = driver.find_element_by_xpath('//*[@id="description"]')
desc.send_keys(loop_description)
time.sleep(0.5)
# Select Polygon blockchain if applicable
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()
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)
wait_css_selector("i[aria-label='Close']")
cross = driver.find_element_by_css_selector("i[aria-label='Close']")
cross.click()
time.sleep(1)
main_page = driver.current_window_handle
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()
wait_css_selector("input[placeholder='Amount']")
amount = driver.find_element_by_css_selector("input[placeholder='Amount']")
amount.send_keys(str(loop_price))
wait_css_selector("button[type='submit']")
listing = driver.find_element_by_css_selector("button[type='submit']")
listing.click()
time.sleep(5)
wait_css_selector("button[class='Blockreact__Block-sc-1xf18x6-0 Buttonreact__StyledButton-sc-glfma3-0 bhqEJb fzwDgL']")
sign = driver.find_element_by_css_selector("button[class='Blockreact__Block-sc-1xf18x6-0 Buttonreact__StyledButton-sc-glfma3-0 bhqEJb fzwDgL']")
sign.click()
time.sleep(2)
for handle in driver.window_handles:
if handle != main_page:
login_page = handle
# change the control to signin page
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()
time.sleep(1)
# change control to main page
driver.switch_to.window(main_page)
time.sleep(1)
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()