-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadSelenium.py
70 lines (66 loc) · 2.38 KB
/
uploadSelenium.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
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import os
import demoji
from dotenv import load_dotenv
def upload_file(file_path, infos):
os.system("clear")
print(file_path)
load_dotenv()
url = "https://anchor.fm/dashboard/episode/new"
email = os.getenv("EMAIL")
passwd = os.getenv("PASSWORD")
try:
options = ChromeOptions()
options.add_argument("--headless")
print("iniciando upload")
drive = Chrome(options=options)
drive.get(url)
print("preenchendo login")
drive.find_element(by="id", value="email").send_keys(email)
drive.find_element(by="id", value="password").send_keys(
passwd, Keys.ENTER
)
sleep(5)
print("preenchendo arquivo")
inputFile = drive.find_element(By.TAG_NAME, "input")
drive.execute_script("arguments[0].style.display='block';", inputFile)
inputFile.send_keys(os.path.abspath(file_path))
print("aguardando upload")
wait = WebDriverWait(drive, 500)
element = wait.until(
EC.element_to_be_clickable(
(
By.XPATH,
"/html/body/div/div/main/div/div/div/div/div[2]/button",
)
)
).click()
print("Upload concluído", element)
sleep(5)
print("preenchendo informações")
drive.find_element(By.ID, "title").send_keys(infos["title"])
drive.find_element(
By.XPATH,
'//*[@id="app-content"]/div/form/div[4]/div[2]/div[2]/div/div/div[2]/div/div[2]/div',
).send_keys(demoji.replace(infos["description"], ''))
sleep(5)
drive.find_element(
By.XPATH, '//*[@id="app-content"]/div/form/div[1]/div[2]/button[2]'
).click()
sleep(3)
print("Episódio publicado")
drive.close()
except (KeyboardInterrupt):
print("\nUpload interrompido")
if __name__ == "__main__":
dist = {
"title": "Falando com Maker Comece cedo mas saiba onde quer chegar! [Thais Sadami]",
"description": "é um teste",
}
name = "./audio/test.mp3"
upload_file(name, dist)