commit a013f894242c342490f0d17520e4f979adbf23dd Author: Castro0o Date: Sun Feb 3 19:22:20 2019 +0100 simple scripts for Mastodon API diff --git a/all_accounts.py b/all_accounts.py new file mode 100644 index 0000000..92a7d70 --- /dev/null +++ b/all_accounts.py @@ -0,0 +1,14 @@ +from time import sleep +from mastodon import Mastodon + +with open('token.txt','r') as token: + mastodon = Mastodon(access_token=token.read(),api_base_url="https://post.lurk.org/") + +# print all accounts in post.lurk.org/ + +i = 1 +while True: + account = mastodon.account(i) + print(account, account['display_name'], "\n") + i = i +1 + sleep(1) diff --git a/search.py b/search.py new file mode 100644 index 0000000..020bb6b --- /dev/null +++ b/search.py @@ -0,0 +1,19 @@ +from mastodon import Mastodon + +with open('token.txt','r') as token: # getting token from toke.txt file + mastodon = Mastodon(access_token=token.read(),api_base_url="https://post.lurk.org/") + + # search(q, resolve=False) method of mastodon.Mastodon.Mastodon instance + # Fetch matching hashtags, accounts and statuses. Will search federated + # instances if resolve is True. Full-text search is only enabled if + # the instance supports it, and is restricted to statuses the logged-in + # user wrote or was mentioned in. + +# search +searchresult = mastodon.search("cat") + +print(searchresult.keys()) #.search returns a dictionary w/ they keys ['accounts', 'hashtags', 'statuses'] + +for cat_account in searchresult['accounts']: # loop through all accounts + print(cat_account) + print(cat_account['username'], cat_account['url']) diff --git a/toot.py b/toot.py new file mode 100644 index 0000000..73af10c --- /dev/null +++ b/toot.py @@ -0,0 +1,12 @@ +from mastodon import Mastodon + +with open('token.txt','r') as token: + mastodon = Mastodon(access_token=token.read(),api_base_url="https://post.lurk.org/") + +mycreds = mastodon.account_verify_credentials() #dictionary with my user info +print(mycreds) +myname = mycreds['display_name'] + +toot_text = '{} whishes you a good hello world'.format(myname) +mastodon.toot(toot_text) +print(toot_text) \ No newline at end of file