-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapp.py
36 lines (30 loc) · 996 Bytes
/
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
"""
Top-level code for launching the CP Knowledge Graph server
"""
from local_database import populate_db, start_db
from flask import Flask, send_from_directory
from flask_graphql import GraphQLView
from schema import schema
from argparse import ArgumentParser
from scrape_data import scrape_data
app = Flask(__name__, static_url_path="")
app.debug = True
app.add_url_rule(
"/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True)
)
@app.route("/visualize")
def display_api():
"""
Displays the GraphQL Voyager page that allows users to visually explore the API
"""
return send_from_directory("pages", "voyager.html")
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("--prod", type=bool, default=False)
parser.add_argument("--scrapers", "-s", nargs="*", default=[])
args = parser.parse_args()
if not args.prod:
start_db()
populate_db()
scrape_data(args.scrapers)
app.run()