mirror of
https://github.com/Xevion/the-office.git
synced 2025-12-16 10:13:35 -06:00
season rebuilding/redownloading methods, titles for directory
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -23,6 +23,18 @@ def viewEpisode(season, episode):
|
||||
return render_template("episode.html", episode=e, seasons=Season.query.all())
|
||||
|
||||
|
||||
@app.route("/redownload/<season>")
|
||||
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/<season>")
|
||||
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/<season>/<episode>/")
|
||||
def rebuildEpisode(season, episode):
|
||||
e = Episode.query.filter_by(season_id=season, number=episode).first_or_404()
|
||||
@@ -34,3 +46,4 @@ 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))
|
||||
|
||||
|
||||
213
app/static/titles.json
Normal file
213
app/static/titles.json
Normal file
@@ -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"
|
||||
]
|
||||
]
|
||||
@@ -19,9 +19,9 @@
|
||||
<div class="box">
|
||||
{# List of Seasons/Episodes #}
|
||||
{% for season in seasons %}
|
||||
<b><a href="{{ url_for("viewSeason", season=season.id) }}" >Season {{ season.id }}</a></b><br>
|
||||
<u><b><a href="{{ url_for("viewSeason", season=season.id) }}" >Season {{ season.id }}</a></b><br></u>
|
||||
{% for episode in season.episodes %}
|
||||
<a class="tab" href="{{ url_for("viewEpisode", season=season.id, episode=episode.number) }}" > e{{ episode.number }} - "Episode Name"</a><br>
|
||||
<a class="tab" href="{{ url_for("viewEpisode", season=season.id, episode=episode.number) }}" > e{{ episode.number }} - <em>{{ episode.title }}</em></a><br>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user