-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
96 lines (79 loc) · 2.63 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# railway-opendata: scrape and analyze italian railway data
# Copyright (C) 2023 Marco Aceti
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
import os
import sys
import src.analysis.main as analysis
import src.scraper.main as scraper
from src import station_extractor, train_extractor
parser = argparse.ArgumentParser(
prog="train-scraper",
)
subparsers = parser.add_subparsers(dest="subcommand", required=True)
parser.add_argument("-d", "--debug", action="store_true", help="activate debug logs")
scraper_p = subparsers.add_parser(
"scraper",
help="station and train data scraper",
)
train_extractor.register_args(
subparsers.add_parser(
"train-extractor",
help="convert scraped train data",
)
)
station_extractor.register_args(
subparsers.add_parser(
"station-extractor",
help="convert scraped station data",
)
)
analysis.register_args(
subparsers.add_parser(
"analyze",
help="data analyzer and visualizer",
)
)
def main():
print(
"railway-opendata, Copyright (C) 2023 Marco Aceti"
"\nrailway-opendata comes with ABSOLUTELY NO WARRANTY; "
"for details read the LICENSE."
)
print()
hashseed: str | None = os.getenv("PYTHONHASHSEED")
if not hashseed or hashseed != "0":
logging.critical(
"Hash seed randomization is not disabled. "
"Please disable it by setting the PYTHONHASHSEED=0 environment variable."
)
sys.exit(1)
args: argparse.Namespace = parser.parse_args()
logging.basicConfig(
stream=sys.stdout,
format="[%(asctime)s - %(levelname)s] %(message)s",
level=logging.INFO if not args.debug else logging.DEBUG,
)
if args.subcommand == "scraper":
scraper.main()
if args.subcommand == "train-extractor":
train_extractor.main(args)
if args.subcommand == "station-extractor":
station_extractor.main(args)
if args.subcommand == "analyze":
analysis.main(args)
if __name__ == "__main__":
main()