Skip to content

Commit d84bd86

Browse files
SpEcHiDenull-nick
authored andcommitted
Automate error scrapping
Credits: https://t.me/c/1999755950/19474 thanks to TelegramPlayground/pyrogram@c67504c
1 parent 0340cc7 commit d84bd86

6 files changed

Lines changed: 2107 additions & 499 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Scrape Errors
2+
on:
3+
workflow_dispatch: {} # Allow manually kicking off builds
4+
schedule:
5+
- cron: '0 12 * * *' # Every day at 12:00 (noon). Ref https://crontab.guru/examples.html
6+
jobs:
7+
build:
8+
name: scrape-errors
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 1
14+
- name: Set up Python
15+
uses: actions/setup-python@v3
16+
with:
17+
python-version: '3.9'
18+
19+
- name: scrape
20+
run: |
21+
cd compiler/errors/
22+
pip install --upgrade pip setuptools wheel
23+
pip install requests==2.28.1
24+
python sort.py scrape
25+
python sort.py sort
26+
27+
- name: Open Pull Request
28+
uses: peter-evans/create-pull-request@v4
29+
with:
30+
commit-message: >
31+
Update unknown_errors
32+
title: >
33+
Update Telegram API errors
34+
body: >
35+
This is an automated PR. Please check the diff, and the action logs, to check for any funky behaviour.
36+
branch: automated/api-error-scrape
37+
labels: automated
38+
delete-branch: true

compiler/errors/sort.py

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,54 @@
1818

1919
import csv
2020
from pathlib import Path
21+
import re
22+
import requests # requests==2.28.1
23+
import sys
2124

22-
for p in Path("source").glob("*.tsv"):
23-
with open(p) as f:
24-
reader = csv.reader(f, delimiter="\t")
25-
dct = {k: v for k, v in reader if k != "id"}
26-
keys = sorted(dct)
25+
if len(sys.argv) != 1:
26+
sys.exit(1)
2727

28-
with open(p, "w") as f:
29-
f.write("id\tmessage\n")
28+
if sys.argv[1] == "sort":
29+
for p in Path("source").glob("*.tsv"):
30+
with open(p) as f:
31+
reader = csv.reader(f, delimiter="\t")
32+
dct = {k: v for k, v in reader if k != "id"}
33+
keys = sorted(dct)
3034

31-
for i, item in enumerate(keys, start=1):
32-
f.write(f"{item}\t{dct[item]}")
35+
with open(p, "w") as f:
36+
f.write("id\tmessage\n")
3337

34-
if i != len(keys):
35-
f.write("\n")
38+
for i, item in enumerate(keys, start=1):
39+
f.write(f"{item}\t{dct[item]}")
40+
41+
if i != len(keys):
42+
f.write("\n")
43+
44+
elif sys.argv[1] == "scrape":
45+
b = "https://core.telegram.org"
46+
c = "/api/errors"
47+
a = requests.get(b + c)
48+
d = a.text
49+
e = r"\<a\ href\=\"(.*)\"\>here.*\<\/a\>"
50+
f = re.search(e, d)
51+
if f:
52+
a = requests.get(
53+
b + f.group(1)
54+
)
55+
d = a.json()
56+
e = d.get("errors", [])
57+
w = ""
58+
for h in e:
59+
j = b.get("errors").get(h)
60+
for k in j:
61+
if k.endswith("_*"):
62+
continue
63+
g = d.get("descriptions")
64+
l = g.get(k)
65+
m = k.replace("_%d", "_X")
66+
l = l.replace("%d", "{value}")
67+
w += f"{m}\t{l}\n"
68+
for p in Path("source/").glob(f"{d}*.tsv"):
69+
with open(p, "w") as f:
70+
f.write("id\tmessage\n")
71+
f.write(w)

0 commit comments

Comments
 (0)