generated from Beesquit/telegram-bot-template
23 lines
603 B
Python
23 lines
603 B
Python
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
|