Adder json API by going to /json/nameofsoftware
This commit is contained in:
parent
8402645a14
commit
55f375a49f
1 changed files with 19 additions and 2 deletions
21
server.py
21
server.py
|
@ -35,7 +35,10 @@ class handler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
def start_page(self):
|
def start_page(self):
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header('Content-type', 'text/html')
|
if "/json/" not in self.path:
|
||||||
|
self.send_header('Content-type', 'text/html')
|
||||||
|
else:
|
||||||
|
self.send_header('Content-type', 'application/json')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
||||||
def send(self, text):
|
def send(self, text):
|
||||||
|
@ -50,8 +53,22 @@ class handler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
|
|
||||||
|
if self.path.startswith("/json/"):
|
||||||
|
|
||||||
if self.path == "/":
|
# API CALL
|
||||||
|
|
||||||
|
|
||||||
|
term = self.path[6:]
|
||||||
|
software_data, match = search.search_app(term)
|
||||||
|
data = {"found":{"data":software_data,"match":match}}
|
||||||
|
data["suggestions"] = search.suggest(software_data)
|
||||||
|
text = json.dumps(data, indent = 2)
|
||||||
|
|
||||||
|
self.start_page()
|
||||||
|
self.wfile.write(text.encode("utf-8"))
|
||||||
|
|
||||||
|
|
||||||
|
elif self.path == "/":
|
||||||
|
|
||||||
# If the user is at the front page, let him get only the search bar
|
# If the user is at the front page, let him get only the search bar
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue