bbj/src/schema.py

85 lines
2.3 KiB
Python
Raw Normal View History

2017-03-01 21:54:56 +00:00
from src import formatting
2017-03-01 16:59:33 +00:00
from time import time
2017-03-03 06:08:32 +00:00
2017-03-01 16:59:33 +00:00
def base():
return {
"error": False
}
def response(dictionary, usermap=None):
result = base()
result.update(dictionary)
if usermap:
result["usermap"] = usermap
return result
def error(code, description):
result = base()
result.update({
"error": {
2017-03-03 06:08:32 +00:00
"description": description, # string
"code": code # integer
2017-03-01 16:59:33 +00:00
}
})
return result
2017-03-01 17:01:07 +00:00
def user_internal(ID, auth_hash, name, quip, bio, admin):
2017-03-03 06:08:32 +00:00
if not quip: quip = ""
if not bio: bio = ""
2017-03-01 16:59:33 +00:00
return {
2017-03-03 06:08:32 +00:00
"user_id": ID, # string
"quip": quip, # (possibly empty) string
"bio": bio, # (possibly empty) string
"name": name, # string
"admin": admin, # boolean
"auth_hash": auth_hash # SHA256 string
2017-03-01 16:59:33 +00:00
}
2017-03-01 17:01:07 +00:00
def user_external(ID, name, quip, bio, admin):
2017-03-03 06:08:32 +00:00
if not quip: quip = ""
if not bio: bio = ""
2017-03-01 16:59:33 +00:00
return {
2017-03-03 06:08:32 +00:00
"user_id": ID, # string
"quip": quip, # (possibly empty) string
"name": name, # string
"bio": bio, # string
"admin": admin # boolean
2017-03-01 16:59:33 +00:00
}
def thread(ID, author, body, title, tags):
2017-03-03 06:08:32 +00:00
if not tags: tags = list()
2017-03-03 01:10:16 +00:00
body = formatting.parse(body, doquotes=False)
2017-03-01 16:59:33 +00:00
now = time()
return {
2017-03-03 06:08:32 +00:00
"thread_id": ID, # string
"post_id": 1, # integer
"author": author, # string
"body": body, # string
"title": title, # string
"tags": tags, # (possibly empty) list of strings
"replies": list(), # (possibly empty) list of reply objects
"reply_count": 0, # integer
"edited": False, # boolean
"lastmod": now, # floating point unix timestamp
"created": now # floating point unix timestamp
2017-03-01 16:59:33 +00:00
}
def reply(ID, author, body):
2017-03-03 01:10:16 +00:00
body = formatting.parse(body)
2017-03-01 16:59:33 +00:00
now = time()
return {
2017-03-03 06:08:32 +00:00
"post_id": ID, # integer
"author": author, # string
"body": body, # string
"edited": False, # boolean
"lastmod": now, # floating point unix timestamp
"created": now # floating point unix timestamp
2017-03-01 16:59:33 +00:00
}