altrepo.parser.news: add date check for p11 and add p10

parent 8adda819
......@@ -45,6 +45,13 @@ class NewsInfo:
return None
html = await self.client.get(url, "koi8-r")
return await packages_parser(html, url)
async def p10(self) -> models.PackagesModel | None:
url = (await self.news_urls()).p10
if not url:
return None
html = await self.client.get(url, "koi8-r")
return await packages_parser(html, url)
class PackagesInfo:
......
......@@ -5,6 +5,7 @@ from typing import List
class NewsURL(BaseModel):
sisyphus: str | None = None
p11: str | None = None
p10: str | None = None
bugs: str | None = None
......
from bs4 import BeautifulSoup
from datetime import datetime
import re
from .. import models
......@@ -17,7 +16,6 @@ async def urls_parser(client):
html = await client.get(f"{base_url}date.html", "koi8-r")
soup = BeautifulSoup(html, "html.parser")
sisyphus_id = 0
result = {"sisyphus": None, "bugs": None, "p11": None}
for li in soup.find_all("li"):
......@@ -28,22 +26,32 @@ async def urls_parser(client):
href = a["href"]
text = a.get_text(strip=True)
match = re.search(r"(\d+)\.html", href)
if not match:
continue
msg_id = int(match.group(1))
url = base_url + href
if f"Sisyphus-{today} packages" in text:
result["sisyphus"] = url
sisyphus_id = msg_id
elif f"Sisyphus-{today} bugs" in text:
result["bugs"] = url
elif "p11/branch packages" in text and sisyphus_id:
if msg_id > sisyphus_id:
elif "p11/branch packages" in text and await _check_date(url, client):
result["p11"] = url
if result["sisyphus"] is None:
result["p11"] = None
elif "p10/branch packages" in text and await _check_date(url, client):
result["p10"] = url
return models.NewsURL(**result)
async def _check_date(url, client):
html = await client.get(url, "koi8-r")
soup = BeautifulSoup(html, "html.parser")
tag = soup.find("i")
if not tag:
return False
parts = tag.text.strip().split()
if len(parts) < 3:
return False
try:
return int(parts[2]) == datetime.now().day
except ValueError:
return False
......@@ -8,6 +8,9 @@ news_type_kb = (
.add(InlineButton("p11", callback_data="news/p11/0"))
.add(InlineButton("p11 (ru)", callback_data="news/p11/1"))
.row()
.add(InlineButton("p10", callback_data="news/p10/0"))
.add(InlineButton("p10 (ru)", callback_data="news/p10/1"))
.row()
.add(InlineButton("Bugs", callback_data="news/bugs/0"))
.add(InlineButton("FTBFS", callback_data="news/ftbfs/0"))
.row()
......
......@@ -28,7 +28,7 @@ async def news_handler(
text = (
"Выберите тип новостей.\n\n"
"Внимание: Sisyphus (ru) и p11 (ru) могут работать нестабильно."
"Внимание: Sisyphus (ru), p11 (ru) и p10 (ru) могут работать нестабильно."
)
await m.ctx_api.send_message(
chat_id=m.from_user.id, text=text, reply_markup=news_keyboards.news_type_kb
......@@ -60,6 +60,8 @@ async def news_handler(
packages_data = await altrepo.parser.news.sisyphus()
elif news_type == "p11":
packages_data = await altrepo.parser.news.p11()
elif news_type == "p10":
packages_data = await altrepo.parser.news.p10()
else:
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment