Skip to content

Commit 52dfc18

Browse files
committed
✨ feat(compiler/parse_tg.py): Fetch Bot API documentation directly from the web instead of a local file.
1 parent a832d23 commit 52dfc18

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

compiler/parse_tg.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
"""Parse types and methods from the Telegram Bot API HTML page (tg.html).
1+
"""Parse types and methods from the Telegram Bot API page.
22
3-
Outputs two JSON files under compiler/api/:
3+
Fetches https://core.telegram.org/bots/api and outputs two JSON files
4+
under compiler/api/:
45
- bot_api_types.json — all Bot API types
56
- bot_api_methods.json — all Bot API methods
67
"""
@@ -10,9 +11,10 @@
1011
from html import unescape
1112
from html.parser import HTMLParser
1213
from pathlib import Path
14+
from urllib.request import urlopen
1315

1416
BASE_DIR = Path(__file__).parent
15-
HTML_PATH = BASE_DIR / "tg.html"
17+
API_URL = "https://core.telegram.org/bots/api"
1618
API_DIR = BASE_DIR / "api"
1719

1820
# ---------- HTML table extractor ----------
@@ -309,7 +311,8 @@ def _get_section(heading_line: int) -> str:
309311

310312

311313
def main():
312-
html = HTML_PATH.read_text(encoding="utf-8")
314+
with urlopen(API_URL) as resp:
315+
html = resp.read().decode("utf-8")
313316
types, methods = parse(html)
314317

315318
API_DIR.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)