diff --git a/BDSM/templates/archive.html b/BDSM/templates/archive.html new file mode 100644 index 0000000..bb0f9e9 --- /dev/null +++ b/BDSM/templates/archive.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} + +{% block content %} +

存档

+
+
+ 嘟文 + 喜欢 + 书签 +
+
+ 增量备份 +
+
+
+

1. 增量备份是指如果检查到数据库已存在嘟文超过十个就停止存档,即只存最新的。

+

2. 也因为现在嘟文、喜欢、收藏的数据全部存放在一起,所以可能导致增量备份逻辑混乱, + 建议对每一个栏目来一次全量备份(即不勾选增量备份框)。

+

3. 目前没有做网页进度条,请前往终端(控制台)查看进度。

+ +
+
+ +{% endblock %} diff --git a/BDSM/toot.py b/BDSM/toot.py index f4ec3ca..e9ecb69 100644 --- a/BDSM/toot.py +++ b/BDSM/toot.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from mastodon import Mastodon +from tenacity import * from BDSM import db from BDSM.models import Other, Toot, Tag, Media, Emoji, Poll 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)) return duplicates_counter -def archive_toot(url): +# @retry(stop=stop_after_attempt(7)) +def archive_toot(url, archive_match): mastodon, user = app_login(url) acct = mastodon.me().acct @@ -243,13 +245,21 @@ def archive_toot(url): if statuses == None: break - statuses_count = str(mastodon.me().statuses_count) - statuses = mastodon.account_statuses(user["id"], limit=20) - archive(statuses) + skip_duplicates = False + if 'duplicate' in archive_match: + skip_duplicates = True - statuses_count = '???' - statuses = mastodon.favourites() - archive(statuses) + if 'statuses' in archive_match: + statuses_count = str(mastodon.me().statuses_count) + statuses = mastodon.account_statuses(user["id"], limit=20) + archive(statuses, skip_duplicates=skip_duplicates) - statuses = mastodon.bookmarks() - archive(statuses, skip_duplicates=False) + if 'favourites' in archive_match: + statuses_count = '???' + statuses = mastodon.favourites() + archive(statuses, skip_duplicates=skip_duplicates) + + if 'bookmarks' in archive_match: + statuses_count = '???' + statuses = mastodon.bookmarks() + archive(statuses, skip_duplicates=skip_duplicates) diff --git a/BDSM/views.py b/BDSM/views.py index de17d31..ff2b0e3 100644 --- a/BDSM/views.py +++ b/BDSM/views.py @@ -23,7 +23,7 @@ def index(): return redirect(url_for('settings')) else: 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_) path=SimpleNamespace() path.path = "index" @@ -39,7 +39,8 @@ def search(): query = request.args.get('query', "", type=str) 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_) path=SimpleNamespace() # Rule: /serch @@ -164,17 +165,20 @@ def register(): @app.route('/archive', methods=['GET', 'POST']) def archive(): settings = Settings.query.first() - if settings == None: - return redirect(url_for('settings')) - else: + if request.method == 'POST': + archive_match = request.form.getlist("archive_match") account = settings.account[1:] username, domain = account.split("@") url = "https://" + domain + archive_toot(url, archive_match) - archive_toot(url) + flash('存档完成……大概!') + return redirect(url_for('index')) - flash('存档完成……大概!') - return redirect(url_for('index')) + if settings == None: + return redirect(url_for('settings')) + else: + return render_template('archive.html') def process_toot(toots_): toots = []