summaryrefslogtreecommitdiff
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
parent8a99e664b9f095a1b53dcaa380daaa35b1093c18 (diff)
parent15984540740a580ccc16131d47d2e9899510b0c7 (diff)
Merge branch 'flask'
-rw-r--r--.gitignore3
-rw-r--r--Procfile1
-rw-r--r--geshem.py28
-rw-r--r--img/140.pngbin182715 -> 0 bytes
-rw-r--r--img/280_0.pngbin119540 -> 0 bytes
-rw-r--r--img/280_1.pngbin91892 -> 0 bytes
-rw-r--r--img/280_2.pngbin114716 -> 0 bytes
-rw-r--r--img/280_3.pngbin114757 -> 0 bytes
-rw-r--r--img/280_4.pngbin115120 -> 0 bytes
-rw-r--r--requirements.txt7
-rw-r--r--runtime.txt1
-rw-r--r--static/.keep0
-rw-r--r--templates/index.html (renamed from index.html)51
13 files changed, 58 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e31ab26
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.pyc
+__pycache__/
+static/
diff --git a/Procfile b/Procfile
new file mode 100644
index 0000000..683410a
--- /dev/null
+++ b/Procfile
@@ -0,0 +1 @@
+web: gunicorn geshem:app \ No newline at end of file
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)
diff --git a/img/140.png b/img/140.png
deleted file mode 100644
index e2394d5..0000000
--- a/img/140.png
+++ /dev/null
Binary files differ
diff --git a/img/280_0.png b/img/280_0.png
deleted file mode 100644
index 979cef4..0000000
--- a/img/280_0.png
+++ /dev/null
Binary files differ
diff --git a/img/280_1.png b/img/280_1.png
deleted file mode 100644
index 48af202..0000000
--- a/img/280_1.png
+++ /dev/null
Binary files differ
diff --git a/img/280_2.png b/img/280_2.png
deleted file mode 100644
index f98fa52..0000000
--- a/img/280_2.png
+++ /dev/null
Binary files differ
diff --git a/img/280_3.png b/img/280_3.png
deleted file mode 100644
index 98bfe2a..0000000
--- a/img/280_3.png
+++ /dev/null
Binary files differ
diff --git a/img/280_4.png b/img/280_4.png
deleted file mode 100644
index 327d39c..0000000
--- a/img/280_4.png
+++ /dev/null
Binary files differ
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..41bd02d
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,7 @@
+Flask==0.10.1
+Jinja2==2.8
+MarkupSafe==0.23
+Werkzeug==0.10.4
+gunicorn==19.3.0
+itsdangerous==0.24
+requests==2.8.1
diff --git a/runtime.txt b/runtime.txt
new file mode 100644
index 0000000..8f76fd1
--- /dev/null
+++ b/runtime.txt
@@ -0,0 +1 @@
+python-3.5.0 \ No newline at end of file
diff --git a/static/.keep b/static/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/static/.keep
diff --git a/index.html b/templates/index.html
index ca9386a..8437a60 100644
--- a/index.html
+++ b/templates/index.html
@@ -39,6 +39,11 @@ var mapStyle = {
"mapbox": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v6"
+ },
+ "overlay": {
+ "type": "image",
+ "url": "/static/280.png",
+ "coordinates": RASTER_COORDS_280
}
},
"sprite": "mapbox://sprites/mapbox/dark-v8",
@@ -65,6 +70,19 @@ var mapStyle = {
"paint": {"line-color": "#797979"}
},
{
+ "id": "water2",
+ "source": "mapbox",
+ "source-layer": "water",
+ "type": "fill",
+ "paint": {"fill-color": "#111122"}
+ },
+ {
+ "id": "overlay",
+ "source": "overlay",
+ "type": "raster",
+ "paint": {"raster-opacity": 0.85}
+ },
+ {
"id": "cities",
"source": "mapbox",
"source-layer": "place_label",
@@ -112,39 +130,6 @@ var map = new mapboxgl.Map({
style: mapStyle,
hash: false
});
-
-function changeToImage(num){
- map.addSource('overlay'+num,{
- "type": "image",
- "url": "/img/280_"+num+".png",
- "coordinates": RASTER_COORDS_280
- }
- );
- if (map.getLayer("overlay")) {
- map.removeSource(map.getLayer("overlay").source);
- map.removeLayer('overlay');
- }
- map.addLayer({
- "id": "overlay",
- "source": "overlay"+num,
- "type": "raster",
- "paint": {"raster-opacity": 0.85}
- },"cities");
- map.update(true);
-}
-
-map.on('load', function(){
- var count = 0;
- var nextImage = function(){
- changeToImage(count);
- count = count+1;
- if(count>4) count = 0;
- }
-
- window.setInterval(nextImage, 1000);
-});
-
-
</script>
</body>