From c6166a9212cd259323e2fe0e488287fbdcc1d521 Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Sat, 19 Feb 2022 17:09:11 +0000 Subject: [PATCH] update - add support for some scrobble types --- README.md | 17 ++++++++++++++++- src/microcosm/__init__.py | 26 +++++++++++++++++++------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c9542cd..02eb002 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ # pymicrocosm -A tiny python-based micropub endpoint that supports a Gitea + drone static website \ No newline at end of file +A tiny python-based micropub endpoint that supports a Gitea + drone static website + + +## Developing + +Using a recent version of python 3.7+ install [poetry](https://python-poetry.org/): + +```shell +pip install poetry +``` + +Then you can install microcosm and its required libraries with: + +```shell +poetry install +``` \ No newline at end of file diff --git a/src/microcosm/__init__.py b/src/microcosm/__init__.py index c92117b..aa06762 100644 --- a/src/microcosm/__init__.py +++ b/src/microcosm/__init__.py @@ -31,10 +31,8 @@ app.config['SECRET_KEY'] = 'my super secret key' ENTITY_TYPE_PLURAL_MAP = { - "post": "posts", - "note": "notes", "reply": "replies", - "bookmark": "bookmarks" + "watch":"watches" } @@ -296,6 +294,12 @@ def detect_entry_type(doc: dict) -> str: elif ('like-of' in doc) or ('u-like-of' in doc): entry_type = "like" + elif ('read-of' in doc): + entry_type = "read" + + elif ('watch-of' in doc): + entry_type = "watch" + elif ('name' in doc) or ('p-name' in doc): entry_type = "post" else: @@ -306,14 +310,23 @@ def detect_entry_type(doc: dict) -> str: def capture_frontmatter_props(doc: Dict[str, Union[str, List[str]]], frontmatter: Dict[str, Union[str,List[str]]]): - keys = ['bookmark-of', 'in-reply-to', 'repost-of', 'like-of'] + keys = ['summary', 'bookmark-of', 'in-reply-to', 'repost-of', 'like-of', 'read-of', 'watch-of', 'read-status', 'rating'] keys += [f'u-{key}' for key in keys] for key in keys: if key in doc: - if isinstance(doc[key], list) and (len(doc[key]) < 2): + + if isinstance(doc[key], dict) and ('type' in doc[key]): + + if doc[key]['type'][0] == 'h-cite': + + if 'citations' not in frontmatter: + frontmatter['citations'] = [] + frontmatter['citations'].append(doc[key]['properties']) + + elif isinstance(doc[key], list) and (len(doc[key]) < 2): frontmatter[key] = doc[key][0] else: frontmatter[key] = doc[key] @@ -415,7 +428,6 @@ def process_json_post(): if 'name' in props: frontmatter['title'] = props['name'][0] - docstr = "" if 'photo' in props: @@ -556,4 +568,4 @@ def index(): if __name__ == '__main__': - app.run(debug=True) + app.run(debug=False)