-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
48 lines (40 loc) · 1.53 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
from argparse import ArgumentParser
import sys
import json
from requests import RequestException
from SAScrapper import download_page_as_soup, get_courses_tables, tables_to_courses
SUPPORTED_PAGES = {
'sdvx4': 'http://bemaniwiki.com/index.php?SOUND%20VOLTEX%20IV%20HEAVENLY%20HAVEN/SKILL%20ANALYZER',
'sdvx5': 'http://bemaniwiki.com/index.php?SOUND%20VOLTEX%20VIVID%20WAVE/SKILL%20ANALYZER',
}
DEFAULT_PAGE = SUPPORTED_PAGES['sdvx5']
DESCRIPTION = '''\
Scraps Skill Analyzer SDVX courses from Bemaniwiki 2nd and outputs them as JSON.
'''
def parse_args():
parser = ArgumentParser(description=DESCRIPTION)
parser.add_argument('url', metavar='game or URL', type=str, nargs='?',
default=DEFAULT_PAGE,
help='Supported games: {}'.format(list(SUPPORTED_PAGES.keys())))
parser.add_argument('--indent', metavar='N', type=int, default=2,
help='Indent level for JSON output')
parser.add_argument('--unicode-escapes', action='store_true',
help='Escapes non-ASCII strings with unicode escapes')
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
if args.url in SUPPORTED_PAGES:
args.url = SUPPORTED_PAGES[args.url]
try:
page = download_page_as_soup(args.url)
except RequestException as e:
print(e)
sys.exit(1)
tables = get_courses_tables(page)
courses = tables_to_courses(tables)
print(json.dumps(
courses,
ensure_ascii=args.unicode_escapes,
indent=args.indent,
default=lambda x: x.__dict__)
)