From 592de1b22d8d920f28b6d15b706f3156b2c0fd71 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Fri, 8 Jul 2022 12:10:20 +0200 Subject: [PATCH] Tweak/fix webfinger and signed GET --- app/activitypub.py | 1 + app/templates.py | 4 ++-- app/webfinger.py | 2 ++ poetry.lock | 13 +------------ pyproject.toml | 1 - tasks.py | 8 +++++++- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/activitypub.py b/app/activitypub.py index e9822a2..ff1b14e 100644 --- a/app/activitypub.py +++ b/app/activitypub.py @@ -113,6 +113,7 @@ async def fetch(url: str, params: dict[str, Any] | None = None) -> RawObject: }, params=params, follow_redirects=True, + auth=auth, ) # Special handling for deleted object diff --git a/app/templates.py b/app/templates.py index 174fb42..b799519 100644 --- a/app/templates.py +++ b/app/templates.py @@ -9,7 +9,7 @@ from urllib.parse import urlparse import bleach import emoji import html2text -import timeago # type: ignore +import humanize from bs4 import BeautifulSoup # type: ignore from fastapi import Request from fastapi.templating import Jinja2Templates @@ -293,7 +293,7 @@ def _timeago(original_dt: datetime) -> str: dt = original_dt if dt.tzinfo: dt = dt.astimezone(timezone.utc).replace(tzinfo=None) - return timeago.format(dt, now().replace(tzinfo=None)) + return humanize.naturaltime(dt, when=now().replace(tzinfo=None)) def _has_media_type(attachment: Attachment, media_type_prefix: str) -> bool: diff --git a/app/webfinger.py b/app/webfinger.py index addc122..e6bb213 100644 --- a/app/webfinger.py +++ b/app/webfinger.py @@ -38,7 +38,9 @@ async def webfinger( headers={ "User-Agent": config.USER_AGENT, }, + follow_redirects=True, ) + resp.raise_for_status() break except httpx.HTTPStatusError as http_error: logger.exception("HTTP error") diff --git a/poetry.lock b/poetry.lock index 8b38cdc..04d7cde 100644 --- a/poetry.lock +++ b/poetry.lock @@ -993,14 +993,6 @@ anyio = ">=3.4.0,<5" [package.extras] full = ["itsdangerous", "jinja2", "python-multipart", "pyyaml", "requests"] -[[package]] -name = "timeago" -version = "1.0.15" -description = "A very simple python library, used to format datetime with `*** time ago` statement. eg: \"3 hours ago\"." -category = "main" -optional = false -python-versions = "*" - [[package]] name = "tomli" version = "2.0.1" @@ -1162,7 +1154,7 @@ dev = ["pytest (>=4.6.2)", "black (>=19.3b0)"] [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "1192c7c9d7ce2b93f928406f66c6a6797581bdb4928974679f7b8a0a08a1cf9f" +content-hash = "ae7b5b5dfd9a30bc585c27be3d79e48c13b5cbb60b917034bc93e8038c4d3d8f" [metadata.files] aiosqlite = [ @@ -1968,9 +1960,6 @@ starlette = [ {file = "starlette-0.19.1-py3-none-any.whl", hash = "sha256:5a60c5c2d051f3a8eb546136aa0c9399773a689595e099e0877704d5888279bf"}, {file = "starlette-0.19.1.tar.gz", hash = "sha256:c6d21096774ecb9639acad41b86b7706e52ba3bf1dc13ea4ed9ad593d47e24c7"}, ] -timeago = [ - {file = "timeago-1.0.15.tar.gz", hash = "sha256:cfce420d82892af6b2439d0f69eeb3e876bbeddab6670c3c88ebf7676407bf4c"}, -] tomli = [ {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, diff --git a/pyproject.toml b/pyproject.toml index 4a6d373..2379695 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,6 @@ itsdangerous = "^2.1.2" python-multipart = "^0.0.5" tomli = "^2.0.1" httpx = "^0.23.0" -timeago = "^1.0.15" SQLAlchemy = {extras = ["asyncio"], version = "^1.4.39"} alembic = "^1.8.0" bleach = "^5.0.0" diff --git a/tasks.py b/tasks.py index 452658f..9955183 100644 --- a/tasks.py +++ b/tasks.py @@ -125,7 +125,13 @@ def configuration_wizard(ctx): run("PYTHONPATH=. poetry run python scripts/config_wizard.py", pty=True, echo=True) -@task(compile_scss, migrate_db) +@task +def install_deps(ctx): + # type: (Context) -> None + run("poetry install", pty=True, echo=True) + + +@task(install_deps, compile_scss, migrate_db) def update(ctx): # type: (Context) -> None print("Done")