Answer the question
In order to leave comments, you need to log in
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
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()
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.
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question