@@ -24,9 +23,9 @@
{% else %}
diff --git a/BDSM/toot.py b/BDSM/toot.py
index c0efba5..4e0e49e 100644
--- a/BDSM/toot.py
+++ b/BDSM/toot.py
@@ -3,7 +3,7 @@
from mastodon import Mastodon
from tenacity import *
from BDSM import db
-from BDSM.models import Other, Toot, Tag, Media, Emoji, Poll
+from BDSM.models import Toot, Tag, Media, Emoji, Poll, Settings
import sys
import dateutil.parser
@@ -40,8 +40,9 @@ def app_login(url):
return mastodon, user
def get_context(url, toot_id):
- mastodon, user = app_login(url)
- acct = mastodon.me().acct
+ mastodon, _ = app_login(url)
+ settings = Settings.query.first()
+ acct = settings.account
context = mastodon.status_context(toot_id)
statuses = []
statuses= context['ancestors'] + context['descendants']
@@ -52,7 +53,6 @@ def get_context(url, toot_id):
def toot_process(statuses, my_acct, duplicates_counter=0):
for status in statuses:
is_reblog = False
- is_myself = False
if status['reblog'] != None:
if my_acct == status['reblog']['account']['acct']:
reblog_myself = True
@@ -78,11 +78,6 @@ def toot_process(statuses, my_acct, duplicates_counter=0):
id = status['id']
acct = status['account']['acct']
- if my_acct == acct:
- is_myself = True
- else:
- is_myself = False
-
url = status['url']
created_at = status['created_at']
@@ -181,10 +176,7 @@ def toot_process(statuses, my_acct, duplicates_counter=0):
favourites_count = status['favourites_count']
language = status['language']
- if is_reblog or not is_myself:
- table = Other()
- else:
- table = Toot()
+ table = Toot()
table.id=id
table.acct = acct
@@ -208,7 +200,7 @@ def toot_process(statuses, my_acct, duplicates_counter=0):
table.favourites_count=favourites_count
table.language=language
- if Toot.query.get(id) != None or Other.query.get(id) != None:
+ if Toot.query.get(id) != None:
duplicates_counter += 1
db.session.merge(table)
diff --git a/BDSM/views.py b/BDSM/views.py
index d0a9570..1402035 100644
--- a/BDSM/views.py
+++ b/BDSM/views.py
@@ -5,9 +5,10 @@ import json
from flask import render_template, request, url_for, redirect, flash, abort
from flask_sqlalchemy import Pagination
+from sqlalchemy import or_
from BDSM import app, db
-from BDSM.models import Media, Poll, Settings, Toot, Emoji, Other
-from BDSM.toot import app_register, archive_toot, get_context
+from BDSM.models import Media, Poll, Settings, Toot, Emoji
+from BDSM.toot import app_login, app_register, archive_toot, get_context
from mastodon import Mastodon
from types import SimpleNamespace
from datetime import timezone
@@ -24,7 +25,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=page, per_page=50)
+ toots_ = Toot.query.order_by(Toot.created_at.desc()).filter(or_(Toot.acct==settings.account, Toot.reblog_id!=None)).paginate(page=page, per_page=50)
toots = process_toot(toots_)
path=SimpleNamespace()
path.path = "index"
@@ -32,6 +33,21 @@ 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()
+ if settings == None:
+ 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=page, per_page=50)
+ toots = process_toot(toots_)
+ path=SimpleNamespace()
+ path.path = "favourited"
+ path.args = {}
+
+ return render_template('view.html', toots=toots, pagination=toots_, path=path)
+
@app.route('/search', methods=['GET', 'POST'])
def search():
if request.method == 'POST':
@@ -55,8 +71,6 @@ def search():
def context(toot_id):
def get_reply(reply_id):
toots = Toot.query.order_by(Toot.created_at.desc()).filter_by(in_reply_to_id=reply_id).all()
- other_toots = Other.query.order_by(Other.created_at.desc()).filter_by(in_reply_to_id=reply_id).all()
- toots = process_toot(toots) + process_toot(other_toots)
for i in toots:
if i.in_reply_to_id != None:
@@ -68,9 +82,7 @@ def context(toot_id):
toot_ = Toot.query.get(toot_id)
if toot_ == None:
- toot_ = Other.query.get(toot_id)
- if toot_ == None:
- abort(404)
+ abort(404)
toots.append(toot_)
toots = process_toot(toots)
@@ -81,9 +93,7 @@ def context(toot_id):
toot = []
toot_ = Toot.query.get(toots[0].in_reply_to_id)
if toot_ == None:
- toot_ = Other.query.get(toots[0].in_reply_to_id)
- if toot_ == None:
- break
+ break
toot.append(toot_)
toot = process_toot(toot)
@@ -95,8 +105,7 @@ def context(toot_id):
@app.route('/grab/', methods=['GET', 'POST'])
def grab(toot_id):
settings = Settings.query.first()
- account = settings.account[1:]
- username, domain = account.split("@")
+ domain = settings.domain
url = "https://" + domain
get_context(url, toot_id)
@@ -106,20 +115,18 @@ def grab(toot_id):
@app.route('/settings', methods=['GET', 'POST'])
def settings():
if request.method == 'POST':
- account = request.form['account']
timezone = request.form['timezone']
-
- if not account or len(account) > 30:
- flash('无效输入')
- return redirect(url_for('settings'))
-
settings = Settings.query.first()
-
if settings == None:
- settings = Settings(account=account, timezone=timezone)
+ domain = request.form['domain']
+
+ if not domain or len(domain) > 50:
+ flash('无效输入')
+ return redirect(url_for('settings'))
+
+ settings = Settings(domain=domain, timezone=timezone)
db.session.add(settings)
else:
- settings.account = account
settings.timezone = timezone
db.session.commit()
@@ -137,13 +144,17 @@ def settings():
def register():
settings = Settings.query.first()
if settings == None:
- flash('请先输入用户名!')
+ flash('请先输入站点地址!')
return redirect(url_for('settings'))
else:
- account = settings.account[1:]
- username, domain = account.split("@")
+ domain = settings.domain
url = "https://" + domain
+ mastodon, _ = app_login(url)
+ account = mastodon.me().acct
+ settings.account = account
+ db.session.commit()
+
if request.method == 'POST':
token = request.form['token'].rstrip()
mastodon = Mastodon(client_id='pyBDSM_clientcred.secret', api_base_url=url)
@@ -168,8 +179,7 @@ def archive():
settings = Settings.query.first()
if request.method == 'POST':
archive_match = request.form.getlist("archive_match")
- account = settings.account[1:]
- username, domain = account.split("@")
+ domain = settings.domain
url = "https://" + domain
archive_toot(url, archive_match)
@@ -196,20 +206,16 @@ def process_toot(toots_):
toot.created_at = toot.created_at.replace(tzinfo=timezone.utc)
toot.created_at = toot.created_at.astimezone(user_timezone).strftime(fmt)
- if hasattr(toot, 'reblog_id'):
+ if toot.acct == settings.account:
toot.is_myself = True
- if toot.reblog_id != None:
- if toot.reblog_myself:
- toot = Toot.query.get(toot.reblog_id)
- toot = SimpleNamespace(**toot.__dict__)
- toot.is_reblog = True
- else:
- toot = Other.query.get(toot.reblog_id)
- toot = SimpleNamespace(**toot.__dict__)
- toot.is_reblog = True
else:
toot.is_myself = False
+ if toot.reblog_id != None:
+ toot = Toot.query.get(toot.reblog_id)
+ toot = SimpleNamespace(**toot.__dict__)
+ toot.is_reblog = True
+
if toot.media_list != "":
toot.medias = []
#media_list "1111,2222,333,"