-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
79 lines (59 loc) · 2.34 KB
/
main.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
from downloader import Downloader
from extractor import (
BundlesExtractor,
FlatbufferExtractor,
MediasExtractor,
TablesExtractor,
)
from lib.console import notice
from lib.structure import Resource, ResourceItem
from utils.config import Config
from xtractor.character import CharacterNameRelation
def filter_resource_type(resource: Resource) -> Resource:
"""Filter the necessary item from the resource_type specified in the Config"""
if len(Config.resource_type) == 3:
return resource
filtered_res = Resource()
for res in resource:
if res.resource_type.name in Config.resource_type:
filtered_res.add_item(res)
return filtered_res
def process_search(resource: Resource, keywords: list[str]) -> Resource:
results = Resource()
searched_list: list[ResourceItem] = []
for keyword in keywords:
searched_list += resource.search_resource("path", keyword)
for searched in searched_list:
results.add_item(searched)
return results
if __name__ == "__main__":
downloader = Downloader()
res = downloader.main()
if Config.region == "jp":
fb_extractor = FlatbufferExtractor()
if "table" in Config.resource_type or Config.advance_search:
fb_extractor.dump()
fb_extractor.compile()
if Config.advance_search:
notice("Preparing for advance srearch...")
char_extractor = CharacterNameRelation()
if not char_extractor.verify_relation_file(Config.version, Config.region):
excel_zip = char_extractor.get_excel_res(res)
downloader.verify_and_download(excel_zip)
char_extractor.main()
keywords = char_extractor.search(
Config.version, Config.region, Config.advance_search
)
res = process_search(res, keywords)
if Config.search:
res = process_search(res, Config.search)
resource = filter_resource_type(res)
downloader.verify_and_download(resource)
if Config.region == "jp":
if "table" in Config.resource_type:
TablesExtractor().extract_tables()
if "bundle" in Config.resource_type:
BundlesExtractor.extract()
if "media" in Config.resource_type:
MediasExtractor().extract_zips()
notice("Extract task done.")