1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-09-11 16:22:24 +02:00

Don't rely on fromtimestamp() raising ValueError

Instead of relying on that datetime.fromtimestamp() raises ValueError if
the timestamp of a story is in milliseconds rather than seconds, we now
compare the timestamp value with a timestamp of the year 2286 to decide
whether to divide it by 1000 or not.

This is motivated by #30, where an OSError is raised in
datetime.fromtimestamp() under Windows.
This commit is contained in:
Alexander Graf 2017-08-09 18:27:05 +02:00
parent 42864997b3
commit 9eddc03cf1

View File

@ -714,9 +714,9 @@ class Instaloader:
shortcode = item["code"] if "code" in item else "no_code"
date_float = item["device_timestamp"] if "device_timestamp" in item else item["taken_at"]
try:
if date_float < 10000000000:
date = datetime.fromtimestamp(date_float)
except ValueError:
else:
# device_timestamp seems to sometime be in milliseconds
date_float /= 1000
date = datetime.fromtimestamp(date_float)