mastodon-py-tools/zeroToots.py

63 lines
1.9 KiB
Python
Raw Permalink Normal View History

2020-12-06 23:36:01 +01:00
import json
import datetime
import time
from json import JSONEncoder
from credentials import user, password
# subclass JSONEncoder
class DateTimeEncoder(JSONEncoder):
#Override the default method
def default(self, obj):
if isinstance(obj, (datetime.date, datetime.datetime)):
return obj.isoformat()
#employeeJSONData = json.dumps(employee, indent=4, cls=DateTimeEncoder)
from mastodon import *
Mastodon.create_app(
'0toots',
api_base_url = 'https://mastodon.bida.im',
to_file = 'clientcred.secret'
)
mastodon = Mastodon(
client_id = 'clientcred.secret',
api_base_url = 'https://mastodon.bida.im'
)
mastodon.log_in(
user,
password,
to_file = 'clientcred.secret'
)
def zeroToots():
for i in range(237265, 1, -1):
try:
account=mastodon.account(i)
if account['id'] != None and not "@" in account['acct']:
if account['statuses_count'] == 0:
userJson = {
'id' : account['id'],
'acct' : account['acct'],
'username' : account['username'],
'created_at' : account['created_at'],
'followers_count' : account['followers_count'],
'following_count' : account['following_count'],
}
with open("user.0toot.txt", "a") as userFile:
userFile.write((str(userJson)+ ", \n"))
print(account['id'])
time.sleep(2)
except NameError as e:
print("Oops!", e.__class__, "occurred.")
pass
except MastodonNotFoundError as e:
print("Oops!", e.__class__, "occurred.")
pass
except MastodonAPIError as e:
print("Oops!", e.__class__, "occurred.")
pass
zeroToots()