import Datetime
import webbrowser
import os
import time
n = datetime.datetime.today().weekday()
fo = open("Morning.py","r")
if n == 0:
print('Monday')
webbrowser.open('https://www.youtube.com',new=0)
time.sleep(10)
os.system('pkill chromium')
if n == 1:
print('Monday')
webbrowser.open('https://www.youtube.com',new=0)
time.sleep(10)
os.system('pkill chromium')
if n == 2:
print('Monday')
webbrowser.open('https://www.youtube.com',new=0)
time.sleep(10)
os.system('pkill chromium')
if n == 3:
print('Monday')
webbrowser.open('https://www.youtube.com',new=0)
time.sleep(10)
os.system('pkill chromium')
if n == 4:
print('Monday')
webbrowser.open('https://www.youtube.com',new=0)
time.sleep(10)
os.system('pkill chromium')
if n == 5:
print('Monday')
webbrowser.open('https://www.youtube.com',new=0)
time.sleep(10)
os.system('pkill chromium')
if n == 6:
print('Monday')
webbrowser.open('https://www.youtube.com',new=0)
time.sleep(10)
os.system('pkill chromium')
os.system('pkill chromium')
print('Finish')
fo.close()
Python3 - file executes fine but if I want to schedule to run this code to run every minute, I am using Cron (rasberry pi)
* * * * * cd Desktop && /usr/bin/python3.5m Morning.py >> Output.out
I can see my code executes but chronium browser will not open. Can any of you help
I had the same problem as you. Your job fails because it requires an X session, since you're trying to open a web browser. You should place export DISPLAY=:0; after the schedule in your cronjob, as in
* * * * * export DISPLAY=:0; cd Desktop && /usr/bin/python3.5m Morning.py >> Output.out
But note that cd Desktop && /usr/bin/python3.5m Morning.py might also not work with cron. It is advised to just put multiple commands into a .sh script that has been chmod +x'd.
If this doesn't work, you could replace :0 with the output of echo $DISPLAY in a graphical terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With