From aa84b3a0775cf1224641dd1f5cac8db373e84090 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 30 Aug 2020 00:08:13 +0200 Subject: [PATCH] get latest diario entries --- pyproject.toml | 2 +- royalpack/stars/__init__.py | 2 ++ royalpack/stars/api_diario_latest.py | 31 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 royalpack/stars/api_diario_latest.py diff --git a/pyproject.toml b/pyproject.toml index 4372e9e1..8d67c8cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "royalpack" - version = "5.14.5" + version = "5.14.6" description = "A Royalnet command pack for the Royal Games community" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" diff --git a/royalpack/stars/__init__.py b/royalpack/stars/__init__.py index db031fd5..e87eb26b 100644 --- a/royalpack/stars/__init__.py +++ b/royalpack/stars/__init__.py @@ -14,6 +14,7 @@ from .api_user_ryg_list import ApiUserRygListStar from .api_user_avatar import ApiUserAvatarStar from .api_auth_login_osu import ApiAuthLoginOsuStar from .api_diario_range import ApiDiarioRangeStar +from .api_diario_latest import ApiDiarioLatestStar # Enter the PageStars of your Pack here! available_page_stars = [ @@ -32,6 +33,7 @@ available_page_stars = [ ApiUserAvatarStar, ApiAuthLoginOsuStar, ApiDiarioRangeStar, + ApiDiarioLatestStar, ] # Don't change this, it should automatically generate __all__ diff --git a/royalpack/stars/api_diario_latest.py b/royalpack/stars/api_diario_latest.py new file mode 100644 index 00000000..00bd9b3d --- /dev/null +++ b/royalpack/stars/api_diario_latest.py @@ -0,0 +1,31 @@ +from typing import * +import royalnet.constellation.api as rca +import royalnet.utils as ru +from ..tables import * +from sqlalchemy import func + + +class ApiDiarioLatestStar(rca.ApiStar): + path = "/api/diario/latest/v3" + + parameters = { + "get": { + "amount": "The number of diario entries to get." + } + } + + tags = ["diario"] + + @rca.magic + async def get(self, data: rca.ApiData) -> ru.JSON: + """Get the latest diario entries.""" + DiarioT = self.alchemy.get(Diario) + + entries: List[Diario] = await ru.asyncify( + data.session + .query(DiarioT) + .order_by(func.random()) + .limit(data.int("amount", optional=False)) + .all + ) + return list(map(lambda e: e.json(), entries))