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

21
main.py
View file

@ -4,18 +4,7 @@ from os import path
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import re import re
api_base_url = "https://botsin.space" from os import environ
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")
def parse_toot(toot): def parse_toot(toot):
if toot.spoiler_text != "": return if toot.spoiler_text != "": return
@ -76,9 +65,11 @@ def get_toots(client, id):
print(i) print(i)
client = Mastodon( client = Mastodon(
client_id="clientcred.secret", client_id=environ['client_id'],
access_token="usercred.secret", client_secret=environ['client_secret'],
api_base_url=api_base_url) access_token=environ['access_token'],
api_base_url=environ['instance'],
)
me = client.account_verify_credentials() me = client.account_verify_credentials()
following = client.account_following(me.id) following = client.account_following(me.id)