This commit is contained in:
alban 2019-06-15 20:31:53 +02:00
commit ad9f348da3
4 changed files with 92 additions and 0 deletions

79
reboostTag.py Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import sys
import io
import json
from toot.console import main
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-c", "--count", type=int, help="How many toots to read")
parser.add_argument("-t", "--tag", type=str, help="Which tag to follow")
args = parser.parse_args()
tag = args.tag
count = args.count
toot_exec = "./toot-cli"
# Handle the last seen file
last_seen_file = "/tmp/reboost.{}.lastseen".format( tag )
# Touch last seen file if not exists
if( os.path.isfile( last_seen_file ) ):
wrapper = open(last_seen_file, 'r',encoding="utf-8")
last_seen = next(wrapper)
else:
open(last_seen_file, 'w').close()
last_seen = 0
# Build a fake list of args to run the toot main() function on
sim_args = [sys.argv[0], 'timeline', '-t', tag, '-c', str(count), '--json', '-1']
sys.argv = sim_args
# redirect sys.stdout to a buffer
stdout = sys.stdout
sys.stdout = io.StringIO()
# Call the toot library to get a list of toots
main()
# get output and restore sys.stdout
output = sys.stdout.getvalue()
sys.stdout = stdout
# Convert the received JSON to a list
itemList = json.loads( output)
# Contains the first item id in the list, to be stored
most_recent = None
print ('Running with last_seen being: {}'.format(last_seen))
# Loop through items
for item in itemList:
# Set the most recent id
if None == most_recent :
most_recent = item['id']
# if never seen, and therefore recent, reboost
if( last_seen != item['id'] ):
print("Reboosting item#{}".format(item['id']) )
# Build a fake list of args to run the toot main() function on
sim_args = [sys.argv[0], 'reblog', str(item['id'])]
sys.argv = sim_args
main()
# We've seen you already that toot, break
else:
break;
if( last_seen != most_recent) :
print( "Saving most_recent as last_seen: {}".format(most_recent))
handle = open(last_seen_file, 'w')
handle.write(most_recent)
handle.close()

1
toot Symbolic link
View File

@ -0,0 +1 @@
toot.src/toot/

11
toot-cli Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from toot.console import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())

1
toot.src Submodule

@ -0,0 +1 @@
Subproject commit 9dfdaaa28016444e6a862a7ff6ee00ed79d4da3c