ui/archive page
This commit is contained in:
parent
57cadb2e11
commit
603bbff5ae
3 changed files with 55 additions and 17 deletions
24
BDSM/templates/archive.html
Normal file
24
BDSM/templates/archive.html
Normal 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 %}
|
28
BDSM/toot.py
28
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)
|
||||
|
|
|
@ -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 = []
|
||||
|
|
Loading…
Reference in a new issue