python - Adding timestamp to file downloaded with urllib.urlretrieve -
i using urllib.urlretrieve download files, add check changes before downloading. have following:
import urllib urllib.urlretrieve("http://www.site1.com/file.txt", r"output/file1.txt") urllib.urlretrieve("http://www.site2.com/file.txt", r"output/file2.txt") ideally script check changes (compare last modified stamp?), ignore if same , download if newer, need script add timestamp filename.
can help?
i new programming (python first) criticism welcome!
the simplest approach timestamp in filename is:
import time 'output/file_%d.txt' % time.time() human readable way:
from datetime import datetime n = datetime.now() n.strftime('output/file_%y%m%d_%h%m%s.txt')
Comments
Post a Comment