feat(onomastics): web server for geogen
This commit is contained in:
25
onomastics/geogen/cli.py
Executable file
25
onomastics/geogen/cli.py
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Output SVG maps of surnames.
|
||||
Powered by Christoph Stöpel's Geogen API.
|
||||
|
||||
Usage:
|
||||
geogen.py relative <name>... [--color=<color>]
|
||||
geogen.py absolute <name>... [--color=<color>]
|
||||
geogen.py (-h | --help)
|
||||
|
||||
Options:
|
||||
-h --help Show this screen.
|
||||
--color=<color> Diagram accent colour.
|
||||
"""
|
||||
from docopt import docopt
|
||||
import geogen.client
|
||||
|
||||
|
||||
def cli():
|
||||
arguments = docopt(__doc__)
|
||||
df = geogen.client.create_data_frame(arguments["<name>"])
|
||||
color = arguments["--color"] or "navy"
|
||||
if arguments["relative"]:
|
||||
print(geogen.client.generate_map(df, "relative", fill_color=color))
|
||||
elif arguments["absolute"]:
|
||||
print(geogen.client.generate_map(df, "absolute", fill_color=color))
|
||||
24
onomastics/geogen → onomastics/geogen/client.py
Executable file → Normal file
24
onomastics/geogen → onomastics/geogen/client.py
Executable file → Normal file
@@ -1,17 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Output SVG maps of surnames.
|
||||
Powered by Christoph Stöpel's Geogen API.
|
||||
|
||||
Usage:
|
||||
geogen.py relative <name>... [--color=<color>]
|
||||
geogen.py absolute <name>... [--color=<color>]
|
||||
geogen.py (-h | --help)
|
||||
|
||||
Options:
|
||||
-h --help Show this screen.
|
||||
--color=<color> Diagram accent colour.
|
||||
"""
|
||||
from docopt import docopt
|
||||
import pandas as pd
|
||||
import requests
|
||||
import requests_cache
|
||||
@@ -90,13 +76,3 @@ def generate_map(df, key, fill_color):
|
||||
<g>{unlines(district_paths)}</g>
|
||||
<g>{unlines(state_paths)}</g>
|
||||
</svg>"""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
arguments = docopt(__doc__)
|
||||
df = create_data_frame(arguments["<name>"])
|
||||
color = arguments["--color"] or "navy"
|
||||
if arguments["relative"]:
|
||||
print(generate_map(df, "relative", fill_color=color))
|
||||
elif arguments["absolute"]:
|
||||
print(generate_map(df, "absolute", fill_color=color))
|
||||
32
onomastics/geogen/server.py
Normal file
32
onomastics/geogen/server.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from flask import Flask, request, Response
|
||||
import geogen.client
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/<name>/relative.svg")
|
||||
def relative(name):
|
||||
color = request.args.get("color") or "navy"
|
||||
df = geogen.client.create_data_frame([name])
|
||||
return geogen.client.generate_map(df, "relative", fill_color=color)
|
||||
|
||||
|
||||
@app.route("/<name>/data.csv")
|
||||
def relative_csv(name):
|
||||
df = (
|
||||
geogen.client.create_data_frame([name])
|
||||
.drop(columns=["path"])
|
||||
.sort_values(by="absolute", ascending=False)
|
||||
)
|
||||
return Response(df.to_csv(index=False), mimetype="text/csv")
|
||||
|
||||
|
||||
@app.route("/<name>/absolute.svg")
|
||||
def absolute(name):
|
||||
color = request.args.get("color") or "navy"
|
||||
df = geogen.client.create_data_frame([name])
|
||||
return geogen.client.generate_map(df, "absolute", fill_color=color)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0")
|
||||
Reference in New Issue
Block a user