forked from nnja/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (30 loc) · 1.14 KB
/
app.py
File metadata and controls
40 lines (30 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
A Simple Flask Web Application interface
For viewing popular GitHub Repos sorted by stars using the
GitHub Search API.
To run:
(env) $ python -m pip install -r requirements.txt
(env) $ export FLASK_ENV=development; python3 -m flask run
"""
from flask import Flask, render_template, request
from repos.api import repos_with_most_stars
from repos.exceptions import GitHubApiException
app = Flask(__name__)
available_languages = ["Python", "JavaScript", "Ruby", "Java"]
@app.route('/', methods=['POST', 'GET'])
def index():
if request.method == 'GET':
# Use the list of all languages
selected_languages = available_languages
elif request.method == 'POST':
# Use the languages we selected in the request form
selected_languages = request.form.getlist("languages")
results = repos_with_most_stars(selected_languages)
return render_template(
'index.html',
selected_languages=selected_languages,
available_languages=available_languages,
results=results)
@app.errorhandler(GitHubApiException)
def handle_api_error(error):
return render_template('error.html', message=error)