ljfbot/lgfbot.py

59 lines
1.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2022-11-23 00:55:53 -08:00
import random
from getpass import getpass
2022-11-23 00:55:53 -08:00
from mastodon import Mastodon
import os
if not os.path.exists('./.lgfbot/'):
2022-11-23 00:55:53 -08:00
os.mkdir('./.lgfbot')
if not os.path.exists('./.lgfbot/lgf_client.secret'):
2022-11-23 00:55:53 -08:00
instance = input('Please enter your instance: ')
if instance[:4] != 'http':
2022-11-23 00:55:53 -08:00
instance = 'https://' + instance
Mastodon.create_app('Hourly lgf', api_base_url = instance, to_file = './.lgfbot/lgf_client.secret')
mastodon = Mastodon(
client_id = './.lgfbot/lgf_client.secret',
)
if not os.path.exists('./.lgfbot/lgf_user.secret'):
2022-11-23 00:55:53 -08:00
print('To post, lgfbot needs to generate an access token')
username = input('Enter your username: ')
password = getpass('Enter your password: ')
2022-11-23 00:55:53 -08:00
mastodon.log_in(username=username, password=password, scopes=['write:statuses'], to_file='./.lgfbot/lgf_user.secret')
mastodon = Mastodon(
access_token = './.lgfbot/lgf_user.secret'
)
with open('adjectives.txt') as f:
adjectives = list(map(str.rstrip, f))
with open('verbs.txt') as f:
verbs = list(map(str.rstrip, f))
postform = random.choice((
'{adjective} {gender} who {verb}',
'{adjective} {gender}',
'{gender} who {verb}',
))
gender = random.choice(('lgf', 'lbf', 'elf'))
2022-11-23 00:55:53 -08:00
verb = random.choice(verbs)
if verb[-2:] == 'ed' and verb[-3] not in {'a', 'e', 'i', 'o', 'u'}:
verb = verb[:-2]
if verb[-1] in {'a', 'i', 'o', 'u'}:
2022-11-23 00:55:53 -08:00
verb = verb + 'es'
elif verb[-1] in {'s', 'x'} or verb[-2] in {'s', 'x'} or verb[-2:] == 'ch':
2022-11-23 00:55:53 -08:00
verb = verb + 'es'
elif verb[-1] == 'y' and verb[-2] not in {'a', 'e', 'i', 'o', 'u'}:
2022-11-23 00:55:53 -08:00
verb = verb[:-1] + 'ies'
else:
verb = verb + 's'
adjective = random.choice(adjectives)
content = postform.format(adjective=adjective, gender=gender, verb=verb)
2022-11-23 00:55:53 -08:00
print(content)
mastodon.status_post(content, visibility='unlisted')