from mastodon import Mastodon
import json
import os

FIRST_RUN=False
DEBUG=False
INSTANCE='https://mastodon.host'

# Register app - only once!
if FIRST_RUN or not os.path.exists('.pytooter_clientcred.txt'):
	Mastodon.create_app(
	     'autofollower',
	      to_file = '.pytooter_clientcred.txt',
	      api_base_url=INSTANCE
	)
	username=raw_input('What is the username ?')
	password=raw_input('What is the password ?')

	mastodon = Mastodon(client_id = '.pytooter_clientcred.txt',api_base_url=INSTANCE)
	mastodon.log_in(
	    username,
	    password,
	    to_file = '.pytooter_usercred.txt'
	)

## Create actual instance
mastodon = Mastodon(
    client_id = '.pytooter_clientcred.txt',
    access_token = '.pytooter_usercred.txt',
    api_base_url=INSTANCE
)


if os.path.exists('.Autofollow.state.json'):
	with open('.Autofollow.state.json','r') as file:
		runparams=json.load(file)
else:
	runparams={'since_id':0}

my_id = mastodon.account_search('@followbot')[0]['id']

if DEBUG:
    print('Found my id %i' % my_id)

my_followed = mastodon.account_following(my_id)
my_followed_list=[my_id]
total_followed=0
for user in my_followed:
    my_followed_list.append(user['id'])
    total_followed+=1

if DEBUG:
    print('I am currently already following %i persons' % total_followed)

toots = mastodon.timeline_public(since_id=runparams['since_id'])
new_followed=0
for toot in toots:
    user_id = toot['account']['id']
    if DEBUG:
        print('[%i] new Toot from %i' % (toot['id'],user_id))
    runparams['since_id'] = toot['id']
    if user_id not in my_followed_list:
        if DEBUG:
            print('Trying to follow %i' % user_id)
        new_followed+=1
        mastodon.account_follow(user_id)
        my_followed_list.append(user_id)


with open('.Autofollow.state.json','w') as file:
        json.dump(runparams,file)

if new_followed > 0:
    mastodon.toot('I am now following %i new users, for a total of %i.' % (new_followed,total_followed+new_followed))

@@ -911,16 +911,114 @@
 id':0%7D%0A%0A
+if 'runcount' not in runparams:%0A    runparams%5B'runcount'%5D = 1%0Aelse:%0A    runparams%5B'runcount'%5D+=1%0A%0A
 my_id = 
@@ -1290,16 +1290,96 @@
 wed+=1%0A%0A
+if 'list_seen' not in runparams:%0A    runparams%5B'list_seen'%5D = my_followed_list%0A%0A
 if DEBUG
@@ -1518,16 +1518,25 @@
 nce_id'%5D
+,limit=40
 )%0Anew_fo
@@ -1752,16 +1752,57 @@
 wed_list
+ or user_id not in runparams%5B'list_seen'%5D
 :%0A      
@@ -1974,112 +1974,105 @@
 id)%0A
-%0A%0Awith open('.Autofollow.state.json','w') as file:%0A        json.dump(runparams,file)%0A%0Aif new_followed %3E 
+        runparams%5B'list_seen'%5D.append(user_id)%0A%0Aif new_followed %3E 0 and runparams%5B'runcount'%5D %3E 1
 0:%0A 
@@ -2115,81 +2115,259 @@
  %25i 
-new 
 users
-, for a total of %25i.' %25 (new_followed,total_followed+new_followed)
+ out of the %25i I have seen, boost some toots from others so I add them :)' %25 (total_followed+new_followed,len(runparams%5B'list_seen'%5D)))%0A    runparams%5B'runcount'%5D = 1%0A%0Awith open('.Autofollow.state.json','w') as file:%0A        json.dump(runparams,file
 )%0A

Implement #1 plus a few other things