feat/add grab all toots context command
This commit is contained in:
parent
51dcceed35
commit
c8d863d86f
2 changed files with 45 additions and 2 deletions
|
@ -2,7 +2,9 @@
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from BDSM import app, db
|
from BDSM import app, db
|
||||||
from BDSM.models import Settings
|
from BDSM.models import Settings, Toot, Other
|
||||||
|
from BDSM.toot import app_login, toot_process
|
||||||
|
from mastodon import MastodonNotFoundError
|
||||||
|
|
||||||
|
|
||||||
@app.cli.command()
|
@app.cli.command()
|
||||||
|
@ -13,3 +15,43 @@ def initdb(drop):
|
||||||
db.drop_all()
|
db.drop_all()
|
||||||
db.create_all()
|
db.create_all()
|
||||||
click.echo('Initialized database.')
|
click.echo('Initialized database.')
|
||||||
|
|
||||||
|
@app.cli.command()
|
||||||
|
def graball():
|
||||||
|
"""Grab all toots context"""
|
||||||
|
settings = Settings.query.first()
|
||||||
|
account = settings.account[1:]
|
||||||
|
username, domain = account.split("@")
|
||||||
|
url = "https://" + domain
|
||||||
|
mastodon, user = app_login(url)
|
||||||
|
acct = mastodon.me().acct
|
||||||
|
|
||||||
|
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):
|
||||||
|
continue
|
||||||
|
#context api excluding itself
|
||||||
|
toots_id.append(i.id)
|
||||||
|
|
||||||
|
while(toots_id != []):
|
||||||
|
toot_id = toots_id.pop(0)
|
||||||
|
|
||||||
|
try:
|
||||||
|
context = mastodon.status_context(toot_id)
|
||||||
|
except MastodonNotFoundError:
|
||||||
|
print('NotFound!')
|
||||||
|
continue
|
||||||
|
|
||||||
|
statuses = []
|
||||||
|
statuses= context['ancestors'] + context['descendants']
|
||||||
|
|
||||||
|
for i in statuses:
|
||||||
|
if i['id'] in toots_id:
|
||||||
|
toots_id.remove(i['id'])
|
||||||
|
|
||||||
|
toot_process(statuses, acct)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
print(len(toots_id))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from types import NoneType
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
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
|
||||||
|
@ -140,7 +141,7 @@ def toot_process(statuses, my_acct, duplicates_counter=0):
|
||||||
|
|
||||||
if not is_reblog:
|
if not is_reblog:
|
||||||
data=Emoji.query.filter_by(shortcode=shortcode, acct=acct).first()
|
data=Emoji.query.filter_by(shortcode=shortcode, acct=acct).first()
|
||||||
if data is None:
|
if data is None or NoneType:
|
||||||
emoji_data = Emoji(shortcode=shortcode,
|
emoji_data = Emoji(shortcode=shortcode,
|
||||||
acct=acct,
|
acct=acct,
|
||||||
url=emoji['url'],
|
url=emoji['url'],
|
||||||
|
|
Loading…
Reference in a new issue