From e951d55d222da68593b21dc350b16509317a5abd Mon Sep 17 00:00:00 2001 From: Xevion Date: Mon, 9 Mar 2020 21:03:58 -0500 Subject: [PATCH] season rebuilding/redownloading methods, titles for directory --- app/models.py | 15 ++- app/routes.py | 15 ++- app/static/titles.json | 213 +++++++++++++++++++++++++++++++++++++ app/templates/content.html | 4 +- 4 files changed, 240 insertions(+), 7 deletions(-) create mode 100644 app/static/titles.json diff --git a/app/models.py b/app/models.py index 0267e51..ee1a1e1 100644 --- a/app/models.py +++ b/app/models.py @@ -1,4 +1,5 @@ import requests +import json import os from bs4 import BeautifulSoup @@ -17,7 +18,8 @@ episodes = [ 23, ] # Episode counts. Index 0 is for Webisodes. quotePattern = r"([\w\s\.\',-\[\]\d&\"#]+):(.+)" - +with open(os.path.join('app', 'static', 'titles.json')) as file: + titles = json.load(file) class Season(db.Model): id = db.Column(db.Integer, primary_key=True) @@ -63,6 +65,9 @@ class Season(db.Model): for season in Season.query.all(): season.build(rebuild=True) + @staticmethod + + @property def episodes(self): """returns a List of Episodes under this Season""" @@ -81,6 +86,7 @@ class Episode(db.Model): db.Integer, primary_key=True ) # arbitrary ID, should NOT be relied on to determine episode number or correlating season number = db.Column(db.Integer) # episode number + title = db.Column(db.String(32)) season_id = db.Column( db.Integer, db.ForeignKey("season.id") ) # correlating season number @@ -95,7 +101,7 @@ class Episode(db.Model): @property def path(self): - return os.path.join('app', 'data', f'{self.season_id}-{self.number}.html') + return os.path.join("app", "data", f"{self.season_id}-{self.number}.html") @property def downloaded(self): @@ -104,13 +110,13 @@ class Episode(db.Model): def download(self, force=False): """downloads data""" if not self.downloaded or force: - print(f'Downloading e{self.number}/s{self.season_id} from {self.link}') + print(f"Downloading e{self.number}/s{self.season_id} from {self.link}") data = requests.get(self.link).text open(self.path, "w+", encoding="utf-8").write(data) @property def data(self): - return open(self.path, 'r', encoding="utf-8").read() + return open(self.path, "r", encoding="utf-8").read() def build(self): """downloads, processes, and automatically creates Sections and Quotes""" @@ -145,6 +151,7 @@ class Episode(db.Model): s.build(quotes[1:] if isDeletedScene else quotes) db.session.add(s) self.built = True + self.title = titles[self.season_id - 1][self.number - 1] db.session.commit() def rebuild(self): diff --git a/app/routes.py b/app/routes.py index b805ff7..55fc574 100644 --- a/app/routes.py +++ b/app/routes.py @@ -23,6 +23,18 @@ def viewEpisode(season, episode): return render_template("episode.html", episode=e, seasons=Season.query.all()) +@app.route("/redownload/") +def rebuildSeason(season): + season = Season.query.filter_by(id=season).first_or_404() + season.rebuild() + return redirect(url_for("viewSeason", season=season.id)) + +@app.route("/redownload/") +def rebuildSeason(season): + seasonObj = Season.query.filter_by(id=season).first_or_404() + seasonObj.redownload_all() + return redirect(url_for("viewSeason", season=season)) + @app.route("/rebuild///") def rebuildEpisode(season, episode): e = Episode.query.filter_by(season_id=season, number=episode).first_or_404() @@ -33,4 +45,5 @@ def rebuildEpisode(season, episode): def redownloadEpisode(season, episode): e = Episode.query.filter_by(season_id=season, number=episode).first_or_404() e.download(force=True) - return redirect(url_for("viewEpisode", season=season, episode=episode)) \ No newline at end of file + return redirect(url_for("viewEpisode", season=season, episode=episode)) + diff --git a/app/static/titles.json b/app/static/titles.json new file mode 100644 index 0000000..625fff1 --- /dev/null +++ b/app/static/titles.json @@ -0,0 +1,213 @@ +[ + [ + "Webisodes – Kevin’s Loan", + "Webisodes – Subtle Sexuality", + "Webisodes – The 3rd floor", + "Creed Thoughts", + "Schrute Space" + ], + [ + "Pilot", + "Diversity Day", + "Health Care", + "The Alliance", + "Basketball", + "Hot Girl" + ], + [ + "The Dundies", + "Sexual Harassment", + "Office Olympics", + "The Fire", + "Halloween", + "The Fight", + "The Client", + "Performance Review", + "E-mail Surveillance", + "Christmas Party", + "Booze Cruise", + "The Injury", + "The Secret", + "The Carpet", + "Boys and Girls", + "Valentine’s Day", + "Dwight’s Speech", + "Take Your Daughter to Work Day", + "Michael’s Birthday", + "Drug Testing", + "Conflict Resolution", + "Casino Night" + ], + [ + "Gay Witch Hunt", + "The Convention", + "The Coup", + "Grief Counseling", + "Initiation", + "Diwali", + "Branch Closing", + "The Merger", + "The Convict", + "A Benihana Christmas", + "Back From Vacation", + "Traveling Salesmen", + "The Return", + "Ben Franklin", + "Phyllis’ Wedding", + "Business School", + "Cocktails", + "The Negotiation", + "Safety Training", + "Product Recall", + "Women’s Appreciation", + "Beach Games", + "The Job" + ], + [ + "Fun Run", + "Dunder Mifflin Infinity", + "Launch Party", + "Money", + "Local Ad", + "Branch Wars", + "Survivor Man", + "The Deposition", + "Dinner Party", + "Chair Model", + "Night Out", + "Did I Stutter?", + "Job Fair", + "Goodbye Toby" + ], + [ + "Weight Loss", + "Business Ethics", + "Baby Shower", + "Crime Aid", + "Employee Transfer", + "Customer Survey", + "Business Trip", + "Frame Toby", + "The Surplus", + "Moroccan Christmas", + "The Duel", + "Prince Family Paper", + "Stress Relief", + "Lecture Circuit 1", + "Lecture Circuit 2", + "Blood Drive", + "Golden Ticket", + "New Boss", + "Two Weeks", + "Dream Team", + "Michael Scott Paper Company", + "Heavy Competition", + "Broke", + "Casual Friday", + "Cafe Disco", + "Company Picnic" + ], + [ + "Gossip", + "The Meeting", + "The Promotion", + "Niagara", + "Mafia", + "The Lover", + "Koi Pond", + "Double Date", + "Murder", + "Shareholder Meeting", + "Scott’s Tots", + "Secret Santa", + "The Banker", + "Sabre", + "Manager and Salesman", + "The Delivery", + "St. Patrick’s Day", + "New Leads", + "Happy Hour", + "Secretary’s Day", + "Body Language", + "The Cover-Up", + "The Chump", + "Whistleblower" + ], + [ + "Nepotism", + "Counseling", + "Andy’s Play", + "Sex Ed", + "The Sting", + "Costume Contest", + "Christening", + "Viewing Party", + "WUPHF.com", + "China", + "Classy Christmas", + "Ultimatum", + "The Seminar", + "The Search", + "PDA", + "Threat Level Midnight", + "Todd Packer", + "Garage Sale", + "Trainin Day", + "Michael’s Last Dundies", + "Goodbye Michael", + "The Inner Circle", + "Dwight K. Schrute, (Acting) Manager", + "Search Committee" + ], + [ + "The List", + "The Incentive", + "Lotto", + "Garden Party", + "Spooked", + "Doomsday", + "Pam’s Replacement", + "Gettysburg", + "Mrs. California", + "Christmas Wishes", + "Trivia", + "Pool Party", + "Jury Duty", + "Special Project", + "Tallahasse", + "After Hours", + "Test the Store", + "Last Day In Florida", + "Get The Girl", + "Welcome Party", + "Angry Andy", + "Fundraiser", + "Turf War", + "Free Family Portrait Studio" + ], + [ + "New Guys", + "Roy’s Wedding", + "Andy’s Ancestry", + "Work Bus", + "Here Comes Treble", + "The Boat", + "The Whale", + "The Target", + "Dwight Christmas", + "Lice", + "Suit Warehouse", + "Customer Loyalty", + "Junior Salesman", + "Vandalism", + "Couples Discount", + "Moving On", + "The Farm", + "Promos", + "Stairmageddon", + "Paper Airplane", + "Livin’ The Dream", + "A.A.R.M", + "Finale" + ] +] \ No newline at end of file diff --git a/app/templates/content.html b/app/templates/content.html index 297b809..81c0be6 100644 --- a/app/templates/content.html +++ b/app/templates/content.html @@ -19,9 +19,9 @@
{# List of Seasons/Episodes #} {% for season in seasons %} - Season {{ season.id }}
+ Season {{ season.id }}
{% for episode in season.episodes %} - e{{ episode.number }} - "Episode Name"
+ e{{ episode.number }} - {{ episode.title }}
{% endfor %} {% endfor %}