diff options
| author | Yuval Adam <yuval@y3xz.com> | 2015-11-07 00:29:11 +0200 |
|---|---|---|
| committer | Yuval Adam <yuval@y3xz.com> | 2015-11-07 00:29:11 +0200 |
| commit | 15984540740a580ccc16131d47d2e9899510b0c7 (patch) | |
| tree | 9f276ca42921e7f86ef4834e5f965cc8164fa1e9 | |
| parent | 98ec7b35afb5a59e7db6af842c63b71216dc73d3 (diff) | |
Serve geshem from flask app and import latest imagery
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Procfile | 1 | ||||
| -rw-r--r-- | geshem.py | 28 | ||||
| -rw-r--r-- | requirements.txt | 7 | ||||
| -rw-r--r-- | runtime.txt | 1 | ||||
| -rw-r--r-- | static/.keep | 0 | ||||
| -rw-r--r-- | templates/index.html (renamed from index.html) | 9 |
7 files changed, 48 insertions, 1 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/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 8b77ded..8d14542 100644 --- a/index.html +++ b/templates/index.html @@ -42,7 +42,7 @@ var mapStyle = { }, "overlay": { "type": "image", - "url": "/img/280.png", + "url": "/static/280.png", "coordinates": RASTER_COORDS_280 } }, @@ -70,6 +70,13 @@ 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", |
