Skip to content

Commit a5a3ebf

Browse files
committed
Updated csv_to_libretime.py to cut out unnecessary waiting and skip csv header, and added csv_to_email.py to send out automated emails with show credentials to DJs.
1 parent 79e3a02 commit a5a3ebf

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ fabric.properties
6868
**__pycache__
6969
**data_krlx_org_credentials.py
7070
**libretime_credentials.py
71+
**email_credentials.py

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Works in progress for future implementation on the website or for local use.
33

44
### _Required Packages:_
55
- `python3`
6+
- `selenium` package for `python3`
7+
- `chromedriver`
8+
- `Chrome` binary in path
69
- `ffmpeg`
710
- `zip`
811
- `scp`

csv_to_email.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
import sys
3+
import csv
4+
import time
5+
from email.mime.text import MIMEText
6+
import ssl
7+
import smtplib
8+
9+
from email_credentials import EMAIL, PASSWORD, PORT, SMTP_SERVER
10+
# PORT for local server is 25, for Gmail is 465
11+
# SMTP server may be something like 'smtp.gmail.com'
12+
13+
14+
def get_credentials_filename():
15+
credentials_filename = 'show_credentials.csv'
16+
if len(sys.argv) > 1:
17+
credentials_filename = sys.argv[1]
18+
assert(os.path.exists(credentials_filename))
19+
return credentials_filename
20+
21+
def main():
22+
credentials_filename = get_credentials_filename()
23+
24+
context = ssl.create_default_context()
25+
26+
with smtplib.SMTP_SSL(SMTP_SERVER, PORT, context=context) as server:
27+
server.login(EMAIL, PASSWORD)
28+
29+
with open(credentials_filename, newline='') as infile:
30+
reader = csv.reader(infile)
31+
for row in reader:
32+
name, start_date, start_time, end_date, end_time, login, password, emails = row
33+
if start_date == 'startDate':
34+
continue
35+
36+
recipient_list = emails.split(':')
37+
38+
msg = MIMEText(f'''Welcome to a new and exciting term for KRLX!\nWe are very excited to hear you live on air for {name}.\nBelow, you will find your login credentials for streaming.\n\nlogin: {login}\npassword: {password}\n\n<3 KRLX IT''')
39+
msg['Subject'] = f'KRLX Credentials for {name}'
40+
msg['From'] = EMAIL
41+
msg['To'] = ', '.join(recipient_list)
42+
43+
server.sendmail(EMAIL, recipient_list, msg.as_string())
44+
45+
if __name__ == '__main__':
46+
main()

csv_to_libretime.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ def main():
3737
for row in reader:
3838
name, start_date, start_time, end_date, end_time, login, password, emails = row
3939
# camelCase variables are for page elements, snake_case for values
40+
if start_date == 'startDate':
41+
continue
4042

4143
driver.find_element_by_xpath("//button[@onclick=\"showForm()\"]").click()
42-
time.sleep(3)
4344
showName = driver.find_element_by_id("add_show_name")
4445
showName.send_keys(name)
4546

4647
driver.find_element_by_id("add_show_start_now-future").click()
47-
time.sleep(3)
4848
startDate = driver.find_element_by_id("add_show_start_date")
4949
startDate.clear()
5050
startDate.send_keys(start_date)
@@ -60,13 +60,9 @@ def main():
6060
endTime.send_keys(end_time)
6161

6262
driver.find_element_by_id("add_show_repeats").click()
63-
time.sleep(3)
6463
driver.find_element_by_xpath("//*[text()='Live Stream Input']").click()
65-
time.sleep(3)
6664
driver.find_element_by_id("cb_custom_auth").click()
6765

68-
time.sleep(3)
69-
7066
showUsername = driver.find_element_by_id("custom_username")
7167
showUsername.send_keys(login)
7268

0 commit comments

Comments
 (0)