bbj/src/schema.py

81 lines
1.7 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
def base():
return {
"usermap": {},
"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": {
"description": description,
"code": code
}
})
return result
2017-03-01 17:01:07 +00:00
def user_internal(ID, auth_hash, name, quip, bio, admin):
2017-03-01 16:59:33 +00:00
return {
"user_id": ID,
2017-03-01 17:02:04 +00:00
"quip": quip,
2017-03-01 16:59:33 +00:00
"name": name,
"bio": bio,
"admin": admin,
"auth_hash": auth_hash
}
2017-03-01 17:01:07 +00:00
def user_external(ID, name, quip, bio, admin):
2017-03-01 16:59:33 +00:00
return {
"user_id": ID,
2017-03-01 17:02:04 +00:00
"quip": quip,
2017-03-01 16:59:33 +00:00
"name": name,
"bio": bio,
"admin": admin
}
def thread(ID, author, body, title, tags):
2017-03-01 21:54:56 +00:00
text, entities = formatting.parse(body, doquotes=False)
2017-03-01 16:59:33 +00:00
now = time()
return {
"thread_id": ID,
"author": author,
2017-03-01 21:54:56 +00:00
"body": text,
"entities": entities, # of type list()
2017-03-01 16:59:33 +00:00
"title": title,
"tags": tags,
"replies": list(),
"reply_count": 0,
"lastmod": now,
"edited": False,
"created": now
}
def reply(ID, author, body):
2017-03-01 21:54:56 +00:00
text, entities = formatting.parse(body)
2017-03-01 16:59:33 +00:00
now = time()
return {
"post_id": ID,
"author": author,
2017-03-01 21:54:56 +00:00
"body": text,
"entities": entities, # of type list()
2017-03-01 16:59:33 +00:00
"lastmod": now,
"edited": False,
"created": now
}