#!/usr/bin/env python import anyio import qtoml import random import pleroma def load_config(): with open('config.toml') as f: return qtoml.load(f) def load_static(): with open('messages2.txt') as f: messages = list(map(str.rstrip, f)) with open('labels.txt') as f: labels = list(map(str.rstrip, f)) return messages, labels def gen_post(messages, labels): message = random.choice(messages) label = random.choice(labels) if message.startswith('{}'): # believe me, there isn't already a string method that does this. # not even .capitalize(). label = label[0].upper() + label[1:] return message.format(label) async def main(): config = load_config() static_data = load_static() async with pleroma.Pleroma(api_base_url=config['site'], access_token=config['access_token']) as pl: visibility = 'direct' if config.get('test_mode', False) else 'unlisted' await pl.post(gen_post(*static_data), visibility=visibility) if __name__ == '__main__': anyio.run(main)