diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index eff36a2..62702aa 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -10,14 +10,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: # full history needed to determine correct version fetch-depth: 0 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' - name: Install build tools run: | python -m pip install --upgrade pip @@ -28,7 +28,7 @@ jobs: - name: Build distribution run: python -m build - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: dist-files path: dist/* @@ -45,7 +45,7 @@ jobs: id-token: write steps: - name: Download artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: dist-files path: dist diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a5ccce2..e0d7ad2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,13 +10,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' - name: Install build tools run: | python -m pip install --upgrade pip @@ -27,7 +27,7 @@ jobs: - name: Build Distribution run: python -m build - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: dist-files path: dist/* @@ -43,7 +43,7 @@ jobs: id-token: write steps: - name: Download artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: dist-files path: dist @@ -55,9 +55,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: dist-files path: dist diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9413718..54d6a9c 100755 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,11 +10,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' - name: Install tox run: | python -m pip install --upgrade pip @@ -30,13 +30,13 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - py: ['3.8', '3.9', '3.10', '3.11'] + py: ['3.9', '3.10', '3.11', '3.12'] os: ['ubuntu-latest', 'windows-latest'] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Python ${{ matrix.py }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.py }} - name: Install tox @@ -46,5 +46,7 @@ jobs: python -m pip install "tox >= 3.26.0" - name: Run tests via tox run: python -m tox - - name: Upload code coverage - uses: codecov/codecov-action@v3 + - name: Upload to CodeCov + uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/RELEASENOTES.md b/RELEASENOTES.md index bda4c7f..003e1a3 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,7 +1,8 @@ -## New Features +## Changes -- Added simple logging (for level `INFO`) +- Added support for python 3.12 + - Support for python 3.8 will be dropped in the next version ## Fixes -- Added a Hoyolab structured content parser to fix #10 +- Added fix for native hoyolab video posts (#13) diff --git a/pyproject.toml b/pyproject.toml index e3f5d20..df75bc5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools == 69.0.2", "setuptools_scm[toml] == 8.0.4"] +requires = ["setuptools == 70.2.0", "setuptools_scm[toml] == 8.1.0"] build-backend = "setuptools.build_meta" [project] @@ -22,10 +22,10 @@ keywords = [ ] classifiers = [ "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Development Status :: 5 - Production/Stable", @@ -34,8 +34,8 @@ classifiers = [ "Topic :: Internet :: WWW/HTTP :: Dynamic Content :: News/Diary" ] dependencies = [ - "aiohttp == 3.9.2", - "aiofiles == 23.2.1", + "aiohttp == 3.9.5", + "aiofiles == 24.1.0", "pydantic == 1.10.13, < 2", 'tomli == 2.0.1 ; python_version < "3.11"' ] @@ -44,17 +44,17 @@ dynamic = ["version"] [project.optional-dependencies] dev = [ "tox == 4.11.4", - "pytest == 7.4.4", - "pytest-asyncio == 0.23.3", - "pytest-cov == 4.1.0", - "pytest-mock == 3.12.0", + "pytest == 8.2.2", + "pytest-asyncio == 0.23.7", + "pytest-cov == 5.0.0", + "pytest-mock == 3.14.0", "atoma == 0.0.17", "langdetect == 1.0.9" ] [project.urls] -"Homepage" = "https://github.com/c3kay/hoyolab-rss-feeds" -"Tracker" = "https://github.com/c3kay/hoyolab-rss-feeds/issues" +"Repository" = "https://github.com/c3kay/hoyolab-rss-feeds" +"Homepage" = "https://c3kay.de/hoyolab-rss-feeds" [project.scripts] hoyolab-rss-feeds = "hoyolabrssfeeds.__main__:cli" diff --git a/src/hoyolabrssfeeds/feeds.py b/src/hoyolabrssfeeds/feeds.py index 7b3597c..8c25a80 100644 --- a/src/hoyolabrssfeeds/feeds.py +++ b/src/hoyolabrssfeeds/feeds.py @@ -142,9 +142,11 @@ async def _update_category_feed( """Create or update a specific category feed.""" known_ids = { - item.id: item.published - if item.updated is None - else max(item.published, item.updated) + item.id: ( + item.published + if item.updated is None + else max(item.published, item.updated) + ) for item in category_items if item.category == category } diff --git a/src/hoyolabrssfeeds/hoyolab.py b/src/hoyolabrssfeeds/hoyolab.py index ba436a5..f2025e0 100644 --- a/src/hoyolabrssfeeds/hoyolab.py +++ b/src/hoyolabrssfeeds/hoyolab.py @@ -64,6 +64,21 @@ def _transform_post(self, post: Dict[str, Any]) -> Dict[str, Any]: post["post"]["structured_content"] ) + # native/local video post + if ( + "view_type" in post["post"] + and post["post"]["view_type"] == 5 + and post["video"] is not None + ): + post["post"]["content"] = ( + '

' + "{desc}

".format( + src=post["video"]["url"], + poster=post["video"]["cover"], + desc=post["post"]["desc"], + ) + ) + # remove empty leading paragraphs if post["post"]["content"].startswith( ("

", "

 

", "


") diff --git a/src/hoyolabrssfeeds/writers.py b/src/hoyolabrssfeeds/writers.py index f98d91c..4c36690 100644 --- a/src/hoyolabrssfeeds/writers.py +++ b/src/hoyolabrssfeeds/writers.py @@ -207,9 +207,9 @@ def create_atom_feed_entries( author = ElementTree.SubElement(entry, "author") ElementTree.SubElement(author, "name").text = item.author - ElementTree.SubElement( - entry, "content", {"type": "html"} - ).text = item.content + ElementTree.SubElement(entry, "content", {"type": "html"}).text = ( + item.content + ) entries.append(entry) diff --git a/tests/conftest.py b/tests/conftest.py index 326d3c7..872f551 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -191,9 +191,11 @@ def json_feed_items(feed_item_list: List[models.FeedItem]) -> Dict[str, Any]: "tags": [feed_item.category.name.title()], "content_html": feed_item.content, "date_published": feed_item.published.astimezone().isoformat(), - "date_modified": feed_item.updated.astimezone().isoformat() - if feed_item.updated - else "", + "date_modified": ( + feed_item.updated.astimezone().isoformat() + if feed_item.updated + else "" + ), "image": feed_item.image, } for feed_item in feed_item_list diff --git a/tests/test_hoyolab.py b/tests/test_hoyolab.py index d1b03bf..7a00499 100644 --- a/tests/test_hoyolab.py +++ b/tests/test_hoyolab.py @@ -236,6 +236,29 @@ def test_structured_content_parser() -> None: hoyolab.HoyolabNews._parse_structured_content("###") +def test_video_post() -> None: + post = { + "post": { + "content": '{"video": "https://example.com/video.mp4"}', + "view_type": 5, + "desc": "Hello world!", + }, + "video": { + "url": "https://example.com/video.mp4", + "cover": "https://example.com/cover.jpg", + }, + } + + api = hoyolab.HoyolabNews(models.Game.GENSHIN) + transformed_post = api._transform_post(post) + expected = ( + '

Hello world!

" + ) + + assert transformed_post["post"]["content"] == expected + + # ---- HELPER FUNCTIONS ---- diff --git a/tox.ini b/tox.ini index 957d749..ddfb494 100644 --- a/tox.ini +++ b/tox.ini @@ -1,29 +1,29 @@ [tox] isolated_build = True skip_missing_interpreters = True -envlist = clean, black, flake, type, py38, py39, py310, py311 +envlist = clean, black, flake, type, py39, py310, py311, py312 [gh-actions] python = - 3.8: py38 3.9: py39 3.10: py310 3.11: py311 + 3.12: py312 [testenv] deps = - pytest == 7.4.4 - pytest-asyncio == 0.23.3 - pytest-cov == 4.1.0 - pytest-mock == 3.12.0 - coverage[toml] == 7.4.0 + pytest == 8.2.2 + pytest-asyncio == 0.23.7 + pytest-cov == 5.0.0 + pytest-mock == 3.14.0 + coverage[toml] == 7.5.4 atoma == 0.0.17 langdetect == 1.0.9 commands = pytest {posargs} [testenv:type] deps = - mypy == 1.8.0 + mypy == 1.10.1 {[testenv]deps} commands = mypy --install-types --non-interactive {posargs} @@ -34,12 +34,12 @@ commands = coverage erase [testenv:black] skip_install = true -deps = black == 23.12.1 +deps = black == 24.4.2 commands = black src tests {posargs} [testenv:flake] skip_install = true -deps = flake8 == 7.0.0 +deps = flake8 == 7.1.0 commands = flake8 {posargs}