-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmock_data.py
executable file
·95 lines (86 loc) · 2.58 KB
/
mock_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python3
"""
Script to provide mock input to the script to test regex results and other stuff.
Requires xdcc_anime.py in the same folder.
"""
__author__ = "nightly5"
__license__ = "MIT"
import re
import sys
import requests
import xdcc_anime
def prepare_mock_data():
"""
Fetches the data using a requests session.
"""
with requests.session() as session:
print("\033[36mFetching data from the bot…\033[0m")
try:
for link, file_name in [
(
"https://arutha.info/xdcc/CR-NL.NEW.xdcc.txt",
"CR-ARUTHA.NEW.xdcc.txt"
),
(
"https://arutha.info/xdcc/ARUTHA-BATCH.1080p.xdcc.txt",
"ARUTHA-BATCH.1080p.xdcc.txt"
)
]:
with (session.get(link) as r, open(file_name, "w") as f):
if r.status_code == 200:
f.write(r.text)
else:
print(
"\033[31mThe required data cannot be fetched."
f" \033[1;36m{r.status_code} {r.reason}\033[0m"
)
except KeyboardInterrupt:
print("\033[31mRequest manually stopped by the user.\033[0m")
exit(130)
def _mock_data():
with (
open("ARUTHA-BATCH.1080p.xdcc.txt") as f1,
open("CR-ARUTHA.NEW.xdcc.txt") as f2
):
f1_txt = f1.read()
f2_txt = f2.read()
args_list = (
(
re.escape("vinland saga s2"), # test for lower case
"1080p",
"CR-HOLLAND|NEW",
f2_txt
),
(
re.escape("tokyo revengers"), # test for ep with 01v2 format
"1080p",
"ARUTHA-BATCH|1080p",
f1_txt
),
(
re.escape("tok"), # test for partial anime name
"1080p",
"ARUTHA-BATCH|1080p",
f1_txt
),
(
re.escape("yahari"), # horriblesubs packs
"1080p",
"ARUTHA-BATCH|1080p",
f1_txt
),
(
re.escape("kakushigoto movie"), # single ep with no episode number
"1080p",
"CR-HOLLAND|NEW",
f2_txt
),
)
for i, args in enumerate(args_list):
print(f"\nMock {i+1}: {args[0]}")
xdcc_anime.PRINT_EACH_PACK = True
xdcc_anime.process_data(*args)
if __name__ == "__main__":
if sys.argv.pop() in ('--get-deta', '-g'):
prepare_mock_data()
_mock_data()