Browse Source

Limited top posts properly.

master
Trey Del Bonis 2 years ago
parent
commit
7f00aa48d0
1 changed files with 36 additions and 6 deletions
  1. 36
    6
      main.py

+ 36
- 6
main.py View File

@@ -23,7 +23,7 @@ def load_recents():
return []

def save_recents(recents):
with open(os.getenv('MR_RECENTS'), 'w') as f:
with open(os.getenv('MR_RECENTS', 'recents.json'), 'w') as f:
f.write(json.dumps(recents))

def make_masto(config):
@@ -141,10 +141,33 @@ def query_tops(config):
for post in j['data']['children']:
if post['kind'] != 't3':
print('found post of kind', post['kind'])
posts.append(process_post(post))


p = process_post(post)

lt = p['title'].lower()
if any(f in lt for f in config['skip_titles']):
continue

posts.append(p)

return posts

def filter_posts(config, posts, filt):
ok = []
filt = set(filt)
newfilt = set()

for p in posts:
if p['rid'] not in filt:
ok.append(p)
newfilt.add(p['rid'])

if len(ok) > config['top_posts']:
ok = ok[:config['top_posts']]

return ok, list(newfilt)

def just_toot(config, msg):
masto = make_masto(config)
masto.toot(msg)
@@ -152,11 +175,18 @@ def just_toot(config, msg):
def main():
config = load_config()
masto = make_masto(config)
# make_post(masto, {'title': sys.argv[1], 'username': 'nobody', 'rid': 'none', 'attachments': [sys.argv[2]]})

recents = load_recents()

res = query_tops(config)
for r in res:
print('posting', r['rid'], '-', r['title'], '=====', r)
make_post(masto, r)
okps, newrecents = filter_posts(config, res, recents)

for p in okps:
print('posting', p['rid'], '-', p['title'])
make_post(masto, p)

print(newrecents)
save_recents(newrecents)

if __name__ == '__main__':
main()

Loading…
Cancel
Save