From 9bc622faf49397aac757f3e94f183325bdc1acfe Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Thu, 31 Dec 2015 22:45:11 +0200 Subject: Fetch all latest images with caching --- geshem.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/geshem.py b/geshem.py index 19eb984..eaf1060 100644 --- a/geshem.py +++ b/geshem.py @@ -17,9 +17,14 @@ redis = redis.from_url(environ.get('REDIS_URL', 'redis://localhost')) def fetch_latest_images(local=False): maps_json = requests.get(MAPS_JSON).json() for r in ['images140', 'images280']: - imgs = sorted(maps_json[r].items(), key=lambda x: x[0], reverse=True)[:1] # only take latest + imgs = sorted(maps_json[r].items(), key=lambda x: x[0], reverse=True) res = r[-3:] for ts, url in imgs: + if not local: + if redis.get('processed:{}'.format(ts)): + continue + else: + redis.set('processed:{}'.format(ts)) dt = datetime.strptime(ts, '%Y:%m:%d:%H:%M').strftime('%Y%m%d_%H%M%S') image = requests.get('http://' + url) if not local: -- cgit v1.3.1