summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <yuval@y3xz.com>2016-01-01 12:19:41 +0200
committerYuval Adam <yuval@y3xz.com>2016-01-01 12:19:41 +0200
commitdcd266d1ee8996309f100769e92fcfc58bf61600 (patch)
treef358a4d1fae62bbbe9ad372bda6b872f4fbd9cbb
parent6444fe07ec8a805f1ef83fa2c7573fb1914e0330 (diff)
Add /imgs endpoint
-rw-r--r--geshem.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/geshem.py b/geshem.py
index 511802f..95eb4d5 100644
--- a/geshem.py
+++ b/geshem.py
@@ -2,8 +2,8 @@ import redis
import requests
from datetime import datetime
-from flask import Flask, render_template
-from os import environ
+from flask import Flask, jsonify, render_template
+from os import environ, listdir
from pathlib import Path
from pytz import utc, timezone
from redis.exceptions import ConnectionError
@@ -21,10 +21,10 @@ def fetch_latest_images(local=False):
res = r[-3:]
for ts, url in imgs:
if not local:
- if redis.get('processed:{}'.format(ts)):
+ if redis.get('processed:{}:{}'.format(res, ts)):
continue
else:
- redis.set('processed:{}'.format(ts), '1')
+ redis.set('processed:{}:{}'.format(res, ts), '1')
dt = datetime.strptime(ts, '%Y:%m:%d:%H:%M').strftime('%Y%m%d_%H%M%S')
image = requests.get('http://' + url)
if not local:
@@ -35,10 +35,26 @@ def fetch_latest_images(local=False):
with open(str(STATIC_DIR / 'img' / filename), 'wb+') as f:
f.write(image.content)
+@app.route('/imgs')
+def get_imgs():
+ img_files = sorted(
+ filter(
+ lambda f: f.endswith('.png'), listdir(str(STATIC_DIR / 'img'))
+ ), reverse=True
+ )
+ img_140_files = list(filter(lambda f: f.endswith('140.png'), img_files))
+ img_280_files = list(filter(lambda f: f.endswith('280.png'), img_files))
+ imgs = {
+ '140': img_140_files[:7],
+ '280': img_280_files[:7]
+ }
+ return jsonify(imgs)
+
@app.route('/')
def home():
return render_template('index.html')
+
@app.after_request
def update_images(response):
# poor man's background task