refactor/remove Other model
This commit is contained in:
parent
e079552833
commit
fbfd8a1505
4 changed files with 15 additions and 59 deletions
|
@ -2,7 +2,7 @@
|
|||
import click
|
||||
|
||||
from BDSM import app, db
|
||||
from BDSM.models import Settings, Toot, Other
|
||||
from BDSM.models import Settings, Toot
|
||||
from BDSM.toot import app_login, toot_process
|
||||
from mastodon import MastodonNotFoundError
|
||||
|
||||
|
@ -19,7 +19,7 @@ def initdb(drop):
|
|||
@app.cli.command()
|
||||
def analysis():
|
||||
"""Analysis current Year"""
|
||||
from BDSM.models import Toot, Other
|
||||
from BDSM.models import Toot
|
||||
from sqlalchemy.sql import extract
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy import desc
|
||||
|
@ -42,8 +42,8 @@ def analysis():
|
|||
)
|
||||
|
||||
print("2022 年互动最多帐号排名" +
|
||||
str(db.session.query(Other.acct.label('count'),func.count('count')
|
||||
).filter(extract('year', Other.created_at) == 2022
|
||||
str(db.session.query(Toot.acct.label('count'),func.count('count')
|
||||
).filter(extract('year', Toot.created_at) == 2022
|
||||
).group_by('count'
|
||||
).order_by(desc(func.count('count'))
|
||||
).all()[:3])
|
||||
|
@ -201,8 +201,7 @@ def graball():
|
|||
toots = Toot.query.filter(Toot.in_reply_to_id.isnot(None)).all()
|
||||
toots_id = []
|
||||
for i in toots:
|
||||
if (Toot.query.get(i.in_reply_to_id) != None
|
||||
or Other.query.get(i.in_reply_to_id) != None):
|
||||
if (Toot.query.get(i.in_reply_to_id) != None):
|
||||
continue
|
||||
#context api excluding itself
|
||||
toots_id.append(i.id)
|
||||
|
|
|
@ -26,29 +26,6 @@ class Toot(db.Model):
|
|||
favourites_count = db.Column(db.Integer)
|
||||
language = db.Column(db.Text)
|
||||
|
||||
class Other(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
acct = db.Column(db.Text)
|
||||
url = db.Column(db.Text)
|
||||
created_at = db.Column(db.DateTime)
|
||||
edited_at = db.Column(db.DateTime)
|
||||
in_reply_to_id = db.Column(db.Integer)
|
||||
in_reply_to_account_id = db.Column(db.Integer)
|
||||
content = db.Column(db.Text)
|
||||
media_list = db.Column(db.Text)
|
||||
emoji_list = db.Column(db.Text)
|
||||
spoiler_text = db.Column(db.Text)
|
||||
poll_id = db.Column(db.Integer)
|
||||
visibility = db.Column(db.Text)
|
||||
reblogged = db.Column(db.Boolean)
|
||||
favourited = db.Column(db.Boolean)
|
||||
bookmarked = db.Column(db.Boolean)
|
||||
sensitive = db.Column(db.Boolean)
|
||||
replies_count = db.Column(db.Integer)
|
||||
reblogs_count = db.Column(db.Integer)
|
||||
favourites_count = db.Column(db.Integer)
|
||||
language = db.Column(db.Text)
|
||||
|
||||
class Tag(db.Model):
|
||||
__table_args__ = {'sqlite_autoincrement': True}
|
||||
tag_id = db.Column(db.Integer, primary_key=True)
|
||||
|
|
15
BDSM/toot.py
15
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, Settings
|
||||
from BDSM.models import Toot, Tag, Media, Emoji, Poll, Settings
|
||||
import sys
|
||||
import dateutil.parser
|
||||
|
||||
|
@ -53,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
|
||||
|
@ -79,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']
|
||||
|
||||
|
@ -182,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
|
||||
|
@ -209,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)
|
||||
|
|
|
@ -6,7 +6,7 @@ import json
|
|||
from flask import render_template, request, url_for, redirect, flash, abort
|
||||
from flask_sqlalchemy import Pagination
|
||||
from BDSM import app, db
|
||||
from BDSM.models import Media, Poll, Settings, Toot, Emoji, Other
|
||||
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
|
||||
|
@ -70,8 +70,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:
|
||||
|
@ -83,9 +81,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)
|
||||
|
@ -96,9 +92,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)
|
||||
|
@ -213,17 +207,12 @@ 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
|
||||
toot = Toot.query.get(toot.reblog_id)
|
||||
toot = SimpleNamespace(**toot.__dict__)
|
||||
toot.is_reblog = True
|
||||
else:
|
||||
toot.is_myself = False
|
||||
|
||||
|
|
Loading…
Reference in a new issue