Skip to content

Commit a2fc2a6

Browse files
committed
Adding docs
1 parent 5dc9f4b commit a2fc2a6

10 files changed

+686
-5
lines changed

Pipfile

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ flask-cors = "*"
1010
flask-graphql = "*"
1111
graphene = ">=2.0"
1212
gunicorn = "*"
13+
markdown = "*"
14+
pygments = "*"
1315

1416
[dev-packages]
1517

Pipfile.lock

+17-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
### Mtaa API
1+
# Mtaa API
2+
3+
[Mtaa API](https://mtaa-api.herokuapp.com) is a simple REST(And later GraphQL) API for accessing Tanzania locations.
4+
5+
Mtaa API is powered by [mtaa](https://github.com/Kalebu/mtaa).
6+
7+
## Why?
8+
9+
Most of the time when coding, we found ourselves in need of some location data, especially for our country, [Tanzania](https://en.wikipedia.org/wiki/Tanzania).
10+
11+
We didn't like the idea of scraping some public sites because we had the feeling that we was spending more time understanding the site and cleaning the data than focusing on my task.
12+
13+
But we liked the idea of a public API for developers. So I decided to code a little Flask server inspired by our [tanzania-locations-db](https://github.com/HackEAC/tanzania-locations-db), [mtaa](https://github.com/Kalebu/mtaa) and here is Mtaa API.
14+
15+
You can find it running here and are free to use it in your developments: [https://mtaa-api.herokuapp.com/api](https://mtaa-api.herokuapp.com/api).
16+
17+
I hope you will find it useful.
18+
19+
## Features
20+
21+
* No registration
22+
* Zero-config
23+
* Basic API
24+
* Cross-domain ([CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing))
25+
* Supports GET and POST(GraphQL) verbs
26+
* Compatible with React, Angular, Vue, Ember, ...
27+
<!-- * HTTP or HTTPS -->
28+
<!-- * "Has many" relationships -->
29+
<!-- * Filters and nested resources -->
30+
31+
## Guide
32+
33+
For examples and more, documentation coming soon... <!-- you can visit https://mtaa-api.herokuapp.com -->

api/__init__.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
from os import system, urandom, path, getcwd
12
from flask import Flask
23
from flask_cors import CORS
34
from flask_graphql import GraphQLView
45

56
def create_app():
6-
app = Flask(__name__)
7+
app = Flask(__name__,
8+
template_folder=path.join(getcwd(), "templates"),
9+
static_folder=path.join(getcwd(), "static")
10+
)
11+
app.config['SECRET_KEY'] = urandom(64)
712

813
CORS(app)
914

@@ -19,6 +24,13 @@ def create_app():
1924
batch=True
2025
)
2126
)
27+
28+
# system('rm static/*.css')
29+
# system('mv templates/README.html templates/index.html')
30+
31+
# system('generate-md --layout jasonm23-dark --input README.md --output templates')
32+
# system('mv templates/assets/* static/')
33+
# system('rm -rf templates/assets')
2234

2335
with app.app_context():
2436
from . import routes

api/routes.py

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,56 @@
1+
# import markdown
2+
# from os import getcwd, path
13
from flask import current_app as app
2-
from flask import jsonify
4+
from flask import jsonify, render_template
35
from mtaa import tanzania
4-
from typing import List, Dict
6+
# from pygments.formatters import HtmlFormatter
7+
# import markdown.extensions.fenced_code
8+
# import markdown.extensions.codehilite
9+
10+
from typing import Dict
11+
12+
@app.route('/', methods=['GET'])
13+
def home():
14+
# readme_file = open(path.join(getcwd(), "README.md"), "r")
15+
# md_template_string = markdown.markdown(
16+
# readme_file.read(), extensions=["fenced_code" ,"codehilite"]
17+
# )
18+
19+
# Generate Css for syntax highlighting
20+
# formatter = HtmlFormatter(style="monokai", full=True, cssclass="codehilite")
21+
# css_string = formatter.get_style_defs()
22+
# md_css_string = "<style>" + css_string + "</style>"
23+
24+
# md_template = "<hmtl><body><head><title>Mtaa API</title>" + md_css_string + "</head>" + md_template_string + "</body></hmtl>"
25+
26+
# return md_template
27+
return render_template('README.html')
28+
29+
@app.route('/api', methods=['GET'])
30+
def api():
31+
return render_template('index.html')
532

633
@app.route('/api/tanzania', methods=['GET'])
734
def tanzan():
35+
"""
36+
Returns a list of all the regions in Tanzania
37+
"""
838
return jsonify({ "regions": list(tanzania.get_dict().keys()) })
939

1040
@app.route('/api/tanzania/<region>', methods=['GET'])
1141
def regions(region: str) -> Dict:
42+
"""
43+
Returns a list of all the districts in the given Region and the region's post code
44+
"""
1245
temp: str = region.lower().capitalize()
1346
payload = tanzania.get_dict()[temp]
1447
return jsonify({ "post_code": payload.post_code if hasattr(payload, 'post_code') else 'None', "districts": list(payload.districts.get_dict().keys()) })
1548

1649
@app.route('/api/tanzania/<region>/<district>', methods=['GET'])
1750
def districts(region: str, district: str) -> Dict:
51+
"""
52+
Returns a list of all the wards in the given District and the district's post code
53+
"""
1854
reg: str = region.lower().capitalize()
1955
temp: str = district.lower().capitalize()
2056
payload = tanzania.get_dict()[reg].districts.get_dict()[temp]
@@ -23,6 +59,9 @@ def districts(region: str, district: str) -> Dict:
2359

2460
@app.route('/api/tanzania/<region>/<district>/<ward>', methods=['GET'])
2561
def wards(region: str, district: str, ward: str) -> Dict:
62+
"""
63+
Returns a list of all the streets in the given Ward and the ward's post code, if any
64+
"""
2665
reg: str = region.lower().capitalize()
2766
dist: str = district.lower().capitalize()
2867
temp: str = ward.lower().capitalize()

static/hljs-github.min.css

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
3+
github.com style (c) Vasily Polovnyov <[email protected]>
4+
5+
*/
6+
7+
.hljs {
8+
display: block;
9+
overflow-x: auto;
10+
padding: 0.5em;
11+
color: #333;
12+
background: #f8f8f8;
13+
-webkit-text-size-adjust: none;
14+
}
15+
16+
.hljs-comment,
17+
.diff .hljs-header,
18+
.hljs-javadoc {
19+
color: #998;
20+
font-style: italic;
21+
}
22+
23+
.hljs-keyword,
24+
.css .rule .hljs-keyword,
25+
.hljs-winutils,
26+
.nginx .hljs-title,
27+
.hljs-subst,
28+
.hljs-request,
29+
.hljs-status {
30+
color: #333;
31+
font-weight: bold;
32+
}
33+
34+
.hljs-number,
35+
.hljs-hexcolor,
36+
.ruby .hljs-constant {
37+
color: #008080;
38+
}
39+
40+
.hljs-string,
41+
.hljs-tag .hljs-value,
42+
.hljs-phpdoc,
43+
.hljs-dartdoc,
44+
.tex .hljs-formula {
45+
color: #d14;
46+
}
47+
48+
.hljs-title,
49+
.hljs-id,
50+
.scss .hljs-preprocessor {
51+
color: #900;
52+
font-weight: bold;
53+
}
54+
55+
.hljs-list .hljs-keyword,
56+
.hljs-subst {
57+
font-weight: normal;
58+
}
59+
60+
.hljs-class .hljs-title,
61+
.hljs-type,
62+
.vhdl .hljs-literal,
63+
.tex .hljs-command {
64+
color: #458;
65+
font-weight: bold;
66+
}
67+
68+
.hljs-tag,
69+
.hljs-tag .hljs-title,
70+
.hljs-rules .hljs-property,
71+
.django .hljs-tag .hljs-keyword {
72+
color: #000080;
73+
font-weight: normal;
74+
}
75+
76+
.hljs-attribute,
77+
.hljs-variable,
78+
.lisp .hljs-body {
79+
color: #008080;
80+
}
81+
82+
.hljs-regexp {
83+
color: #009926;
84+
}
85+
86+
.hljs-symbol,
87+
.ruby .hljs-symbol .hljs-string,
88+
.lisp .hljs-keyword,
89+
.clojure .hljs-keyword,
90+
.scheme .hljs-keyword,
91+
.tex .hljs-special,
92+
.hljs-prompt {
93+
color: #990073;
94+
}
95+
96+
.hljs-built_in {
97+
color: #0086b3;
98+
}
99+
100+
.hljs-preprocessor,
101+
.hljs-pragma,
102+
.hljs-pi,
103+
.hljs-doctype,
104+
.hljs-shebang,
105+
.hljs-cdata {
106+
color: #999;
107+
font-weight: bold;
108+
}
109+
110+
.hljs-deletion {
111+
background: #fdd;
112+
}
113+
114+
.hljs-addition {
115+
background: #dfd;
116+
}
117+
118+
.diff .hljs-change {
119+
background: #0086b3;
120+
}
121+
122+
.hljs-chunk {
123+
color: #aaa;
124+
}

static/pilcrow.css

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
h1,
2+
h2,
3+
h3,
4+
h4,
5+
h5,
6+
h6 {
7+
position: relative;
8+
}
9+
10+
h1:hover .header-link:before,
11+
h2:hover .header-link:before,
12+
h3:hover .header-link:before,
13+
h4:hover .header-link:before,
14+
h5:hover .header-link:before,
15+
h6:hover .header-link:before {
16+
content: "\00B6";/* pilcrow */
17+
color: #888;
18+
font-size: smaller;
19+
}
20+
21+
.header-link {
22+
-webkit-user-select: none;
23+
-moz-user-select: none;
24+
-ms-user-select: none;
25+
user-select: none;
26+
27+
position: absolute;
28+
top: 0;
29+
left: -0.7em;
30+
display: block;
31+
padding-right: 1em;
32+
}
33+
34+
h1:hover .header-link,
35+
h2:hover .header-link,
36+
h3:hover .header-link,
37+
h4:hover .header-link,
38+
h5:hover .header-link,
39+
h6:hover .header-link {
40+
display: inline-block;
41+
text-decoration: none;
42+
}

0 commit comments

Comments
 (0)