drifterf
Posts: 136
Joined: Sat Dec 08, 2018 9:09 am
Location: Northants, England

Script to download a file from internet at time intervals

Wed Aug 14, 2019 4:39 pm

hI, is there a simple python script that when i run it, it downloads a file from a location on the web to a folder on the pi ? or one that could auto do this every hour or so ? thanks

Andyroo

Re: Script to download a file from internet at time intervals

Wed Aug 14, 2019 4:42 pm

Use cron to schedule a simple script the uses wget

Code: Select all

wget https://example.com/files/mydiwnload.dat

drifterf
Posts: 136
Joined: Sat Dec 08, 2018 9:09 am
Location: Northants, England

Re: Script to download a file from internet at time intervals

Wed Aug 14, 2019 5:41 pm

Andyroo wrote:
Wed Aug 14, 2019 4:42 pm
Use cron to schedule a simple script the uses wget

Code: Select all

wget https://example.com/files/mydiwnload.dat
hi, thank you for this, this seems to work great.

the only problem is if the file doesent exist or the pi dosent have internet it dosent retain the existing data as a failover ?

im using this wget to get the data

wget http://www.furniss.uk/Databases/database.csv -O /home/pi/furniss/database/database.csv

User avatar
rpdom
Posts: 15238
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Script to download a file from internet at time intervals

Wed Aug 14, 2019 6:26 pm

Try this version of the command in the crontab

Code: Select all

wget http://www.furniss.uk/Databases/database.csv -O /home/pi/furniss/database/database.tmp && mv /home/pi/furniss/database/database.tmp /home/pi/furniss/database/database.csv
That will download to a temporary file, and then overwrite the real file only if the wget didn't have any errors.

drifterf
Posts: 136
Joined: Sat Dec 08, 2018 9:09 am
Location: Northants, England

Re: Script to download a file from internet at time intervals

Wed Aug 14, 2019 6:38 pm

rpdom wrote:
Wed Aug 14, 2019 6:26 pm
Try this version of the command in the crontab

Code: Select all

wget http://www.furniss.uk/Databases/database.csv -O /home/pi/furniss/database/database.tmp && mv /home/pi/furniss/database/database.tmp /home/pi/furniss/database/database.csv
That will download to a temporary file, and then overwrite the real file only if the wget didn't have any errors.
Thank you, this seems to do the trick !!! much appreciated !!!

Return to “Python”