FreakPositivity/freakpos.py

44 lines
1.0 KiB
Python
Raw Normal View History

2022-01-08 16:26:12 -08:00
#!/usr/bin/env python
2022-01-31 12:36:09 -08:00
import sys
2022-01-08 16:26:12 -08:00
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)
2022-01-24 21:33:39 -08:00
message = message.format(label)
# believe me, there isn't already a string method that does this.
# not even .capitalize().
return message[0].upper() + message[1:]
2022-01-08 16:26:12 -08:00
async def main():
config = load_config()
static_data = load_static()
2022-01-31 12:36:09 -08:00
post = gen_post(*static_data)
print(post)
if '--simulate' in sys.argv[1:]:
return
2022-01-08 16:26:12 -08:00
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'
2022-01-31 12:36:09 -08:00
await pl.post(post, visibility=visibility)
2022-01-08 16:26:12 -08:00
if __name__ == '__main__':
anyio.run(main)