Accept keys and stuff from environment variables instead of files, so it's easier to Heroku

This commit is contained in:
Danielle McLean 2018-09-21 11:36:45 +10:00
parent ca8471ea07
commit 08a2058d61
Signed by: 00dani
GPG key ID: 8EB789DDF3ABD240
2 changed files with 12 additions and 19 deletions

10
gen.py
View file

@ -4,12 +4,14 @@ import time
from mastodon import Mastodon
import re, random, subprocess
api_base_url = "https://botsin.space" #todo: this shouldn't be hardcoded
from os import environ
client = Mastodon(
client_id="clientcred.secret",
access_token="usercred.secret",
api_base_url=api_base_url)
client_id=environ['client_id'],
client_secret=environ['client_secret'],
access_token=environ['access_token'],
api_base_url=environ['instance'],
)
with open("corpus.txt", encoding="utf-8") as fp:
model = markovify.NewlineText(fp.read())

21
main.py
View file

@ -4,18 +4,7 @@ from os import path
from bs4 import BeautifulSoup
import re
api_base_url = "https://botsin.space"
if not path.exists("clientcred.secret"):
print("No clientcred.secret, registering application")
Mastodon.create_app("ebooks", api_base_url=api_base_url, to_file="clientcred.secret")
if not path.exists("usercred.secret"):
print("No usercred.secret, registering application")
email = input("Email: ")
password = getpass("Password: ")
client = Mastodon(client_id="clientcred.secret", api_base_url=api_base_url)
client.log_in(email, password, to_file="usercred.secret")
from os import environ
def parse_toot(toot):
if toot.spoiler_text != "": return
@ -76,9 +65,11 @@ def get_toots(client, id):
print(i)
client = Mastodon(
client_id="clientcred.secret",
access_token="usercred.secret",
api_base_url=api_base_url)
client_id=environ['client_id'],
client_secret=environ['client_secret'],
access_token=environ['access_token'],
api_base_url=environ['instance'],
)
me = client.account_verify_credentials()
following = client.account_following(me.id)