Open google using Python and Cron job

Today, I will share to you all on how to open google using python.

I have been looking for a few days on how to do it. The problem is:

  1. My script which is in python “test.py” that used os command. Below is my code:

#——————————————————————#

import webbrowser
import sys
import subprocess
import os
import lxml.html

import webbrowser
import sys
import subprocess
import os
import lxml.html

a_website = “http://www.google.com.my”
webbrowser.open_new(a_website)
print(“Done”);
os.system(‘xdotool mousemove 600 513’)
os.system(‘xdotool click 1’)

#——————————————————————#

2. So how are going to type in cron job since this python used os command. Some tutorials that I read not shows in detail on how to do it. Below is my commands in cron job:

#m h dom mon dow command

XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0

03 07 * * * cd /home/pi && /usr/bin/python3.7 test.py >> login.out

You need to put XD_RUN …. and also DISPLAY =:0. Then you can set time and path of your source file.

Voila !!!

Below is coding if it not works:

XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0

#20 04 * * * DISPLAY=:0 && cd /usr/local/bin/ && sh refresh.sh

40 04 * * * DISPLAY=:0 && cd /home/pi/ && python3 xdotool_login.py >> login.txt

#31 04 * * * DISPLAY=:0 && cd /home/pi && /usr/bin/python3.7 xdotool_login.py >$

#36 04 * * * cd /home/pi && /usr/bin/python3.7 xdotool_login.py >> login.txt