implemented hypothesis metadata storage #10

Merged
ravenscroftj merged 2 commits from james/feature/hypothesis into develop 2022-11-20 09:52:57 +00:00
2 changed files with 38 additions and 1 deletions
Showing only changes of commit cab7a15728 - Show all commits

View File

@ -34,6 +34,9 @@ ENTITY_TYPE_PLURAL_MAP = {
core_bp = Blueprint("core", __name__)
class InvalidRequestException(Exception):
"""Class of exception raised when the server receives an invalid request"""
def create_app():
app = Flask(__name__)
@ -52,6 +55,7 @@ def create_app():
app.register_blueprint(core_bp)
app.register_blueprint(webhook_bp)
return app
@ -80,7 +84,8 @@ def authed_endpoint(f):
_api_client = None
class InvalidRequestException(Exception):
"""Invalid Request"""
def process_photo_url(created_at: datetime, doc: Dict[str, List[str]], suffix: str = ""):
@ -96,6 +101,13 @@ def process_photo_url(created_at: datetime, doc: Dict[str, List[str]], suffix: s
for i, photo in enumerate(doc['photo']):
if isinstance(photo, dict):
photo_url = photo['value']
elif isinstance(photo, str):
photo_url = photo
else:
raise InvalidRequestException()
if os.environ.get('MICROPUB_IMAGE_STRATEGY') == 'copy':
# download the photo
@ -235,6 +247,12 @@ def capture_frontmatter_props(doc: Dict[str, Union[str, List[str]]], frontmatter
else:
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 isinstance(doc['category'], list):
categories = doc['category']
@ -311,6 +329,25 @@ def process_multipart_post():
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():
"""Process JSON POST submission"""

0
src/microcosm/photo.py Normal file
View File