-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcsv_to_libretime.py
76 lines (60 loc) · 2.63 KB
/
csv_to_libretime.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
# Written by Cole Schiffer
# Modified by Oliver Calder
import sys
import os
import csv
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from libretime_credentials import USER, PASSWORD
DOMAIN = 'stream.krlx.org'
def get_credentials_filename():
credentials_filename = 'show_credentials.csv'
if len(sys.argv) > 1:
credentials_filename = sys.argv[1]
assert(os.path.exists(credentials_filename))
return credentials_filename
def main():
driver = webdriver.Chrome()
driver.get(f"http://{DOMAIN}/login")
username = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")
username.send_keys(USER)
password.send_keys(PASSWORD)
driver.find_element_by_name("submit").click()
driver.get(f"http://{DOMAIN}/schedule")
credentials_filename = get_credentials_filename()
with open(credentials_filename, newline='') as infile:
reader = csv.reader(infile)
for row in reader:
name, start_date, start_time, end_date, end_time, login, password, emails = row
# camelCase variables are for page elements, snake_case for values
if start_date == 'startDate':
continue
driver.find_element_by_xpath("//button[@onclick=\"showForm()\"]").click()
showName = driver.find_element_by_id("add_show_name")
showName.send_keys(name)
driver.find_element_by_id("add_show_start_now-future").click()
startDate = driver.find_element_by_id("add_show_start_date")
startDate.clear()
startDate.send_keys(start_date)
startTime = driver.find_element_by_id("add_show_start_time")
startTime.clear()
startTime.send_keys(start_time)
endDate = driver.find_element_by_id("add_show_end_date_no_repeat")
endDate.clear()
endDate.send_keys(end_date)
endTime = driver.find_element_by_id("add_show_end_time")
endTime.clear()
endTime.send_keys(end_time)
driver.find_element_by_id("add_show_repeats").click()
driver.find_element_by_xpath("//*[text()='Live Stream Input']").click()
driver.find_element_by_id("cb_custom_auth").click()
showUsername = driver.find_element_by_id("custom_username")
showUsername.send_keys(login)
showPassword = driver.find_element_by_id("custom_password")
showPassword.send_keys(password)
driver.find_element_by_xpath("//*[text()='Add this show']").click()
time.sleep(5)
if __name__ == '__main__':
main()