summaryrefslogtreecommitdiff
path: root/geshem.py
diff options
context:
space:
mode:
authorYuval Adam <yuval@y3xz.com>2015-11-07 00:31:11 +0200
committerYuval Adam <yuval@y3xz.com>2015-11-07 00:32:00 +0200
commit13447f97f73d9a94b13775ef8947c53253d93212 (patch)
tree51510f602601f18749dccec8591af7280d7fc4af /geshem.py
parent8a99e664b9f095a1b53dcaa380daaa35b1093c18 (diff)
parent15984540740a580ccc16131d47d2e9899510b0c7 (diff)
Merge branch 'flask'
Diffstat (limited to 'geshem.py')
-rw-r--r--geshem.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/geshem.py b/geshem.py
new file mode 100644
index 0000000..0d4ab75
--- /dev/null
+++ b/geshem.py
@@ -0,0 +1,28 @@
+import requests
+
+from flask import Flask, render_template
+from pathlib import Path
+
+MAPS_JSON = 'http://map.govmap.gov.il/rainradar/radar.json'
+STATIC_DIR = Path(__file__).resolve().parents[0] / 'static'
+
+app = Flask(__name__)
+
+
+def fetch_latest_images():
+ 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
+ for _ts, url in imgs:
+ image = requests.get('http://' + url)
+ filename = r[-3:] + '.png'
+ with open(str(STATIC_DIR / filename), 'wb+') as f:
+ f.write(image.content)
+
+@app.route('/')
+def home():
+ fetch_latest_images()
+ return render_template('index.html')
+
+if __name__ == '__main__':
+ app.run(debug=True)