From 81120e8540e17e4f9a82d0e0fac0b0105e9190a9 Mon Sep 17 00:00:00 2001 From: southfox Date: Tue, 9 May 2023 17:34:28 +0800 Subject: [PATCH] [chore] format code --- BDSM/toot.py | 6 ++++++ BDSM/views.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/BDSM/toot.py b/BDSM/toot.py index b4217a1..0bb22c0 100644 --- a/BDSM/toot.py +++ b/BDSM/toot.py @@ -7,6 +7,8 @@ from BDSM.models import Toot, Tag, Media, Emoji, Poll, Settings import sys import dateutil.parser + + def app_register(url): print("Registering app") Mastodon.create_app( @@ -16,6 +18,7 @@ def app_register(url): scopes=["read"] ) + def app_login(url): mastodon = Mastodon( client_id='data/pyBDSM_clientcred.secret', @@ -39,6 +42,7 @@ def app_login(url): return mastodon, user + def get_context(url, toot_id): mastodon, _ = app_login(url) settings = Settings.query.first() @@ -50,6 +54,7 @@ def get_context(url, toot_id): db.session.commit() + def toot_process(statuses, my_acct, duplicates_counter=0): for status in statuses: is_reblog = False @@ -212,6 +217,7 @@ def toot_process(statuses, my_acct, duplicates_counter=0): # poll_id,emoji_list,visibility,reblogged,favourited,bookmarked,sensitive,reblogs_count,favourites_count,language)) return duplicates_counter + def archive_toot(url, archive_match): mastodon, user = app_login(url) acct = mastodon.me().acct diff --git a/BDSM/views.py b/BDSM/views.py index 42880be..fae5df5 100644 --- a/BDSM/views.py +++ b/BDSM/views.py @@ -13,11 +13,14 @@ from mastodon import Mastodon from types import SimpleNamespace from datetime import timezone + + # @app.context_processor # def inject_setting(): # settings = Settings.query.first() # return settings.__dict__ + @app.route('/', methods=['GET', 'POST']) def index(): settings = Settings.query.first() @@ -33,6 +36,7 @@ def index(): return render_template('view.html', toots=toots, pagination=toots_, path=path) + @app.route('/favourited', methods=['GET', 'POST']) def favourited(): settings = Settings.query.first() @@ -48,6 +52,7 @@ def favourited(): return render_template('view.html', toots=toots, pagination=toots_, path=path) + @app.route('/bookmarked', methods=['GET', 'POST']) def bookmarked(): settings = Settings.query.first() @@ -63,6 +68,7 @@ def bookmarked(): return render_template('view.html', toots=toots, pagination=toots_, path=path) + @app.route('/search', methods=['GET', 'POST']) def search(): if request.method == 'POST': @@ -117,6 +123,7 @@ def context(toot_id): return render_template('view.html', toots=toots,) + @app.route('/grab/', methods=['GET', 'POST']) def grab(toot_id): settings = Settings.query.first() @@ -127,6 +134,7 @@ def grab(toot_id): flash('抓取完成……大概!') return redirect(url_for('context',toot_id=toot_id)) + @app.route('/settings', methods=['GET', 'POST']) def settings(): if request.method == 'POST': @@ -155,6 +163,7 @@ def settings(): return render_template('settings.html',settings=settings, app_init=app_init) + @app.route('/register', methods=['GET', 'POST']) def register(): settings = Settings.query.first() @@ -189,6 +198,7 @@ def register(): flash('已授权过!') return redirect(url_for('settings')) + @app.route('/archive', methods=['GET', 'POST']) def archive(): settings = Settings.query.first() @@ -206,6 +216,7 @@ def archive(): else: return render_template('archive.html') + def process_toot(toots_): toots = [] settings = Settings.query.first() @@ -251,7 +262,7 @@ def process_toot(toots_): if emoji != None: emoji_shortcode = ':' + emoji_shortcode + ':' - emoji_url = emoji.url + # emoji_url = emoji.url emoji_html = f''' {emoji_shortcode} ''' @@ -269,4 +280,5 @@ def process_toot(toots_): toot.content += poll_content toots.append(toot) + return toots