#!/usr/bin/env python import random from getpass import getpass from mastodon import Mastodon import os if not os.path.exists('./.lgfbot/'): os.mkdir('./.lgfbot') if not os.path.exists('./.lgfbot/lgf_client.secret'): instance = input('Please enter your instance: ') if instance[:4] != 'http': 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'): print('To post, lgfbot needs to generate an access token') username = input('Enter your username: ') password = getpass('Enter your password: ') 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')) 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'}: verb = verb + 'es' elif verb[-1] in {'s', 'x'} or verb[-2] in {'s', 'x'} or verb[-2:] == 'ch': verb = verb + 'es' elif verb[-1] == 'y' and verb[-2] not in {'a', 'e', 'i', 'o', 'u'}: verb = verb[:-1] + 'ies' else: verb = verb + 's' adjective = random.choice(adjectives) content = postform.format(adjective=adjective, gender=gender, verb=verb) print(content) mastodon.status_post(content, visibility='unlisted')