From 53fca4d6e4ad8f19b73d1137f5bbe18a3f0881fd Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Nov 14 2019 02:22:06 +0000 Subject: Fix epoch conversion in AMI datagrepper URL for Python 2 I'm still supporting Python 2 here (because I'm an idiot) and datetime .timestamp does not exist in Python 2. Sigh. Signed-off-by: Adam Williamson --- diff --git a/tox.ini b/tox.ini index 81638d1..fa2cc8c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py34,py35,py36,py37 +envlist = py27,py34,py35,py36,py37,py38 skip_missing_interpreters=true [testenv] deps=-r{toxinidir}/install.requires diff --git a/wikitcms/page.py b/wikitcms/page.py index 745cdee..bf767e4 100644 --- a/wikitcms/page.py +++ b/wikitcms/page.py @@ -632,9 +632,12 @@ class AMIPage(Page): date = fedfind.helpers.parse_cid(self.event.ff_release.cid, dic=True)['date'] start = datetime.datetime.strptime(date, '%Y%m%d').replace(tzinfo=pytz.utc) end = start + datetime.timedelta(days=2) - # convert to epoch (this is what datagrepper wants) - start = start.timestamp() - end = end.timestamp() + # convert to epoch (this is what datagrepper wants). In Python + # 3 we can use just .timestamp() but sadly not in Python 2. + # https://stackoverflow.com/questions/6999726 + epoch = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc) + start = (start - epoch).total_seconds() + end = (end - epoch).total_seconds() url = "https://apps.fedoraproject.org/datagrepper/raw" url += "?topic=org.fedoraproject.prod.fedimg.image.publish" url += "&start={0}&end={1}".format(start, end)