Merge branch 'develop' of ssh://git.jamesravey.me:222/ravenscroftj/pymicrocosm into develop
This commit is contained in:
commit
f583942894
|
@ -34,6 +34,9 @@ ENTITY_TYPE_PLURAL_MAP = {
|
||||||
|
|
||||||
core_bp = Blueprint("core", __name__)
|
core_bp = Blueprint("core", __name__)
|
||||||
|
|
||||||
|
class InvalidRequestException(Exception):
|
||||||
|
"""Class of exception raised when the server receives an invalid request"""
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
@ -53,6 +56,7 @@ def create_app():
|
||||||
app.register_blueprint(core_bp)
|
app.register_blueprint(core_bp)
|
||||||
app.register_blueprint(webhook_bp)
|
app.register_blueprint(webhook_bp)
|
||||||
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +85,8 @@ def authed_endpoint(f):
|
||||||
|
|
||||||
_api_client = None
|
_api_client = None
|
||||||
|
|
||||||
|
class InvalidRequestException(Exception):
|
||||||
|
"""Invalid Request"""
|
||||||
|
|
||||||
|
|
||||||
def process_photo_url(created_at: datetime, doc: Dict[str, List[str]], suffix: str = ""):
|
def process_photo_url(created_at: datetime, doc: Dict[str, List[str]], suffix: str = ""):
|
||||||
|
@ -194,7 +199,10 @@ def detect_entry_type(doc: dict) -> str:
|
||||||
"""Given a dictionary object from either form or json, detect type of post"""
|
"""Given a dictionary object from either form or json, detect type of post"""
|
||||||
|
|
||||||
|
|
||||||
if ('in-reply-to' in doc) or ('u-in-reply-to' in doc):
|
if 'hypothesis-link' in doc:
|
||||||
|
entry_type = "annotation"
|
||||||
|
|
||||||
|
elif ('in-reply-to' in doc) or ('u-in-reply-to' in doc):
|
||||||
entry_type = "reply"
|
entry_type = "reply"
|
||||||
|
|
||||||
elif ('bookmark-of' in doc) or ('u-bookmark-of' in doc):
|
elif ('bookmark-of' in doc) or ('u-bookmark-of' in doc):
|
||||||
|
@ -215,6 +223,7 @@ def detect_entry_type(doc: dict) -> str:
|
||||||
else:
|
else:
|
||||||
entry_type = "note"
|
entry_type = "note"
|
||||||
|
|
||||||
|
|
||||||
return entry_type
|
return entry_type
|
||||||
|
|
||||||
def capture_frontmatter_props(doc: Dict[str, Union[str, List[str]]], frontmatter: Dict[str, Union[str,List[str]]]):
|
def capture_frontmatter_props(doc: Dict[str, Union[str, List[str]]], frontmatter: Dict[str, Union[str,List[str]]]):
|
||||||
|
@ -241,6 +250,12 @@ def capture_frontmatter_props(doc: Dict[str, Union[str, List[str]]], frontmatter
|
||||||
else:
|
else:
|
||||||
frontmatter[key] = doc[key]
|
frontmatter[key] = doc[key]
|
||||||
|
|
||||||
|
if 'hypothesis-link' in doc:
|
||||||
|
# get the hypothesis data and store it
|
||||||
|
r = requests.get(doc['hypothesis-link'][0])
|
||||||
|
|
||||||
|
frontmatter['hypothesis-meta'] = r.json()
|
||||||
|
|
||||||
if 'category' in doc:
|
if 'category' in doc:
|
||||||
if isinstance(doc['category'], list):
|
if isinstance(doc['category'], list):
|
||||||
categories = doc['category']
|
categories = doc['category']
|
||||||
|
@ -317,6 +332,25 @@ def process_multipart_post():
|
||||||
return docstr, frontmatter, file_path
|
return docstr, frontmatter, file_path
|
||||||
|
|
||||||
|
|
||||||
|
def process_image_alt_texts(doc):
|
||||||
|
|
||||||
|
alts = []
|
||||||
|
|
||||||
|
if isinstance(doc['photo'], str):
|
||||||
|
doc['photo'] = [doc['photo']]
|
||||||
|
|
||||||
|
|
||||||
|
for i, photo in enumerate(doc['photo']):
|
||||||
|
|
||||||
|
if isinstance(photo, dict):
|
||||||
|
alts.append(doc['alt'])
|
||||||
|
else:
|
||||||
|
alts.append("")
|
||||||
|
|
||||||
|
return alts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def process_json_post():
|
def process_json_post():
|
||||||
"""Process JSON POST submission"""
|
"""Process JSON POST submission"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue