ui/archive page

This commit is contained in:
SouthFox 2022-11-09 02:21:50 +08:00
parent 57cadb2e11
commit 603bbff5ae
3 changed files with 55 additions and 17 deletions

View file

@ -0,0 +1,24 @@
{% extends 'base.html' %}
{% block content %}
<h3>存档</h3>
<form method="post" class="form-horizontal" role="form">
<div class="form-group">
<input type="checkbox" name="archive_match" value="statuses" checked> 嘟文
<input type="checkbox" name="archive_match" value="favourites" checked> 喜欢
<input type="checkbox" name="archive_match" value="bookmarks" checked> 书签
</div>
<div class="form-group">
<input type="checkbox" name="archive_match" value="duplicate" checked> 增量备份
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<p>1. 增量备份是指如果检查到数据库已存在嘟文超过十个就停止存档,即只存最新的。</p>
<p>2. 也因为现在嘟文、喜欢、收藏的数据全部存放在一起,所以可能导致增量备份逻辑混乱,
建议对每一个栏目来一次全量备份(即不勾选增量备份框)。</p>
<p>3. 目前没有做网页进度条,请前往终端(控制台)查看进度。</p>
<input class="btn btn-primary" type="submit" name="submit" value="存档!">
</div>
</div>
{% endblock %}

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from mastodon import Mastodon from mastodon import Mastodon
from tenacity import *
from BDSM import db from BDSM import db
from BDSM.models import Other, Toot, Tag, Media, Emoji, Poll from BDSM.models import Other, Toot, Tag, Media, Emoji, Poll
import sys import sys
@ -221,7 +222,8 @@ 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): # @retry(stop=stop_after_attempt(7))
def archive_toot(url, archive_match):
mastodon, user = app_login(url) mastodon, user = app_login(url)
acct = mastodon.me().acct acct = mastodon.me().acct
@ -243,13 +245,21 @@ def archive_toot(url):
if statuses == None: if statuses == None:
break break
skip_duplicates = False
if 'duplicate' in archive_match:
skip_duplicates = True
if 'statuses' in archive_match:
statuses_count = str(mastodon.me().statuses_count) statuses_count = str(mastodon.me().statuses_count)
statuses = mastodon.account_statuses(user["id"], limit=20) statuses = mastodon.account_statuses(user["id"], limit=20)
archive(statuses) archive(statuses, skip_duplicates=skip_duplicates)
if 'favourites' in archive_match:
statuses_count = '???' statuses_count = '???'
statuses = mastodon.favourites() statuses = mastodon.favourites()
archive(statuses) archive(statuses, skip_duplicates=skip_duplicates)
if 'bookmarks' in archive_match:
statuses_count = '???'
statuses = mastodon.bookmarks() statuses = mastodon.bookmarks()
archive(statuses, skip_duplicates=False) archive(statuses, skip_duplicates=skip_duplicates)

View file

@ -23,7 +23,7 @@ def index():
return redirect(url_for('settings')) return redirect(url_for('settings'))
else: else:
page = request.args.get('page', 1, type=int) page = request.args.get('page', 1, type=int)
toots_ = Toot.query.order_by(Toot.created_at.desc()).paginate(page, per_page=50) toots_ = Toot.query.order_by(Toot.created_at.desc()).paginate(page=page, per_page=50)
toots = process_toot(toots_) toots = process_toot(toots_)
path=SimpleNamespace() path=SimpleNamespace()
path.path = "index" path.path = "index"
@ -39,7 +39,8 @@ def search():
query = request.args.get('query', "", type=str) query = request.args.get('query', "", type=str)
page = request.args.get('page', 1, type=int) page = request.args.get('page', 1, type=int)
toots_ = Toot.query.order_by(Toot.created_at.desc()).filter(Toot.content.like("%"+query+"%")).paginate(page, per_page=50) toots_ = Toot.query.order_by(Toot.created_at.desc()).filter(Toot.content.like("%"+query+"%")).paginate(
page=page, per_page=50)
toots = process_toot(toots_) toots = process_toot(toots_)
path=SimpleNamespace() path=SimpleNamespace()
# Rule: /serch # Rule: /serch
@ -164,18 +165,21 @@ def register():
@app.route('/archive', methods=['GET', 'POST']) @app.route('/archive', methods=['GET', 'POST'])
def archive(): def archive():
settings = Settings.query.first() settings = Settings.query.first()
if settings == None: if request.method == 'POST':
return redirect(url_for('settings')) archive_match = request.form.getlist("archive_match")
else:
account = settings.account[1:] account = settings.account[1:]
username, domain = account.split("@") username, domain = account.split("@")
url = "https://" + domain url = "https://" + domain
archive_toot(url, archive_match)
archive_toot(url)
flash('存档完成……大概!') flash('存档完成……大概!')
return redirect(url_for('index')) return redirect(url_for('index'))
if settings == None:
return redirect(url_for('settings'))
else:
return render_template('archive.html')
def process_toot(toots_): def process_toot(toots_):
toots = [] toots = []
settings = Settings.query.first() settings = Settings.query.first()