-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmegadb_indextransforms.py
120 lines (101 loc) · 3.94 KB
/
megadb_indextransforms.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python3
# -*- python -*-
# Copyright (c) HarJIT 2015, 2017.
#
# THIS WORK IS PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL THE AUTHORS OR CONTRIBUTORS
# BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE),
# ARISING IN ANY WAY OUT OF THE USE OF THIS WORK, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Permission is granted to anyone to use this work for any purpose, including
# commercial applications, and to alter it and/or redistribute it freely in any
# form, with or without modification, subject to the following restrictions:
#
# 1. The origin of this work must not be misrepresented; you must not claim that
# you authored the original work. If you use this work in a product, an
# acknowledgment in the product documentation would be appreciated but is not
# required.
#
# 2. Altered versions in any form must not be misrepresented as being the
# original work, and neither the name of HarJIT nor the names of authors or
# contributors may be used to endorse or promote products derived from this
# work without specific prior written permission.
#
# 3. The text of this notice must be included, unaltered, with any distribution.
#
import utility
#SB2Year
def handle_strip_record(strip, by_year, by_year_order, yovr=None):
date = strip["Date"]
year = yovr or date[:4]
if year == "2013":
year = "2013 [- Jul 2014]"
if year in by_year_order:
by_year[year]["Comics"].append(strip)
else:
by_year[year] = {
"Title": year,
"Comics": [strip],
"RecordType": "StoryLine"
}
by_year_order.append(year)
def handle_arc(arc, by_year, by_year_order):
print(">>>>", arc["Title"])
yovr = None
if arc["Title"] not in ("Miscellaneous", "Sketch Week #1"):
yovr = arc["Title"]
for i in arc["Comics"]:
handle_strip_record(i, by_year, by_year_order, yovr)
def megadb_sb2year(main_db):
print(">>> megadb_sb2year (megadb_indextransforms)")
by_year = {}
by_year_order = []
for arc in utility.specific_section(main_db, "sketch")["StoryArcs"]:
handle_arc(arc, by_year, by_year_order)
output = []
for year in by_year_order:
output.append(by_year[year])
utility.specific_section(main_db, "sketch")["StoryArcs"] = output
return main_db
#ArcLine
def handle_line(line, arcs, curatitl_p):
print(line["Title"])
if line["Title"].count(": "):
atitl, ltitl = line["Title"].split(": ", 1)
if atitl != curatitl_p[0]:
if atitl in curatitl_p[1]:
curatitl_p[2] = arcs.index(curatitl_p[1][atitl])
else:
myne = {
"Title": atitl,
"StoryLines": [],
"RecordType": "StoryArc"
}
arcs.append(myne)
curatitl_p[1][atitl] = myne
curatitl_p[2] = -1
curatitl_p[0] = atitl
arcs[curatitl_p[2]]["StoryLines"].append({
"Title": ltitl,
"Comics": line["Comics"],
"RecordType": "StoryLine"
})
else:
curatitl_p[0] = ""
arcs.append(line)
def megadb_arcline(main_db):
print(">>> megadb_arcline (megadb_indextransforms)")
arcs = []
curatitl_p = ["", {}, -1] #functioning as struct of pointers.
arcs_in = utility.specific_section(main_db, "story")["StoryArcs"]
for arc in arcs_in:
handle_line(arc, arcs, curatitl_p)
utility.specific_section(main_db, "story")["StoryArcs"] = arcs
return main_db
#
def megadb_indextransforms(alldat):
return megadb_arcline(megadb_sb2year(alldat))