Added unicode compatibility, better stdout info

This commit is contained in:
Lynne 2018-09-08 23:06:17 +00:00
parent a701196c2e
commit acec5b6668
2 changed files with 69 additions and 67 deletions

8
gen.py
View file

@ -3,14 +3,14 @@ import json
import time
from mastodon import Mastodon
api_base_url = "https://botsin.space"
api_base_url = "https://botsin.space" #todo: this shouldn't be hardcoded
client = Mastodon(
client_id="clientcred.secret",
access_token="usercred.secret",
api_base_url=api_base_url)
with open("corpus.txt") as fp:
with open("corpus.txt", encoding="utf-8") as fp:
model = markovify.NewlineText(fp.read())
print("tooting")
@ -18,4 +18,6 @@ sentence = None
# you will make that damn sentence
while sentence is None:
sentence = model.make_sentence(tries=100000)
client.toot(sentence.replace("\0", "\n"))
toot = sentence.replace("\0", "\n")
client.toot(toot)
print("Created toot: {}".format(toot))

View file

@ -83,8 +83,8 @@ client = Mastodon(
me = client.account_verify_credentials()
following = client.account_following(me.id)
with open("corpus.txt", "w+") as fp:
with open("corpus.txt", "w+", encoding="utf-8") as fp:
for f in following:
print(f.username)
print("Downloading toots for user @{}".format(f.username))
for t in get_toots(client, f.id):
fp.write(t + "\n")