-
Notifications
You must be signed in to change notification settings - Fork 2
/
PinterestBot - Copy.py
354 lines (280 loc) · 22 KB
/
PinterestBot - Copy.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
from gui import *
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
import xlrd
import os
import datetime
import random
import sys
import time
file_queue = 0
stop_upload = False
class Start(QtCore.QThread):
def __init__(self,parent=None):
super(Start,self).__init__(parent)
def run(self):
try:
global stop_upload
global file_queue
self.current_dir = os.getcwd()
self.options = Options()
self.options.add_experimental_option("excludeSwitches",
["ignore-certificate-errors",
"safebrowsing-disable-download-protection",
"safebrowsing-disable-auto-update",
"disable-client-side-phishing-detection"])
self.prefs = {"profile.default_content_setting_values.notifications" : 2}
self.options.add_experimental_option("prefs", self.prefs)
#self.options.add_argument("--headless")
self.options.add_argument("--disable-infobars")
self.options.add_argument("--disable-extensions")
self.options.add_argument("--incognito")
self.options.add_argument("--disable-plugins-discovery")
self.chromedriver_path ="chromedriver"
self.browser = webdriver.Chrome(self.chromedriver_path, chrome_options=self.options)
file_queue = 0
while stop_upload == False:
self.wb = xlrd.open_workbook("info.xlsx")
self.sheet = self.wb.sheet_by_index(0)
self.file_count = self.sheet.nrows
self.title = ""
while True:
self.image_name = random.choice(os.listdir(self.current_dir + "\\image"))
self.image_path = self.current_dir + "\\image\\" + self.image_name
for i in range(self.file_count):
if self.sheet.cell_value(i,0) == self.image_name.split(".")[0]:
self.title = self.sheet.cell_value(i,1)
self.url = self.sheet.cell_value(i,2)
self.description = self.sheet.cell_value(i,3)
if window.excel_board.isChecked():
window.board_link.setText(self.sheet.cell_value(i,4))
break
break
if self.title != "":
if file_queue == 0:
self.browser.get("https://www.pinterest.com/")
time.sleep(5)
if not window.google_account.isChecked():
try:
self.browser.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div/div[3]/div/div[1]/div/div/div[1]/div/div/div[1]/div[4]/div/div[3]/div/div/a").click() # click on 'already have an account'
except:
self.browser.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[3]/div/div[1]/div/div/div[1]/div/div/div[1]/div[4]/div/div[3]/div/div/a").click()
pass
time.sleep(10)
self.mail_box = self.browser.find_element_by_xpath(
"//*[@id='email']")
self.mail_box.send_keys(window.mail_address.text())
time.sleep(10)
self.password_box = self.browser.find_element_by_xpath(
"//*[@id='password']")
self.password_box.send_keys(window.password.text())
time.sleep(5)
try:
self.browser.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div/div[3]/div/div[1]/div/div/div[1]/div/div/div/div[3]/div[1]/form/div[4]/button/div").click() # click on 'log in'
except:
try:
self.browser.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div/div[3]/div/div[1]/div/div/div[1]/div/div/div/div[3]/div[1]/form/div[5]/button").click()
except:
self.browser.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[3]/div/div[1]/div/div/div[1]/div/div/div/div[3]/div[1]/form/div[5]/button").click()
pass
pass
else:
self.first_browser = self.browser.window_handles[0]
self.browser.find_element_by_xpath(
"//*[@id='googleConnectButton']/span").click()
time.sleep(5)
self.second_window = self.browser.window_handles[1]
self.browser.switch_to_window(self.second_window)
time.sleep(10)
self.mail_box = self.browser.find_element_by_xpath(
"//*[@id='identifierId']")
self.mail_box.send_keys(window.mail_address.text())
time.sleep(5)
self.browser.find_element_by_xpath(
"//*[@id='identifierNext']/span/span").click()
time.sleep(10)
self.password_box = self.browser.find_element_by_xpath(
"//*[@id='password']/div[1]/div/div[1]/input")
self.password_box.send_keys(window.password.text())
time.sleep(5)
self.browser.find_element_by_xpath(
"//*[@id='passwordNext']/span/span").click()
time.sleep(15)
self.browser.switch_to_window(self.first_browser)
time.sleep(15)
self.board_link = window.board_link.text()
self.browser.get(self.board_link)
time.sleep(15)
try:
self.browser.find_element_by_xpath(
"//*[@id='__PWS_ROOT__']/div/div[1]/div/div[1]/div[2]/div[3]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div/button/div/div").click() # click on '+' button
except:
try:
self.browser.find_element_by_xpath(
"/html/body/div/div/div[1]/div/div[1]/div[2]/div[3]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div/button/div/div/svg").click()
except:
try:
self.browser.find_element_by_xpath(
"/html/body/div/div[1]/div[3]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div[1]/button/div/div").click()
except:
# self.browser.find_element_by_xpath("/html/body/div/div[2]/div[3]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div/button/div/div").click()
self.browser.find_element_by_xpath(
"/html/body/div/div/div[1]/div/div[1]/div[2]/div[3]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div/button").click()
pass
pass
pass
time.sleep(5)
try:
self.browser.find_element_by_xpath(
"//*[@id='__PWS_ROOT__']/div/div[1]/div/div[1]/div[2]/div[3]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div[2]/div/div[1]/div/div/div[2]/div/div/div/div/div/div[1]").click()
except:
try:
self.browser.find_element_by_xpath(
"/html/body/div/div[1]/div[3]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div[2]/div/div[1]/div/div/div[2]/div/div/div/div/div/div[1]").click()
except:
# self.browser.find_element_by_xpath("/html/body/div/div[2]/div[3]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div[2]/div/div[1]/div/div/div[2]/div/div/div/div/div/div[1]").click()
self.browser.find_element_by_xpath(
"/html/body/div/div/div[1]/div/div[1]/div[2]/div[3]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div[2]/div/div[1]/div/div/div[2]/div/div/div/div").click()
pass
pass
time.sleep(5)
self.soup = BeautifulSoup(self.browser.page_source, "html.parser")
self.browser.find_element_by_id("media-upload-input").send_keys(self.image_path)
time.sleep(10)
try:
title_id = \
(self.soup.find_all("textarea", {"placeholder": "Add your title"}))[
0].get("id")
title = self.browser.find_element_by_id(title_id)
title.send_keys(self.title)
except:
title_id = (self.soup.find_all("textarea",
{"placeholder": "Başlığınızı ekleyin"}))[
0].get("id")
self.browser.find_element_by_id(title_id).send_keys(self.title)
pass
time.sleep(5)
try:
pin_id = (self.soup.find_all("textarea", {
"placeholder": "Tell everyone what your Pin is about"}))[0].get(
"id")
self.browser.find_element_by_id(pin_id).send_keys(self.description)
except:
pin_id = (self.soup.find_all("textarea", {
"placeholder": "Pininizin ne hakkında olduğunu herkese söyleyin"}))[
0].get("id")
self.browser.find_element_by_id(pin_id).send_keys(self.description)
pass
time.sleep(5)
try:
dest_id = (self.soup.find_all("textarea", {
"placeholder": "Add a destination link"}))[0].get("id")
self.browser.find_element_by_id(dest_id).send_keys(self.url)
except:
dest_id = (self.soup.find_all("textarea", {
"placeholder": "Bir hedef bağlantı ekleyin"}))[0].get("id")
self.browser.find_element_by_id(dest_id).send_keys(self.url)
pass
time.sleep(5)
try:
# self.browser.find_element_by_xpath("//*[@id='__PWS_ROOT__']/div/div[1]/div/div[1]/div[2]/div[3]/div/div/div/div[2]/div/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/button[2]/div").click()
self.browser.find_element_by_xpath(
"/html/body/div/div[1]/div[3]/div/div/div/div[2]/div[1]/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/button[2]").click()
except:
try:
self.browser.find_element_by_xpath(
"/html/body/div/div/div[1]/div/div[1]/div[2]/div[3]/div/div/div/div[2]/div/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/button[2]").click()
except:
self.browser.find_element_by_xpath(
"/html/body/div/div[2]/div[3]/div/div/div/div[2]/div/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/button[2]").click()
pass
pass
print("k")
time.sleep(10)
print("skipped time")
file_queue += 1
os.remove(self.image_path)
self.wb = xlrd.open_workbook("info.xlsx")
self.sheet = self.wb.sheet_by_index(0)
self.file_count = self.sheet.nrows
print(self.file_count)
print(file_queue)
if self.file_count > file_queue:
self.wait = random.randint(int(window.min_int.value()) * 60,
int(window.max_int.value()) * 60)
while stop_upload == False and self.wait >= 0:
window.time_remaining.setText(
str(datetime.timedelta(seconds=self.wait)))
time.sleep(1)
self.wait -= 1
if stop_upload == True:
window.time_remaining.setText("Program stopped")
self.browser.quit()
else:
window.start_but.setEnabled(True)
window.mail_address.setEnabled(True)
window.password.setEnabled(True)
window.show_browser.setEnabled(True)
window.min_int.setEnabled(True)
window.max_int.setEnabled(True)
window.google_account.setEnabled(True)
window.board_link.setEnabled(True)
window.excel_board.setEnabled(True)
window.time_remaining.setText(
"All images have been uploaded succesfully")
return
except:
self.browser.close()
pass
return
finally:
self.browser.close()
class PinterestBot():
def start_pressed(self):
global file_queue
global stop_upload
stop_upload = False
if window.min_int.value() > window.max_int.value():
QtWidgets.QMessageBox.about(window, "Error", "Min. interval cannot be bigger than max. interval!")
return
if window.mail_address.text() == "" or window.password.text() == "" or (window.excel_board.isChecked() == False and window.board_link.text() == ""):
QtWidgets.QMessageBox.about(window, "Error", "Please insert your mail, password and board link")
return
window.start_but.setEnabled(False)
window.mail_address.setEnabled(False)
window.password.setEnabled(False)
window.show_browser.setEnabled(False)
window.min_int.setEnabled(False)
window.max_int.setEnabled(False)
window.google_account.setEnabled(False)
window.board_link.setEnabled(False)
window.excel_board.setEnabled(False)
self.start = Start()
self.start.start()
#self.start.run()
def stop_pressed(self):
global stop_upload
stop_upload = True
window.start_but.setEnabled(True)
window.mail_address.setEnabled(True)
window.password.setEnabled(True)
window.show_browser.setEnabled(True)
window.min_int.setEnabled(True)
window.max_int.setEnabled(True)
window.google_account.setEnabled(True)
window.board_link.setEnabled(True)
window.excel_board.setEnabled(True)
window.time_remaining.setText("Time Remaining")
app = QtWidgets.QApplication(sys.argv)
window = Ui_Form()
window.show()
pinterestbot = PinterestBot()
window.start_but.clicked.connect(pinterestbot.start_pressed)
window.stop_but.clicked.connect(pinterestbot.stop_pressed)
sys.exit(app.exec_())