Add docstrings
This commit is contained in:
parent
958cda62b7
commit
e7f978fb43
1 changed files with 16 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Handle API requests to the database
|
||||
something
|
||||
"""
|
||||
Handle API requests to the database
|
||||
"""
|
||||
import json
|
||||
import sqlite3
|
||||
|
@ -10,6 +10,10 @@ DATABASE = '/usr/local/www/mocha-server/mocha.db'
|
|||
|
||||
|
||||
def fetch(user_id):
|
||||
"""
|
||||
Returns a JSON object containing the requested user
|
||||
Also can return a list of all users if user_id == "*"
|
||||
"""
|
||||
conn = sqlite3.connect(DATABASE)
|
||||
conn.row_factory = sqlite3.Row
|
||||
cursor = conn.cursor()
|
||||
|
@ -29,6 +33,12 @@ def fetch(user_id):
|
|||
|
||||
|
||||
def process_request(uri):
|
||||
"""
|
||||
Handles the API endpoint.
|
||||
Currently supports:
|
||||
- /mocha/users/"user_id" Returns JSON of the specified user
|
||||
- /mocha/users/* Returns JSON list of all users
|
||||
"""
|
||||
parts = uri.split('/')[1:]
|
||||
assert parts[0] == 'mocha'
|
||||
|
||||
|
@ -38,10 +48,13 @@ def process_request(uri):
|
|||
output = fetch(parts[2])
|
||||
return output
|
||||
|
||||
print(parts)
|
||||
return None
|
||||
|
||||
|
||||
def application(environ, start_response):
|
||||
"""
|
||||
mod_wsgi entry point
|
||||
"""
|
||||
status = '200 OK'
|
||||
output = process_request(environ['REQUEST_URI']).encode('UTF-8')
|
||||
|
||||
|
|
Reference in a new issue