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

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -