[chore] format code

This commit is contained in:
SouthFox 2023-05-09 17:34:28 +08:00
parent 20b89b5139
commit 81120e8540
2 changed files with 19 additions and 1 deletions

View file

@ -7,6 +7,8 @@ from BDSM.models import Toot, Tag, Media, Emoji, Poll, Settings
import sys import sys
import dateutil.parser import dateutil.parser
def app_register(url): def app_register(url):
print("Registering app") print("Registering app")
Mastodon.create_app( Mastodon.create_app(
@ -16,6 +18,7 @@ def app_register(url):
scopes=["read"] scopes=["read"]
) )
def app_login(url): def app_login(url):
mastodon = Mastodon( mastodon = Mastodon(
client_id='data/pyBDSM_clientcred.secret', client_id='data/pyBDSM_clientcred.secret',
@ -39,6 +42,7 @@ def app_login(url):
return mastodon, user return mastodon, user
def get_context(url, toot_id): def get_context(url, toot_id):
mastodon, _ = app_login(url) mastodon, _ = app_login(url)
settings = Settings.query.first() settings = Settings.query.first()
@ -50,6 +54,7 @@ def get_context(url, toot_id):
db.session.commit() db.session.commit()
def toot_process(statuses, my_acct, duplicates_counter=0): def toot_process(statuses, my_acct, duplicates_counter=0):
for status in statuses: for status in statuses:
is_reblog = False 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)) # poll_id,emoji_list,visibility,reblogged,favourited,bookmarked,sensitive,reblogs_count,favourites_count,language))
return duplicates_counter return duplicates_counter
def archive_toot(url, archive_match): def archive_toot(url, archive_match):
mastodon, user = app_login(url) mastodon, user = app_login(url)
acct = mastodon.me().acct acct = mastodon.me().acct

View file

@ -13,11 +13,14 @@ from mastodon import Mastodon
from types import SimpleNamespace from types import SimpleNamespace
from datetime import timezone from datetime import timezone
# @app.context_processor # @app.context_processor
# def inject_setting(): # def inject_setting():
# settings = Settings.query.first() # settings = Settings.query.first()
# return settings.__dict__ # return settings.__dict__
@app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST'])
def index(): def index():
settings = Settings.query.first() settings = Settings.query.first()
@ -33,6 +36,7 @@ def index():
return render_template('view.html', toots=toots, pagination=toots_, path=path) return render_template('view.html', toots=toots, pagination=toots_, path=path)
@app.route('/favourited', methods=['GET', 'POST']) @app.route('/favourited', methods=['GET', 'POST'])
def favourited(): def favourited():
settings = Settings.query.first() settings = Settings.query.first()
@ -48,6 +52,7 @@ def favourited():
return render_template('view.html', toots=toots, pagination=toots_, path=path) return render_template('view.html', toots=toots, pagination=toots_, path=path)
@app.route('/bookmarked', methods=['GET', 'POST']) @app.route('/bookmarked', methods=['GET', 'POST'])
def bookmarked(): def bookmarked():
settings = Settings.query.first() settings = Settings.query.first()
@ -63,6 +68,7 @@ def bookmarked():
return render_template('view.html', toots=toots, pagination=toots_, path=path) return render_template('view.html', toots=toots, pagination=toots_, path=path)
@app.route('/search', methods=['GET', 'POST']) @app.route('/search', methods=['GET', 'POST'])
def search(): def search():
if request.method == 'POST': if request.method == 'POST':
@ -117,6 +123,7 @@ def context(toot_id):
return render_template('view.html', toots=toots,) return render_template('view.html', toots=toots,)
@app.route('/grab/<int:toot_id>', methods=['GET', 'POST']) @app.route('/grab/<int:toot_id>', methods=['GET', 'POST'])
def grab(toot_id): def grab(toot_id):
settings = Settings.query.first() settings = Settings.query.first()
@ -127,6 +134,7 @@ def grab(toot_id):
flash('抓取完成……大概!') flash('抓取完成……大概!')
return redirect(url_for('context',toot_id=toot_id)) return redirect(url_for('context',toot_id=toot_id))
@app.route('/settings', methods=['GET', 'POST']) @app.route('/settings', methods=['GET', 'POST'])
def settings(): def settings():
if request.method == 'POST': if request.method == 'POST':
@ -155,6 +163,7 @@ def settings():
return render_template('settings.html',settings=settings, app_init=app_init) return render_template('settings.html',settings=settings, app_init=app_init)
@app.route('/register', methods=['GET', 'POST']) @app.route('/register', methods=['GET', 'POST'])
def register(): def register():
settings = Settings.query.first() settings = Settings.query.first()
@ -189,6 +198,7 @@ def register():
flash('已授权过!') flash('已授权过!')
return redirect(url_for('settings')) return redirect(url_for('settings'))
@app.route('/archive', methods=['GET', 'POST']) @app.route('/archive', methods=['GET', 'POST'])
def archive(): def archive():
settings = Settings.query.first() settings = Settings.query.first()
@ -206,6 +216,7 @@ def archive():
else: else:
return render_template('archive.html') return render_template('archive.html')
def process_toot(toots_): def process_toot(toots_):
toots = [] toots = []
settings = Settings.query.first() settings = Settings.query.first()
@ -251,7 +262,7 @@ def process_toot(toots_):
if emoji != None: if emoji != None:
emoji_shortcode = ':' + emoji_shortcode + ':' emoji_shortcode = ':' + emoji_shortcode + ':'
emoji_url = emoji.url # emoji_url = emoji.url
emoji_html = f''' emoji_html = f'''
<img class="emojione custom-emoji" alt="{emoji_shortcode}" title="{emoji_shortcode}" src="{emoji.url}" > <img class="emojione custom-emoji" alt="{emoji_shortcode}" title="{emoji_shortcode}" src="{emoji.url}" >
''' '''
@ -269,4 +280,5 @@ def process_toot(toots_):
toot.content += poll_content toot.content += poll_content
toots.append(toot) toots.append(toot)
return toots return toots