-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
82 lines (58 loc) · 1.74 KB
/
generator.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
import shutil
from pathlib import Path
from lib.gig import Gig
from lib.music_album import MusicAlbum
from lib.person import Person
from lib.raw_funk_maharishi import RawFunkMaharishi
from lib.tools import save_json
from lib.venue import Venue
def make_dirs():
"""Make the output dirs."""
outdir = Path("dist/venues")
if outdir.exists():
shutil.rmtree(str(outdir))
Path(outdir).mkdir(exist_ok=True, parents=True)
def make_list(klass, directory, sort_key=None):
"""Make a list of things."""
things = list(map(klass, Path("data", directory).glob("**/*.yaml")))
if sort_key:
things.sort(key=lambda x: x[sort_key])
save_json(things, "dist", f"{directory}.json")
def make_gigs():
"""Make the `Gigs` data."""
make_list(Gig, "gigs", "startDate")
def make_records():
"""Make the `MusicAlbums` data."""
make_list(MusicAlbum, "records", "datePublished")
def make_items(klass, directory):
"""Make a collection."""
things = Path("data", directory).glob("**/*.yaml")
for thing in things:
item = klass(thing)
item.save()
def make_venues():
"""Make the `Venues` data."""
make_items(Venue, "venues")
def make_people():
"""Make the `People` data."""
make_items(Person, "people")
def make_rfm():
"""Make the `RawFunkMaharishi` data."""
rfm = RawFunkMaharishi()
rfm.save()
def make_index():
"""Make a front page."""
things = {
"The band": "raw-funk-maharishi.json",
"Records": "records.json",
"Gigs": "gigs.json",
}
save_json(things, "dist", "index.json")
# this could use some tests tbh
if __name__ == "__main__":
make_dirs()
make_venues()
make_people()
make_gigs()
make_records()
make_rfm()