1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

get latest diario entries

This commit is contained in:
Steffo 2020-08-30 00:08:13 +02:00
parent 8d6c57ad30
commit aa84b3a077
3 changed files with 34 additions and 1 deletions

View file

@ -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 <ste.pigozzi@gmail.com>"]
license = "AGPL-3.0+"

View file

@ -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__

View file

@ -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))