This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.py
73 lines (58 loc) · 1.97 KB
/
app.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
__author__ = 'schwa'
from flask import Flask
from flask import render_template
from flask import url_for
from flask import request
import json
import os
app = Flask(__name__)
types_by_identifier = json.load(file('processed.json'))
@app.route("/")
@app.route("/roots")
def roots():
hits = []
for t in types_by_identifier.values():
if 'UTTypeConformsTo' not in t or not t['UTTypeConformsTo']:
hits.append(t)
hits = sorted(hits, key = lambda t:t['UTTypeIdentifier'])
return render_template('list.html', all_types = hits)
@app.route("/all")
def all():
hits = types_by_identifier.values()
hits = sorted(hits, key = lambda t:t['UTTypeIdentifier'])
return render_template('list.html', all_types = hits)
@app.route("/public")
def public():
hits = []
for t in types_by_identifier.values():
if 'UTTypeConformsTo' not in t or not t['UTTypeConformsTo']:
if t['UTTypeIdentifier'].startswith('public.'):
hits.append(t)
hits = sorted(hits, key = lambda t:t['UTTypeIdentifier'])
return render_template('list.html', all_types = hits)
@app.route("/identifier/<identifier>")
def type_(identifier):
t = types_by_identifier[identifier]
image_path = url_for('static', filename='iconsets')
return render_template('type.html', type = t, image_path = image_path)
@app.route('/search', methods = ['POST'])
def search():
query = request.form['query']
hits = []
for t in types_by_identifier.values():
if query in t['UTTypeIdentifier']:
hits.append(t)
return render_template('list.html', all_types = hits)
# if __name__ == "__main__":
# if os.environ.get('PYCHARM_HOSTED', False):
# app.debug = True
# app.run()
# else:
# app.run()
if __name__ == '__main__':
host = '0.0.0.0'
port = int(os.environ.get('PORT', 5000))
if os.environ.get('DEVELOPMENT', False):
host = None
app.debug = True
app.run(host = host, port = port)