Skip to content

Commit

Permalink
v2.3.1 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
c3kay authored Jul 2, 2024
2 parents 7229796 + eba00b6 commit 0816aa9
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 52 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/*
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/*
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}
7 changes: 4 additions & 3 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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",
Expand All @@ -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"'
]
Expand All @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions src/hoyolabrssfeeds/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions src/hoyolabrssfeeds/hoyolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = (
'<video src="{src}" poster="{poster}" controls playsinline>Watch the video here: {src}</video><p>'
"{desc}</p>".format(
src=post["video"]["url"],
poster=post["video"]["cover"],
desc=post["post"]["desc"],
)
)

# remove empty leading paragraphs
if post["post"]["content"].startswith(
("<p></p>", "<p>&nbsp;</p>", "<p><br></p>")
Expand Down
6 changes: 3 additions & 3 deletions src/hoyolabrssfeeds/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 5 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/test_hoyolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
'<video src="https://example.com/video.mp4" poster="https://example.com/cover.jpg" controls playsinline>Watch '
"the video here: https://example.com/video.mp4</video><p>Hello world!</p>"
)

assert transformed_post["post"]["content"] == expected


# ---- HELPER FUNCTIONS ----


Expand Down
20 changes: 10 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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}

Expand All @@ -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}


Expand Down

0 comments on commit 0816aa9

Please sign in to comment.