generated from Beesquit/telegram-bot-template
Implemented last article command
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import base64
|
||||
import json
|
||||
|
||||
import httpx
|
||||
|
||||
habrApiUrl="https://habr.frik.su/api/".removesuffix("/")
|
||||
|
||||
|
||||
async def getArticles(amount: int) -> list[tuple[str, str]]:
|
||||
result = []
|
||||
async with httpx.AsyncClient() as client:
|
||||
payload = {
|
||||
"amount": amount
|
||||
}
|
||||
response = await client.post(habrApiUrl + "/articles/get/md", json=payload)
|
||||
|
||||
responseJson = json.loads(response.content)
|
||||
|
||||
for key in responseJson:
|
||||
decoded = base64.b64decode(responseJson[key].encode('ascii')).decode('utf-8')
|
||||
result.append((key, decoded))
|
||||
return result
|
||||
Reference in New Issue
Block a user