work on conversion to 3 step processing with JSON pre-process files, commenting on some classes & methods

This commit is contained in:
Xevion
2020-03-10 18:20:03 -05:00
parent a04a211c55
commit 24dde199e2

View File

@@ -55,7 +55,8 @@ class Season(db.Model):
@staticmethod @staticmethod
def create_all(build=True): def create_all(build=True):
"""creates new Season objects and runs build() on them""" """
creates new Season objects and runs build() on them"""
for i in range(1, 10): for i in range(1, 10):
if Season.query.get(i) is None: if Season.query.get(i) is None:
s = Season(id=i) s = Season(id=i)
@@ -66,18 +67,26 @@ class Season(db.Model):
@staticmethod @staticmethod
def rebuild_all(): def rebuild_all():
"""runs build() on all Season objects in database""" """
Runs .build() on all Season objects in database
"""
for season in Season.query.all(): for season in Season.query.all():
season.rebuild() season.rebuild()
@property @property
def characters(self, sort): def characters(self, sort):
"""returns a List of Characters under this Season, sorted by number of spoken lines""" """
returns a List of all characters in this Season, built off the Episode's .characters() method
"""
pass pass
class Episode(db.Model): class Episode(db.Model):
"""represents a Episode with underlying Sections (representing a specific cutscene or area""" """
represents a Episode with underlying Sections (representing a specific cutscene in the show)
also has some other attributes useful for identify the episode and displaying, as well as countless methods
aimed at providing easy to access information using the database collection
"""
id = db.Column( id = db.Column(
db.Integer, primary_key=True db.Integer, primary_key=True
@@ -148,30 +157,34 @@ class Episode(db.Model):
sections = soup.find_all(attrs={"class": "quote"}) sections = soup.find_all(attrs={"class": "quote"})
deleted = 0 deleted = 0
root = []
for section in sections: for section in sections:
isNewpeat = False isNewpeat = False
isDeleted = "deleted scene" in section.text
if isDeleted:
deleted += 1
quotes = [] quotes = []
for quote in section.find_all("b"): for quote in section.find_all("b"):
if "Newpeat" in quote.string: if "Newpeat" in quote.string:
quote = quote.next_sibling quote = quote.next_sibling
isNewpeat = True isNewpeat = True
if quote is None or quote.next_sibling is None: # if quote is None or quote.next_sibling is None:
print("Quote is None or next sibling is None") # print("Quote is None or next sibling is None")
continue # continue
quotes.append(quote.string + quote.next_sibling.string) quotes.append(quote.string + quote.next_sibling.string)
if len(quotes) == 0: if len(quotes) == 0:
print(f"Section found with Zero quotes. Newpeat: {isNewpeat}") print(f"Section found with Zero quotes. Newpeat: {isNewpeat} Deleted: {isDeleted}")
continue if not (isNewpeat or isDeleted):
isDeletedScene = quotes[0].lower().startswith("deleted scene") continue
if isDeletedScene:
deleted += 1 sectionData = {'isNewpeat' : isNewpeat, 'isDeleted' : isDeleted, 'quotes' : quotes}
s = Section( root.append(sectionData)
episode_id=self.id,
deleted=deleted if isDeletedScene else -1, with open(self.JSONpath, 'w+', encoding='utf-8') as file:
newpeat=isNewpeat, json.dump(root, file)
)
s.build(quotes[1:] if isDeletedScene else quotes)
db.session.add(s)