From 7a0ecf31f0da99ffc3fb05bc3e1d18cb4377e71c Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Sun, 30 Oct 2022 15:01:54 +0000 Subject: [PATCH 1/6] rename now to created_at - more appropriate --- src/microcosm/__init__.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/microcosm/__init__.py b/src/microcosm/__init__.py index e710181..1ca83d9 100644 --- a/src/microcosm/__init__.py +++ b/src/microcosm/__init__.py @@ -81,10 +81,10 @@ _api_client = None -def process_photo_url(now: datetime, doc: Dict[str, List[str]], suffix: str = ""): +def process_photo_url(created_at: datetime, doc: Dict[str, List[str]], suffix: str = ""): """Process photo submitted via URL""" - now_ts = int(time.mktime(now.timetuple())) + now_ts = int(time.mktime(created_at.timetuple())) photo_urls = [] @@ -103,9 +103,9 @@ def process_photo_url(now: datetime, doc: Dict[str, List[str]], suffix: str = "" # generate local filename filename = os.path.join(os.environ.get( - 'MICROPUB_MEDIA_PATH'), now.strftime("%Y/%m/%d"), str(now_ts) + f"{now_ts}_{suffix}_{i}_{ext}") + 'MICROPUB_MEDIA_PATH'), created_at.strftime("%Y/%m/%d"), str(now_ts) + f"{now_ts}_{suffix}_{i}_{ext}") photo_url = os.path.join(os.environ.get( - 'MICROPUB_MEDIA_URL_PREFIX'), now.strftime("%Y/%m/%d"), str(now_ts) + f"{now_ts}_{suffix}_{i}_{ext}") + 'MICROPUB_MEDIA_URL_PREFIX'), created_at.strftime("%Y/%m/%d"), str(now_ts) + f"{now_ts}_{suffix}_{i}_{ext}") photo_urls.append(photo_url) @@ -123,10 +123,10 @@ def process_photo_url(now: datetime, doc: Dict[str, List[str]], suffix: str = "" return photo_urls -def process_photo_upload(now: datetime, file: FileStorage, suffix: str=""): +def process_photo_upload(created_at: datetime, file: FileStorage, suffix: str=""): """Process photo directly uploaded to micropub""" - now_ts = int(time.mktime(now.timetuple())) + now_ts = int(time.mktime(created_at.timetuple())) if os.environ.get('MICROPUB_IMAGE_STRATEGY') == 'copy': @@ -134,9 +134,9 @@ def process_photo_upload(now: datetime, file: FileStorage, suffix: str=""): # generate local filename filename = os.path.join(os.environ.get( - 'MICROPUB_MEDIA_PATH'), now.strftime("%Y/%m/%d"), f"{now_ts}_{suffix}{ext}") + 'MICROPUB_MEDIA_PATH'), created_at.strftime("%Y/%m/%d"), f"{now_ts}_{suffix}{ext}") photo_url = os.path.join(os.environ.get( - 'MICROPUB_MEDIA_URL_PREFIX'), now.strftime("%Y/%m/%d"), f"{now_ts}_{suffix}{ext}") + 'MICROPUB_MEDIA_URL_PREFIX'), created_at.strftime("%Y/%m/%d"), f"{now_ts}_{suffix}{ext}") # make directory if needed if not os.path.exists(os.path.dirname(filename)): @@ -150,9 +150,9 @@ def process_photo_upload(now: datetime, file: FileStorage, suffix: str=""): return None -def init_frontmatter(now: datetime, post_type: str, name: Optional[str]=None): +def init_frontmatter(created_at: datetime, post_type: str, name: Optional[str]=None): - now_ts = int(time.mktime(now.timetuple())) + now_ts = int(time.mktime(created_at.timetuple())) if name: if isinstance(name, list): @@ -164,18 +164,18 @@ def init_frontmatter(now: datetime, post_type: str, name: Optional[str]=None): url = os.path.join("/", ENTITY_TYPE_PLURAL_MAP.get(post_type, post_type + "s"), - now.strftime("%Y/%m/%d"), slug) + created_at.strftime("%Y/%m/%d"), slug) print(os.environ.get( 'CONTENT_PREFIX')) file_path = os.path.join(os.environ.get( - 'CONTENT_PREFIX'), ENTITY_TYPE_PLURAL_MAP.get(post_type, post_type + "s"), now.strftime("%Y/%m/%d"), slug + ".md") + 'CONTENT_PREFIX'), ENTITY_TYPE_PLURAL_MAP.get(post_type, post_type + "s"), created_at.strftime("%Y/%m/%d"), slug + ".md") frontmatter = { "url": url, "type": post_type, - "date": now.isoformat(sep='T'), + "date": created_at.isoformat(sep='T'), } return frontmatter, file_path -- 2.40.1 From dc40d4df692d81efa53699f0a99baf256a5c7242 Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Sun, 30 Oct 2022 15:40:03 +0000 Subject: [PATCH 2/6] implement posting in the past with published flag --- src/microcosm/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/microcosm/__init__.py b/src/microcosm/__init__.py index 1ca83d9..52a1a94 100644 --- a/src/microcosm/__init__.py +++ b/src/microcosm/__init__.py @@ -7,6 +7,8 @@ import giteapy import giteapy.rest import time import base64 + + from werkzeug.datastructures import FileStorage import yaml @@ -27,7 +29,7 @@ PERMITTED_DOMAIN = os.environ.get( ENTITY_TYPE_PLURAL_MAP = { "reply": "replies", - "watch":"watches" + "watch": "watches" } core_bp = Blueprint("core", __name__) @@ -321,7 +323,13 @@ def process_json_post(): props = body['properties'] entry_type = detect_entry_type(props) - now = datetime.now() + if 'published' in props: + + from dateutil import parser + + now = parser.parse(props['published'][0]) + else: + now = datetime.now() frontmatter, file_path = init_frontmatter(now, entry_type, props.get('name')) -- 2.40.1 From 9ba79091d743a2969d3e9e67bdf71c6cd98ebe38 Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Sun, 30 Oct 2022 15:40:17 +0000 Subject: [PATCH 3/6] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 13f802c..18d727f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pymicrocosm" -version = "0.1.0" +version = "0.2.0" description = "A tiny python-based micropub endpoint that supports a Gitea + drone static website" authors = ["James Ravenscroft "] license = "AGPL-3.0" -- 2.40.1 From c7a31ce559ceed08671371804f09c2104a49244f Mon Sep 17 00:00:00 2001 From: ravenscroftj Date: Sun, 30 Oct 2022 15:55:07 +0000 Subject: [PATCH 4/6] Update '.drone.yml' --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index b776aef..7c090b3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -28,7 +28,7 @@ steps: commands: - pip install poetry twine - poetry build - - echo "[distutils]\nindex-servers = gitea\n\n[gitea]\nrepository = ${GITEA_PACKAGE_REPO}\nusername = ${GITEA_OWNER}\npassword = ${GITEA_TOKEN}" > ~/.pypirc + - echo "[distutils]\nindex-servers = gitea\n\n[gitea]\nrepository = $${GITEA_PACKAGE_REPO}\nusername = $${GITEA_OWNER}\npassword = $${GITEA_TOKEN}" > ~/.pypirc - twine upload -r gitea ./dist/*.whl -- 2.40.1 From 1c7d5d570afb55f20167063b0d6ab5100f1b0693 Mon Sep 17 00:00:00 2001 From: ravenscroftj Date: Sun, 30 Oct 2022 15:55:43 +0000 Subject: [PATCH 5/6] Update '.drone.yml' --- .drone.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.drone.yml b/.drone.yml index 7c090b3..98fc1c5 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,12 +3,12 @@ type: docker name: test and build steps: - - name: test - image: python:3.7 - commands: - - pip install poetry - - poetry install - - poetry run pytest + # - name: test + # image: python:3.7 + # commands: + # - pip install poetry + # - poetry install + # - poetry run pytest - name: publish when: -- 2.40.1 From 639fb7e979cf053b67d10c8bb5a584a3b3ca9e70 Mon Sep 17 00:00:00 2001 From: ravenscroftj Date: Sun, 30 Oct 2022 15:56:41 +0000 Subject: [PATCH 6/6] Update '.drone.yml' --- .drone.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.drone.yml b/.drone.yml index 98fc1c5..7c090b3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,12 +3,12 @@ type: docker name: test and build steps: - # - name: test - # image: python:3.7 - # commands: - # - pip install poetry - # - poetry install - # - poetry run pytest + - name: test + image: python:3.7 + commands: + - pip install poetry + - poetry install + - poetry run pytest - name: publish when: -- 2.40.1