-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedbubbleAutoUploader.py
166 lines (138 loc) · 5.07 KB
/
RedbubbleAutoUploader.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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import openpyxl
import glob
import os
#setting webdriver and removing *Chrome is being controlled by automated test software* infobar
options = webdriver.ChromeOptions()
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option("excludeSwitches",["enable-automation"])
driver_path = 'C:\Program Files (x86)\chromedriver.exe'
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)
def driverset():
#set driver
driver.get("https://www.redbubble.com/auth/login")
def performSignIn():
#getting data from excel file
userbook = openpyxl.load_workbook(r"./res/StoreuserData.xlsx")
objuser = userbook['Sheet1']
usernameinp = objuser.cell(1,1).value
passwinp = objuser.cell(1,2).value
#sending username
username = driver.find_element(By.ID, "ReduxFormInput1")
username.send_keys(usernameinp)
#sending password
passwd = driver.find_element(By.ID, "ReduxFormInput2")
passwd.send_keys(passwinp)
passwd.send_keys(Keys.RETURN)
time.sleep(10)
def getdir():
#this function reads the image address from getdir.txt and passes it to strmani
# with open("getdir.txt", "r") as f1:
# string_mani(f1.read())
wbook = openpyxl.load_workbook(r"./res/getuserdatatry.xlsx")
objx = wbook['datax']
strdir = objx.cell(2,1).value
string_mani(strdir)
def string_mani(str):
originalString = str
replacedString = originalString.replace('/', '\\')
reversedString = replacedString[::-1]
slashpos = reversedString.find('\\')
appendString = reversedString[slashpos+1:]
finalString = appendString [::-1]
print(f'final string>>>>>>is >>>>>{finalString}')
# #Setting main folder and image pattern
src_folder = finalString
getnumofimages(src_folder)
def navi(f, j,obj):
#function being called, it's filling in image and row specific data in the given form
driver.get("https://www.redbubble.com/portfolio/images/new")
driver.find_element(By.CLASS_NAME, "copy-icon").click()
goto_Button = driver.find_element(By.CLASS_NAME,"works_work-menu-link")
goto_Button.click()
time.sleep(10)
#navigating the drop-down to Copy settings.
try:
optionsMenus = driver.find_elements(By.CLASS_NAME, "works_work-menu")
for eachMenu in optionsMenus:
anchors = eachMenu.find_elements(By.TAG_NAME, "a")
anchors[2].click()
time.sleep(10)
except Exception as e:
print(e)
time.sleep(10)
# Title
title = driver.find_element(By.ID, "work_title_en")
title.clear()
tit = obj.cell(j, 1).value
title.send_keys(tit)
#Tags
tagss = driver.find_element(By.ID, "work_tag_field_en")
tagss.clear()
tg = obj.cell(j, 2).value
tagss.send_keys(tg)
#description
desc = driver.find_element(By.ID, "work_description_en")
desc.clear()
des = obj.cell(j, 3).value
desc.send_keys(des)
#image
img = driver.find_element(By.ID, "select-image-base")
img.send_keys(f)
#waiting for the image to be uploaded. I need a wait until here
# time.sleep(50)
# single-upload with-uploader
#clicking remaining 2 boxes
driver.find_element(By.ID, "rightsDeclaration").click()
time.sleep(50)
driver.find_element(By.ID, "submit-work").click()
#setting wait until to start new upload
urlpattern = 'https://www.redbubble.com/studio/promote'
wait = WebDriverWait(driver, 50)
wait.until(EC.url_contains(urlpattern))
def getnumofimages(folder):
#Getting total number of images in the dir
src_folder = folder
len = 0
# Set dir to an array of sort containing files with pattern : .png
pattern = "\*.png"
# Setting Glob
list_File = glob.glob(src_folder+pattern)
# Iterate directory
for path in os.listdir(src_folder):
# check if current path is a file
if os.path.isfile(os.path.join(src_folder, path)):
len += 1
getdata(len, list_File)
def getdata(count, listF):
#this sends data to func navi
#it sends one image and the row corresponding to that image.
#it keeps sending till all the images are done
#OpenPyxl ki workbook
wbook = openpyxl.load_workbook(r"./res/getuserdatatry.xlsx")
objx = wbook['datax']
strxl = objx.cell(2,2).value
wb = openpyxl.load_workbook(strxl)
#Workbook ki sheet ka obj
#########################
###########IMP ASK USER TO CALL THE SHEET THIS##
########################################
obj1 = wb['RedbubbleData']
#Get max rows in excelsheet
max_row = obj1.max_row
list_Fi = listF
for row in range(1, max_row+1):
for picnum in range(0, count):
if (row-1) is picnum:
navi(list_Fi[picnum],row,obj1)
if __name__ == '__main__':
driverset()
performSignIn()
getdir()
time.sleep(10)
driver.quit()