From a00a1b9ca37c8bc3a72107db168ceb14307abedb Mon Sep 17 00:00:00 2001 From: d0c Date: Sun, 6 Dec 2020 23:36:01 +0100 Subject: [PATCH] first commit --- zeroToots.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 zeroToots.py diff --git a/zeroToots.py b/zeroToots.py new file mode 100644 index 0000000..b514525 --- /dev/null +++ b/zeroToots.py @@ -0,0 +1,63 @@ +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() \ No newline at end of file