import datetime import webbrowser import holidays from selenium import webdriver import time from selenium.webdriver import ActionChains import os day = datetime.datetime.now().weekday() #refomroep_url = "https://reformatorischeomroep.nl" refomroep_url = "https://reformatorischeomroep.nl/zenders/radio-1" refomroep_stream = "https://ssl.streampartner.nl/player.php?url=refo37ab25da27fdcfb&w=auto&h=40px" spijkenissee_omroep_url = "https://www.dearkspijkenisse.nl/kerkdiensten" feestdagen = holidays.NL() sunday = False #unmute os.system("amixer set Master unmute") os.system("amixer set Master 80%") #Get day of week and feestday. if(day == 6): print("Its a sunday!") sunday = True else: 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!") else: print("Its a weekday") driver = webdriver.Firefox(executable_path="./geckodriver") 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: driver.get(refomroep_url) time.sleep(2) button = driver.find_element_by_xpath('//html//body//div//main//section//div[1]//div//iframe') #/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")