simple scripts for Mastodon API
commit
a013f89424
@ -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)
|
@ -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'])
|
@ -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)
|
Loading…
Reference in New Issue