Browse Source

[init]

master
alban 1 year ago
commit
ad9f348da3
4 changed files with 92 additions and 0 deletions
  1. 79
    0
      reboostTag.py
  2. 1
    0
      toot
  3. 11
    0
      toot-cli
  4. 1
    0
      toot.src

+ 79
- 0
reboostTag.py View File

@@ -0,0 +1,79 @@
1
+#!/usr/bin/python3
2
+# -*- coding: utf-8 -*-
3
+
4
+import os
5
+import sys
6
+import io
7
+import json
8
+from toot.console import main
9
+
10
+from argparse import ArgumentParser
11
+parser = ArgumentParser()
12
+parser.add_argument("-c", "--count", type=int, help="How many toots to read")
13
+parser.add_argument("-t", "--tag", type=str, help="Which tag to follow")
14
+args = parser.parse_args()
15
+tag = args.tag
16
+count = args.count
17
+toot_exec = "./toot-cli"
18
+
19
+# Handle the last seen file
20
+last_seen_file = "/tmp/reboost.{}.lastseen".format( tag )
21
+
22
+# Touch last seen file if not exists
23
+if( os.path.isfile( last_seen_file ) ):
24
+  wrapper = open(last_seen_file, 'r',encoding="utf-8")
25
+  last_seen = next(wrapper)
26
+else:
27
+  open(last_seen_file, 'w').close()
28
+  last_seen = 0
29
+
30
+# Build a fake list of args to run the toot main() function on
31
+sim_args = [sys.argv[0],  'timeline',  '-t',  tag,  '-c',  str(count),  '--json',  '-1']
32
+sys.argv = sim_args
33
+
34
+# redirect sys.stdout to a buffer
35
+stdout = sys.stdout
36
+sys.stdout = io.StringIO()
37
+
38
+# Call the toot library to get a list of toots
39
+main()
40
+
41
+# get output and restore sys.stdout
42
+output = sys.stdout.getvalue()
43
+sys.stdout = stdout
44
+
45
+# Convert the received JSON to a list
46
+itemList = json.loads( output)
47
+
48
+# Contains the first item id in the list, to be stored
49
+most_recent = None
50
+
51
+print ('Running with last_seen being: {}'.format(last_seen))
52
+
53
+# Loop through items
54
+for item in itemList:
55
+
56
+  # Set the most recent id
57
+  if None == most_recent :
58
+    most_recent = item['id']
59
+
60
+  # if never seen, and therefore recent, reboost
61
+  if( last_seen != item['id'] ):
62
+
63
+    print("Reboosting item#{}".format(item['id']) )
64
+
65
+    # Build a fake list of args to run the toot main() function on
66
+    sim_args = [sys.argv[0],  'reblog',  str(item['id'])]
67
+    sys.argv = sim_args
68
+    main()
69
+
70
+  # We've seen you already that toot, break
71
+  else:
72
+    break;
73
+
74
+if( last_seen != most_recent) :
75
+
76
+  print( "Saving most_recent as last_seen: {}".format(most_recent))
77
+  handle = open(last_seen_file, 'w')
78
+  handle.write(most_recent)
79
+  handle.close()

+ 1
- 0
toot View File

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

+ 11
- 0
toot-cli View File

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

+ 1
- 0
toot.src

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

Loading…
Cancel
Save