drifterf
Posts: 134
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
Posts: 4465
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

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
Need Pi spray - these things are breeding in my house...

drifterf
Posts: 134
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: 15178
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: 134
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”