Opa_omroep-automatiseren/main.py

79 lines
2.3 KiB
Python
Raw Normal View History

2020-12-27 20:00:11 +00:00
import datetime
import webbrowser
import holidays
from selenium import webdriver
import time
from selenium.webdriver import ActionChains
2021-01-16 15:52:58 +00:00
import os
2020-12-27 20:00:11 +00:00
day = datetime.datetime.now().weekday()
#refomroep_url = "https://reformatorischeomroep.nl"
refomroep_url = "https://reformatorischeomroep.nl/zenders/radio-1"
2021-02-05 16:26:36 +00:00
refomroep_stream = "https://stream01.sthhost.nl:2020/AudioPlayer/RO-1"
2020-12-27 20:00:11 +00:00
spijkenissee_omroep_url = "https://www.dearkspijkenisse.nl/kerkdiensten"
feestdagen = holidays.NL()
sunday = False
2021-01-16 15:52:58 +00:00
#unmute
os.system("amixer set Master unmute")
os.system("amixer set Master 80%")
2020-12-27 20:00:11 +00:00
#Get day of week and feestday.
if(day == 6):
print("Its a sunday!")
sunday = True
else:
2021-01-16 15:52:58 +00:00
if(datetime.date.today() in feestdagen):
print("Its a dutch holliday! {}".format(datetime.date.today()))
#Now check time
t = datetime.datetime.now()
if(t.hour > 9 and t.hour < 12):
print("Ochtendienst")
sunday = True
else:
print("Not a church time, assuming it is not a church day!")
2020-12-27 20:00:11 +00:00
else:
print("Its a weekday")
2021-12-31 09:18:27 +00:00
fp = webdriver.FirefoxProfile("/home/opa/.mozilla/firefox/sib3verx.default-release")
driver = webdriver.Firefox(fp,executable_path="./geckodriver")
2021-01-16 15:52:58 +00:00
def PlayMe():
if(sunday):
driver.get(spijkenissee_omroep_url)
time.sleep(7)
button = driver.find_element_by_xpath('//html//body//div[1]//div//div[1]//div[3]//div[2]//iframe[1]')
print(button.location)
actionChains = ActionChains(driver)
actionChains.move_to_element(button).click().perform()
else:
2021-02-05 16:26:36 +00:00
driver.get(refomroep_stream)
2021-01-16 15:52:58 +00:00
time.sleep(2)
2021-12-31 09:18:27 +00:00
button = driver.find_element_by_xpath('/html/body/div/div/section/div[3]/button')#'/html/body/div/section/div[3]/button')#('//html//body//div//main//section//div[1]//div//iframe')
2021-01-16 15:52:58 +00:00
#/html/body/div/main/section/div[1]/d
button.location[0] = 10
print(button.location)
actionChains = ActionChains(driver)
actionChains.move_to_element(button).click().perform()
return True
PlayMe()
exit()
count = 0
while(True):
count +=1
if(count > 10):
exit()
try:
if(PlayMe()):
break
except:
time.sleep(4)
print("Failed to press button or something else happened?")
driver.quit()
driver = webdriver.Firefox(executable_path="./geckodriver")