Compare commits

..

No commits in common. "trunk" and "trunk" have entirely different histories.
trunk ... trunk

7 changed files with 1137 additions and 1092 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
config.json .creds/

View File

@ -1,4 +0,0 @@
{
access_token: "...",
site: "https://freak.university",
}

View File

@ -1,13 +0,0 @@
def conjugate(verb):
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] != 'e' and (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'
return verb

96
lgfbot.py Normal file
View File

@ -0,0 +1,96 @@
#!/usr/bin/env python
import random
import requests
import json
from getpass import getpass
import os
from urllib.parse import urlencode
import argparse
import time
parser = argparse.ArgumentParser()
parser.add_argument('-l', '--loop',
action='store',
type=float,
help='Loop command every x hours',
default=None,
dest='loop'
)
args = parser.parse_args()
loop = args.loop
#Ensure Credentials
parent = os.path.dirname(os.path.realpath(__file__))
try:
os.mkdir(os.path.join(parent, '.creds'))
except FileExistsError:
pass
#Create app
try:
with open(os.path.join(parent, '.creds', 'client.secret'), "x") as clientcreds:
instance = input('Please enter your instance: ')
if not instance[:4] == 'http':
instance = 'https://' + instance
response = requests.post(instance + '/api/v1/apps', data={'client_name':'Hourly lgf','scopes':'write:statuses', 'redirect_uris':'urn:ietf:wg:oauth:2.0:oob'})
response = response.json()
print(response)
clientcreds.write(response['client_id'] + "\n")
clientcreds.write(response['client_secret'] + "\n")
clientcreds.write(instance + "\n")
except FileExistsError:
pass
#Fetch information from app credential file
with open(os.path.join(parent, '.creds', 'client.secret'), "r") as clientcreds:
lines = clientcreds.read().split('\n')
client_id = lines[0]
client_secret = lines[1]
instance = lines[2]
#Log in to bot account
try:
with open(os.path.join(parent, '.creds', 'user.secret'), "x") as usercreds:
print(instance + '/oauth/authorize?', urlencode({'response_type':'code', 'client_id':client_id, 'redirect_uri':'urn:ietf:wg:oauth:2.0:oob', 'scope':'write:statuses'}))
code = input("To generate a token to access your account, lgfbot needs an authorization code. Please authorize using the link above and enter the code it provides you \nCode: ")
response = requests.post(instance + '/oauth/token', data={'grant_type':'authorization_code', 'code':code, 'client_id':client_id, 'client_secret':client_secret, 'redirect_uri':'urn:ietf:wg:oauth:2.0:oob', 'scope':'write:statuses'})
usercreds.write(response.json()['access_token'])
except FileExistsError:
pass
#Fetch information from user credential file
with open(os.path.join(parent, '.creds', 'user.secret'), "r") as usercreds:
lines = usercreds.read().split('\n')
token = lines[0]
session = requests.Session()
session.headers.update({"Authorization" : "Bearer " + token})
with open('adjectives.txt') as f:
adjectives = list(map(str.rstrip, f))
with open('verbs.txt') as f:
verbs = list(map(str.rstrip, f))
formats = (
'{adjective} {gender} who {verb}',
'{adjective} {gender}',
'{gender} who {verb}',
)
genders = ('lgf', 'lbf', 'elf')
while True:
postform = random.choice(formats)
gender = random.choice(genders)
verb = random.choice(verbs)
adjective = random.choice(adjectives)
content = postform.format(adjective=adjective, gender=gender, verb=verb)
print(content)
session.post(instance + '/api/v1/statuses', data={'status':content, 'visibility':'unlisted'})
if loop:
time.sleep(loop * 3600)
else:
break

View File

@ -1,32 +0,0 @@
#!/usr/bin/env python
import random
from conjugate import conjugate
from mastodon import Mastodon
import json5 as json
with open('config.json') as f:
config = json.load(f)
mastodon = Mastodon(
access_token=config['access_token'],
api_base_url=config['site'],
)
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', 'lef'))
verb = conjugate(random.choice(verbs))
adjective = random.choice(adjectives)
content = postform.format(adjective=adjective, gender=gender, verb=verb)
print(content)
mastodon.status_post(content, visibility='unlisted')

View File

@ -1,2 +0,0 @@
mastodon.py ~= 1.8
json5 ~= 0.9.11

2080
verbs.txt

File diff suppressed because it is too large Load Diff