Answer the question
In order to leave comments, you need to log in
How to compare Last-Modified with http header and file last modification time?
>>>
>>> r = requests.get('https://ya.ru')
>>>
>>>
>>> r.headers['Last-Modified']
'Tue, 04 Sep 2018 07:46:09 GMT'
touch /tmp/1.txt
Answer the question
In order to leave comments, you need to log in
>>> import datetime
>>> dt = parse(r.headers['Last-Modified'])
>>> dt_header = dt.replace(tzinfo=None)
>>> mtime = os.path.getmtime('/tmp/1.txt')
>>> dt_file = datetime.datetime.fromtimestamp(mtime)
>>> if dt_file > dt_header:
... print(1)
...
1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question