fix catastrophic bug from abc7e07677
This commit is contained in:
parent
b251577ffe
commit
e5488ced4d
|
@ -65,6 +65,9 @@ if __name__ == "__main__":
|
|||
print('Running at ' + str(datetime.now() ))
|
||||
print('=======================================')
|
||||
print('')
|
||||
if options.test:
|
||||
print("This is a test run...")
|
||||
print('')
|
||||
with open(config_file) as config:
|
||||
for accounts in yaml.safe_load_all(config):
|
||||
for user in accounts:
|
||||
|
|
|
@ -46,26 +46,12 @@ def schedule(options):
|
|||
except Exception:
|
||||
print('🙁 Scheduling failed.')
|
||||
|
||||
def checkToots(config, options, deleted_count=0, retry_count=0):
|
||||
if options.test:
|
||||
print("This is a test run...")
|
||||
def checkToots(config, options, retry_count=0):
|
||||
|
||||
print("Fetching account details for @" + config['username'] + "@" + config['base_url'] + "...")
|
||||
try:
|
||||
mastodon = Mastodon(
|
||||
access_token=config['access_token'],
|
||||
api_base_url="https://" + config['base_url'],
|
||||
ratelimit_method="wait",
|
||||
)
|
||||
|
||||
cutoff_date = datetime.now(timezone.utc) - timedelta(days=config['days_to_keep'])
|
||||
user_id = mastodon.account_verify_credentials().id
|
||||
account = mastodon.account(user_id)
|
||||
timeline = mastodon.account_statuses(user_id, limit=40)
|
||||
|
||||
print("Checking " + str(account.statuses_count) + " toots...")
|
||||
|
||||
def checkBatch(timeline, deleted_count=0):
|
||||
for toot in timeline:
|
||||
|
||||
toot_tags = set()
|
||||
for tag in toot.tags:
|
||||
toot_tags.add(tag.name)
|
||||
|
@ -140,7 +126,7 @@ def checkToots(config, options, deleted_count=0, retry_count=0):
|
|||
max_id = timeline[-1:][0].id
|
||||
next_batch = mastodon.account_statuses(user_id, limit=40, max_id=max_id)
|
||||
if len(next_batch) > 0:
|
||||
checkToots(next_batch, deleted_count)
|
||||
checkBatch(next_batch, deleted_count)
|
||||
else:
|
||||
if options.test:
|
||||
print(
|
||||
|
@ -159,6 +145,21 @@ def checkToots(config, options, deleted_count=0, retry_count=0):
|
|||
except IndexError:
|
||||
print("No toots found!")
|
||||
|
||||
mastodon = Mastodon(
|
||||
access_token=config['access_token'],
|
||||
api_base_url="https://" + config['base_url'],
|
||||
ratelimit_method="wait",
|
||||
)
|
||||
|
||||
cutoff_date = datetime.now(timezone.utc) - timedelta(days=config['days_to_keep'])
|
||||
user_id = mastodon.account_verify_credentials().id
|
||||
account = mastodon.account(user_id)
|
||||
timeline = mastodon.account_statuses(user_id, limit=40)
|
||||
|
||||
print("Checking " + str(account.statuses_count) + " toots...")
|
||||
|
||||
checkBatch(timeline)
|
||||
|
||||
except MastodonAPIError:
|
||||
print('User and/or access token does not exist or has been deleted')
|
||||
except MastodonNetworkError:
|
||||
|
@ -168,6 +169,6 @@ def checkToots(config, options, deleted_count=0, retry_count=0):
|
|||
time.sleep(60)
|
||||
retry_count += 1
|
||||
print( 'Attempt ' + str(retry_count + 1) )
|
||||
checkToots(config, options, 0, retry_count)
|
||||
checkToots(config, options, retry_count)
|
||||
else:
|
||||
print('Gave up waiting for network')
|
Loading…
Reference in New Issue