-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (70 loc) · 2.27 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
from tabgetter import GuitarTabGetter
import chords
import book
def get_lines_from_file(filename):
with open(filename) as f:
for line in f:
if not line.startswith("#"):
yield line.strip()
def main():
import argparse
parser = argparse.ArgumentParser(
description="Download tabs and generate HTML and/or PDF and/or Mobi files"
)
parser.add_argument("--mobi", "-m", action="store_true", help="Generate mobi file")
parser.add_argument("--pdf", "-p", action="store_true", help="Generate pdf file")
parser.add_argument("--fake", "-f", action="store_true", help="Use fake data (to make output easier to compare)")
parser.add_argument(
"--tabfile",
"-t",
action="append",
help="File containing URL for tabs",
default=[],
)
parser.add_argument(
"--listfile",
"-l",
action="append",
help="File containing URL for lists of tabs",
default=[],
)
parser.add_argument(
"--output",
"-o",
help='File containing URL for lists of tabs (".html" suffix not required)',
default="output/book",
)
parser.add_argument(
"--name",
"-n",
help="Name for for generated book",
default="Tabs and Chords",
)
# TODO: Add options for content such as cover
args = parser.parse_args()
print(args)
use_fake_data = args.fake
tabs = []
for filename in args.tabfile:
lines = list(get_lines_from_file(filename))
nb_urls = str(len(lines))
for i, url in enumerate(lines, start=1):
tab = GuitarTabGetter.from_url(url, "%d/%s" % (i, nb_urls), use_fake_data)
if tab is not None:
tabs.append(tab)
for filename in args.listfile:
lines = list(get_lines_from_file(filename))
nb_urls = str(len(lines))
for i, url in enumerate(lines, start=1):
tabs.extend(GuitarTabGetter.from_list_url(url, "%d/%s" % (i, nb_urls), use_fake_data))
book.make_book(
tabs,
chords.Chord.get_all(),
base_filename=args.output,
make_mobi=args.mobi,
make_pdf=args.pdf,
use_fake_data=use_fake_data,
title=args.name,
)
if __name__ == "__main__":
main()