V
V
Vitaly2015-04-29 11:35:06
Python
Vitaly, 2015-04-29 11:35:06

Automatic file upload?

Good afternoon!
Task: Download a file at a specified time and location.
Conditions: There is a website and direct links to the file. You need to download this file twice every day.
Difficulty: Every day the file name changes "2015-04-29_10-59.mp4" -> "2015-04-30_10-59.mp4" etc.
The file address also changes " http://***/2015-04-29/ " -> http://***/2015-04-30/ "(Accordingly, only the date changes, which, as I understand it, can be taken from systems.)
What I can do: I'm learning python but haven't figured out how to do it yet.Are there ready-made programs for these tasks or what method is more appropriate to use in this situation?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Kitaev, 2015-04-29
@zet694

Requests you need.
Well, datetime.

from datetime import datetime
import requests

now = datetime.now().strftime('%Y-%m-%d_%H-%M')
string_that_you_need = now + '.mp4'  # Сейчас это выглядит, как "2015-04-29_10-59.mp4"
request = requests.get('http://site.that/you/need/%s' % string_that_you_need)
f = open('file.mp4', 'wb')
f.write(request.content)
f.close()

V
Vladimir Martyanov, 2015-04-29
@vilgeforce

The current date into a string in the required format, this string into the right places in the URL, and, in general, that's all.

B
bromzh, 2015-04-29
@bromzh

If you have Linux or something similar, then the usual bash is enough:

#!/bin/sh
now="$(date +'%Y-%m-%d')"
url="http://example.com/$now/$now.mp4"
wget -c -P /папка/куда/сохранять/ $url

And put it in your daily cron.
Look at the wget options, there are a lot of different things, such as retry on error, downloading a directory / the entire site, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question