diff options
| author | Yuval Adam <_@yuv.al> | 2017-10-21 18:10:55 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2017-10-21 18:10:55 +0300 |
| commit | 535389cd00f66b6d7c2087c4c42b0021a90a80f1 (patch) | |
| tree | 27e7af3ef3508fda98041213a8e18367d22f55f3 | |
| parent | aaea9e2ce63494072c6bb6b5a92be97dfb03a11b (diff) | |
Bye bye python
| -rw-r--r-- | geshem.py | 77 | ||||
| -rw-r--r-- | requirements.txt | 14 | ||||
| -rw-r--r-- | runtime.txt | 1 |
3 files changed, 0 insertions, 92 deletions
diff --git a/geshem.py b/geshem.py deleted file mode 100644 index b192e08..0000000 --- a/geshem.py +++ /dev/null @@ -1,77 +0,0 @@ -import redis -import requests - -from datetime import datetime -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 - -MAPS_JSON = 'http://map.govmap.gov.il/rainradar/radar.json' -STATIC_DIR = Path(__file__).resolve().parents[0] / 'static' - -app = Flask(__name__) -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) - res = r[-3:] - for ts, url in imgs: - if not local: - if redis.get('processed:{}:{}'.format(res, ts)): - continue - else: - 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: - redis.set('latest_{}'.format(res), dt) - else: - dt = 'dev' - filename = '{}_{}.png'.format(dt, res) - with open(str(STATIC_DIR / 'img' / filename), 'wb+') as f: - f.write(image.content) - -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 imgs - -@app.route('/imgs') -def imgs(): - return jsonify(get_imgs()) - -@app.route('/') -def home(): - return render_template('index.html', imgs=get_imgs()) - -@app.after_request -def update_images(response): - # poor man's background task - try: - if not redis.get('fresh'): - redis.setex('fresh', 'yes', 60) - fetch_latest_images() - except ConnectionError as e: - if app.debug: - fetch_latest_images(local=True) - return response - -@app.context_processor -def inject_debug(): - return dict(debug=app.debug) - -if __name__ == '__main__': - app.run(host='0.0.0.0', debug=True) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 110c676..0000000 --- a/requirements.txt +++ /dev/null @@ -1,14 +0,0 @@ -certifi==2017.7.27.1 -chardet==3.0.4 -click==6.7 -Flask==0.12.2 -gunicorn==19.7.1 -idna==2.6 -itsdangerous==0.24 -Jinja2==2.9.6 -MarkupSafe==1.0 -pytz==2017.2 -redis==2.10.6 -requests==2.18.4 -urllib3==1.22 -Werkzeug==0.12.2 diff --git a/runtime.txt b/runtime.txt deleted file mode 100644 index cfa5aa5..0000000 --- a/runtime.txt +++ /dev/null @@ -1 +0,0 @@ -python-3.6.2 |
