0% found this document useful (0 votes)
7 views2 pages

Pin Loader

Uploaded by

HICHAM LABRAHMI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Pin Loader

Uploaded by

HICHAM LABRAHMI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

def upload_pins(self, pin: int) -> None:

"""Upload pins one by one on Pinterest."""


try:
print(f'Uploading pins n°{pin + 1}/{data.lenght}.', end=' ')
self.driver.get(self.upload_url) # Go to upload pins URL.
self.driver.implicitly_wait(5) # Page is fully loaded?
self.clickable('//button[' # Click on button to change pinboard.
'@data-test-id="board-dropdown-select-button"]')
t.sleep(5)
try:
self.clickable( # Select pinboard.
f'//div[text()="{data.pinboard}"]/../../..')
t.sleep(5)
except Exception:
raise Exception('Pinboard name is invalid.')
# Upload IMG
self.driver.find_element(
by=By.XPATH, value="//input[contains(@id, 'media-upload-
input')]").send_keys(data.file_path)
t.sleep(5)
self.clickable( # Click on "update" for img
'//div[@data-test-id="save-edit-button"]/button')
t.sleep(5)
self.send_keys( # Input a title.
'//textarea[contains(@id, "pin-draft-title")]', data.title)
t.sleep(5)
self.send_keys( # Input a description.
'//*[@role="combobox"]/div/div/div', data.description)
t.sleep(5)
self.clickable( # Click on "Add alt text" button.
'//div[@data-test-id="pin-draft-alt-text-button"]/button')
t.sleep(5)
self.send_keys('//textarea[contains(' # Input an alt text.
'@id, "pin-draft-alttext")]', data.alt_text)
t.sleep(5)
self.send_keys( # Input a link.
'//textarea[contains(@id, "pin-draft-link")]', data.link)
t.sleep(5)
if len(data.date) > 0:
date, time = data.date.split(' ')
# Select "Publish later" radio button.
self.clickable('//label[contains(@for, "pin-draft-'
'schedule-publish-later")]')
# Input date.
self.clickable('//input[contains(@id, "pin-draft-'
'schedule-date-field")]/../../../..')
# Get month name.
month_name = dt.strptime(date, "%d/%m/%Y").strftime("%B")
# Remove useless "0" in day number.
day = data.date[:2][1] if \
data.date[:2][0] == '0' else data.date[:2]
self.clickable('//div[contains(@aria-label, '
f'"{month_name} {day}")]')
# Input time.
self.clickable('//input[contains(@id, "pin-draft-'
'schedule-time-field")]/../../../..')
# AM can be set to PM
self.clickable(f'//div[contains(text(), "{time} AM")]')
self.clickable( # Click on upload button.
'//button[@data-test-id="board-dropdown-save-button"]')
# If a dialog div appears, pin is uploaded.
self.visible('//div[@role="dialog"]')
print(f'{green}Uploaded.{reset}')
except Exception as error:
print(f'{red}Failed. {error}{reset}')

You might also like