Mercurial > hg > index.fcgi > www > www-1
changeset 112:17454b47b15f
add myw2
author | paulo |
---|---|
date | Sun, 28 Jun 2020 20:53:33 -0700 |
parents | 320904a2e311 |
children | 2b5d93c5628a |
files | myw2/Dockerfile myw2/myw_flask_app.py myw2/requirements.pip myw2/static/index.css |
diffstat | 4 files changed, 91 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/myw2/Dockerfile Sun Jun 28 20:53:33 2020 -0700 1.3 @@ -0,0 +1,17 @@ 1.4 +# Use the official lightweight Python image. 1.5 +# https://hub.docker.com/_/python 1.6 +FROM python:3.6-slim 1.7 + 1.8 +# Copy local code to the container image. 1.9 +ENV APP_HOME /app 1.10 +WORKDIR $APP_HOME 1.11 +COPY . ./ 1.12 + 1.13 +# Install production dependencies. 1.14 +RUN pip install -r requirements.pip 1.15 + 1.16 +# Run the web service on container startup. Here we use the gunicorn 1.17 +# webserver, with one worker process and 8 threads. 1.18 +# For environments with multiple CPU cores, increase the number of workers 1.19 +# to be equal to the cores available. 1.20 +CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 myw_flask_app:app
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/myw2/myw_flask_app.py Sun Jun 28 20:53:33 2020 -0700 2.3 @@ -0,0 +1,45 @@ 2.4 +import collections 2.5 + 2.6 +import flask 2.7 +import markupsafe 2.8 + 2.9 +from html3.html3 import HTML 2.10 + 2.11 + 2.12 +app = flask.Flask(__name__) 2.13 + 2.14 + 2.15 +REDIRECTS = collections.OrderedDict({ 2.16 + "desktop": "http://forecast.weather.gov/MapClick.php?lat=37.63048605200049&lon=-122.41107706299971", 2.17 + "mobile": "http://mobile.weather.gov/index.php?lat=37.61961&lon=-122.36558", 2.18 + "radar": "https://radar.weather.gov/lite/N0R/MUX_loop.gif", 2.19 + "hourly": "http://forecast.weather.gov/meteograms/Plotter.php?lat=37.6305&lon=-122.4111&wfo=MTR&zcode=CAZ508&gset=18&gdiff=3&unit=0&tinfo=PY8&ahour=0&pcmd=11011111111110000000000000000000000000000000000000000000000&lg=en&indu=1!1!1!&dd=&bw=&hrspan=48&pqpfhr=6&psnwhr=6", 2.20 + "goes": "https://www.star.nesdis.noaa.gov/GOES/sector.php?sat=G17§or=psw", 2.21 +}) 2.22 + 2.23 + 2.24 +@app.route("/") 2.25 +def index(): 2.26 + root = HTML("html") 2.27 + 2.28 + header = root.head 2.29 + header.title("myw") 2.30 + header.link(rel="stylesheet", type="text/css", 2.31 + href=flask.url_for("static", filename="index.css")) 2.32 + 2.33 + body = root.body(klass="body") 2.34 + 2.35 + for i in REDIRECTS: 2.36 + div = body.div() 2.37 + div.a(i.capitalize(), href=flask.url_for("show_target", target=i)) 2.38 + 2.39 + return str(root).encode("utf-8") 2.40 + 2.41 + 2.42 +@app.route("/<target>") 2.43 +def show_target(target): 2.44 + safe_target = markupsafe.escape(target) 2.45 + if safe_target in REDIRECTS: 2.46 + return flask.redirect(REDIRECTS[safe_target], code=301) 2.47 + else: 2.48 + flask.abort(404)
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/myw2/requirements.pip Sun Jun 28 20:53:33 2020 -0700 3.3 @@ -0,0 +1,8 @@ 3.4 +click==7.1.2 3.5 +Flask==1.1.2 3.6 +gunicorn==20.0.4 3.7 +html3==1.18 3.8 +itsdangerous==1.1.0 3.9 +Jinja2==2.11.2 3.10 +MarkupSafe==1.1.1 3.11 +Werkzeug==1.0.1
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/myw2/static/index.css Sun Jun 28 20:53:33 2020 -0700 4.3 @@ -0,0 +1,21 @@ 4.4 +body 4.5 +{ 4.6 + background-color: #111; 4.7 + color: #ccc; 4.8 +} 4.9 + 4.10 +a:link 4.11 +{ 4.12 + color: #831; 4.13 +} 4.14 + 4.15 +a:visited 4.16 +{ 4.17 + color: gray; 4.18 +} 4.19 + 4.20 +div { 4.21 + text-align: center; 4.22 + line-height: 2; 4.23 + font-size: 500%; 4.24 +}