Skip to content

Commit 318730a

Browse files
authored
Merge pull request #34 from pyvec/honzajavorek/api
Add dead simple API
2 parents 59a0ba4 + 09218d3 commit 318730a

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/_build/
1+
# Elsa output
2+
_build
23

34
### OSX
45
*.DS_Store

pyvecorg/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ def run(self, *args, **kwargs):
2121

2222

2323
app = Flask('pyvecorg')
24+
app.config['JSON_AS_ASCII'] = False
25+
2426

2527
from pyvecorg import views
2628
from pyvecorg import templating
2729

30+
2831
__all__ = ['app', 'views', 'templating']

pyvecorg/data/meta.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ downloads:
6868
resources:
6969
cs: grafika
7070
en: resources
71+
json_data:
72+
cs: tato stránka jako JSON
73+
en: this page as JSON

pyvecorg/data/meta_schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
},
6161
"resources": {
6262
"$ref": "definitions/translated_text_schema.json#"
63+
},
64+
"json_data": {
65+
"$ref": "definitions/translated_text_schema.json#"
6366
}
6467
},
6568
"additionalProperties": false

pyvecorg/templates/index.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
<head>
44
<meta charset="utf-8">
55

6-
<link rel="shortcut icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.ico') }}">
6+
<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="{{ url_for('static', filename='favicon.ico') }}">
7+
<link rel="alternate" type="application/json" href="{{ url_for('api', lang=lang) }}">
8+
79
<meta property="og:image" content="{{ url_for('static', filename='img/cover.jpg', _external=True) }}">
810
<meta property="twitter:card" content="summary_large_image">
911
<meta property="twitter:site" content="@pyvec">
@@ -240,8 +242,13 @@ <h3>{{ meta.downloads.heading }}</h3>
240242
<i class="fa fa-file-text-o" aria-hidden="true"></i>
241243
<a href="{{ url_for('static', filename='charter/stanovy.rtf') }}">{{ meta.downloads.charter }}.rtf</a>
242244

245+
<br>
246+
243247
<i class="fa fa-file-image-o" aria-hidden="true"></i>
244248
<a href="https://github.com/pyvec/resources">{{ meta.downloads.resources }}</a>
249+
250+
<i class="fa fa-file-code-o" aria-hidden="true"></i>
251+
<a href="{{ url_for('api', lang=lang) }}">{{ meta.downloads.json_data }}</a>
245252
</p>
246253
</div>
247254
<div class="w-100 d-block d-md-none"></div>

pyvecorg/views.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from datetime import datetime
33

44
from flask import (request, render_template, redirect, url_for,
5-
send_from_directory)
5+
send_from_directory, jsonify)
66

77
from pyvecorg import app
88
from pyvecorg.data import load_data, select_language
@@ -11,23 +11,26 @@
1111
data = load_data()
1212

1313

14-
@app.route('/')
15-
def index_redirect():
16-
if request.accept_languages.best_match(['en', 'cs', 'sk']) == 'en':
17-
return redirect(url_for('index', lang='en'))
18-
return redirect(url_for('index', lang='cs'))
19-
20-
2114
@app.route('/favicon.ico')
2215
def favicon():
2316
static = os.path.join(app.root_path, 'static')
2417
return send_from_directory(static, 'favicon.ico',
2518
mimetype='image/vnd.microsoft.icon')
2619

2720

21+
@app.route('/')
22+
def index_redirect():
23+
return redirect(url_for('index', lang='cs'))
24+
25+
2826
@app.route('/<lang>/')
2927
def index(lang):
3028
context = select_language(data, lang)
3129
context['lang'] = lang
3230
context['now'] = datetime.now()
3331
return render_template('index.html', **context)
32+
33+
34+
@app.route('/<lang>/api.json')
35+
def api(lang):
36+
return jsonify(select_language(data, lang))

0 commit comments

Comments
 (0)