From b4d2922163f1d4bb4469fb5f62272446370f38cf Mon Sep 17 00:00:00 2001 From: Xevion Date: Mon, 9 Mar 2020 02:46:26 -0500 Subject: [PATCH] start working towards better GUI, implementing "download once" protocol --- app/models.py | 22 ++++++++++++++++++---- app/templates/content.html | 10 +++++++--- app/templates/episode.html | 3 ++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/models.py b/app/models.py index e81e754..69f6b44 100644 --- a/app/models.py +++ b/app/models.py @@ -1,5 +1,5 @@ import requests -import re +import os from bs4 import BeautifulSoup from app import db, login @@ -89,11 +89,25 @@ class Episode(db.Model): "Section", backref="episode", lazy="dynamic" ) # sections of quotes under this episode + @property + def links(self): + return f"http://officequotes.net/no{self.season_id}-{str(self.number).zfill(2)}.php" + + @property + def path(self): + return os.path.join('app', 'data', f'{self.season_id}-{self.number}') + + @property + def downloaded(self): + return os.path.exists(self.path) + + def download(self): + """downloads data""" + data = requests.get(link).text + open(self.path, "w+", encoding="utf-8").write(data) + def build(self): """downloads, processes, and automatically creates Sections and Quotes""" - link = f"http://officequotes.net/no{self.season_id}-{str(self.number).zfill(2)}.php" - data = requests.get(link).text - open("test.html", "w+", encoding="utf-8").write(data) soup = BeautifulSoup(data, "html.parser") sections = soup.find_all(attrs={"class": "quote"}) diff --git a/app/templates/content.html b/app/templates/content.html index 51cb4d9..c1bf03c 100644 --- a/app/templates/content.html +++ b/app/templates/content.html @@ -25,14 +25,18 @@ {{ super() }}
-
-
+
+
+ Test +
+
+
{% block content %} {% endblock content %}
-
+{#
#}
{% endblock body %} \ No newline at end of file diff --git a/app/templates/episode.html b/app/templates/episode.html index 5fb349d..0baf976 100644 --- a/app/templates/episode.html +++ b/app/templates/episode.html @@ -4,6 +4,7 @@ {% endblock head %} @@ -15,7 +16,7 @@
{% for section in episode.sections %}
-

+

{% for quote in section.quotes %} {{ quote.speaker }}: {{ quote.text }}