From 9eddc03cf1f1c98e764db3afc28482bad858c1ea Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Wed, 9 Aug 2017 18:27:05 +0200 Subject: [PATCH] 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. --- instaloader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instaloader.py b/instaloader.py index b0fec86..fb66584 100755 --- a/instaloader.py +++ b/instaloader.py @@ -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)