From 3241ed1fe3d2b0e3f76968fc69c5eb79109cab3a Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 11 Jul 2021 10:10:25 +0200 Subject: [PATCH] Last touches --- pynyaata/__init__.py | 18 ++++++++++++++++-- pynyaata/config.py | 2 +- pynyaata/connectors/pantsu.py | 1 - pynyaata/templates/admin/folder/list.html | 5 +++++ pynyaata/templates/layout.html | 2 +- pynyaata/utils.py | 11 ----------- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pynyaata/__init__.py b/pynyaata/__init__.py index b51a848..0ece3c2 100644 --- a/pynyaata/__init__.py +++ b/pynyaata/__init__.py @@ -28,6 +28,19 @@ def mysql_required(f): return decorated_function +def clean_titles(): + db.engine.execute(""" +DELETE +FROM anime_title +WHERE id IN ( + SELECT anime_title.id + FROM anime_title + LEFT JOIN anime_link ON anime_title.id = anime_link.title_id + WHERE anime_link.id IS NULL +) +""") + + @auth.verify_password def verify_password(username, password): return username == ADMIN_USERNAME and ADMIN_PASSWORD == password @@ -71,8 +84,8 @@ def search(): return redirect(url_for('home')) set_event_loop(SelectorEventLoop()) - return render_template('search.html', search_form=SearchForm(), - connectors=get_event_loop().run_until_complete(run_all(query))) + torrents = get_event_loop().run_until_complete(run_all(query)) + return render_template('search.html', search_form=SearchForm(), connectors=torrents) @app.route('/latest') @@ -227,6 +240,7 @@ def admin_edit(link_id=None): # Database db.session.add(link) db.session.commit() + clean_titles() # Transmission if TRANSMISSION_ENABLED and isinstance(instance, Nyaa): diff --git a/pynyaata/config.py b/pynyaata/config.py index c9cd310..0870ac4 100644 --- a/pynyaata/config.py +++ b/pynyaata/config.py @@ -46,7 +46,7 @@ if db_host: db_user, db_password, db_host, db_name ) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True - app.config['SQLALCHEMY_ECHO'] = False + app.config['SQLALCHEMY_ECHO'] = IS_DEBUG app.config['SQLALCHEMY_ENGINE_OPTIONS'] = { 'pool_recycle': 200 } diff --git a/pynyaata/connectors/pantsu.py b/pynyaata/connectors/pantsu.py index 0c83950..076867b 100644 --- a/pynyaata/connectors/pantsu.py +++ b/pynyaata/connectors/pantsu.py @@ -75,7 +75,6 @@ class Pantsu(ConnectorCore): if response['http_code'] == 200: html = BeautifulSoup(response['output'], 'html.parser') title = html.select('h1.torrent-hr') - print(title, flush=True) return check_if_vf(title[0].get_text()) return False diff --git a/pynyaata/templates/admin/folder/list.html b/pynyaata/templates/admin/folder/list.html index cc7f3dd..c030ad4 100644 --- a/pynyaata/templates/admin/folder/list.html +++ b/pynyaata/templates/admin/folder/list.html @@ -1,6 +1,11 @@ {% extends "layout.html" %} {% block title %}- Folder List{% endblock %} {% block add_button %} + +   + Back +   diff --git a/pynyaata/templates/layout.html b/pynyaata/templates/layout.html index b35e586..c55b070 100644 --- a/pynyaata/templates/layout.html +++ b/pynyaata/templates/layout.html @@ -4,7 +4,7 @@ - + PyNyaaTa - {% block title %}{% endblock %} diff --git a/pynyaata/utils.py b/pynyaata/utils.py index b36738f..4ef82e8 100644 --- a/pynyaata/utils.py +++ b/pynyaata/utils.py @@ -1,6 +1,5 @@ import re from datetime import datetime - from dateparser import parse from .config import MYSQL_ENABLED, BLACKLIST_WORDS @@ -35,16 +34,6 @@ def boldify(str_to_replace, keyword): return str_to_replace -def clean_model(obj): - for attr in dir(obj): - if not attr.startswith('_') and getattr(obj, attr) is None: - try: - setattr(obj, attr, '') - except AttributeError: - pass - return obj - - def check_blacklist_words(url): return any(word.lower() in url.lower() for word in BLACKLIST_WORDS)