-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathweb.py
53 lines (47 loc) · 1.46 KB
/
web.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
import flask
import os
import helpers
import __builtin__
from escape_helpers import sparql_escape
from rdflib.namespace import Namespace
app = flask.Flask(__name__)
####################
## Example method ##
####################
@app.route('/templateExample/')
def query():
"""Example query: Returns all the triples in the application graph in a JSON
format."""
q = " SELECT *"
q += " WHERE{"
q += " GRAPH <http://mu.semte.ch/application> {"
q += " ?s ?p ?o"
q += " }"
q += " }"
return flask.jsonify(helpers.query(q))
##################
## Vocabularies ##
##################
mu = Namespace('http://mu.semte.ch/vocabularies/')
mu_core = Namespace('http://mu.semte.ch/vocabularies/core/')
mu_ext = Namespace('http://mu.semte.ch/vocabularies/ext/')
graph = os.environ.get('MU_APPLICATION_GRAPH')
SERVICE_RESOURCE_BASE = 'http://mu.semte.ch/services/'
#######################
## Start Application ##
#######################
if __name__ == '__main__':
__builtin__.app = app
__builtin__.helpers = helpers
__builtin__.sparql_escape = sparql_escape
app_file = os.environ.get('APP_ENTRYPOINT')
f = open('ext/app/__init__.py', 'w+')
f.close()
f = open('/app/__init__.py', 'w+')
f.close()
try:
exec "from ext.app.%s import *" % app_file
except Exception as e:
helpers.log(str(e))
debug = True if (os.environ.get('MODE') == "development") else False
app.run(debug=debug, host='0.0.0.0', port=80)