commit ad9f348da32abf43f5ceb487dc759adbf74707fb Author: alban Date: Sat Jun 15 20:31:53 2019 +0200 [init] diff --git a/reboostTag.py b/reboostTag.py new file mode 100755 index 0000000..c48de58 --- /dev/null +++ b/reboostTag.py @@ -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() diff --git a/toot b/toot new file mode 120000 index 0000000..0e47d0d --- /dev/null +++ b/toot @@ -0,0 +1 @@ +toot.src/toot/ \ No newline at end of file diff --git a/toot-cli b/toot-cli new file mode 100755 index 0000000..afa2fd5 --- /dev/null +++ b/toot-cli @@ -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()) diff --git a/toot.src b/toot.src new file mode 160000 index 0000000..9dfdaaa --- /dev/null +++ b/toot.src @@ -0,0 +1 @@ +Subproject commit 9dfdaaa28016444e6a862a7ff6ee00ed79d4da3c