#!/usr/bin/env python3 # Copyright (C) 2019 @LynnearSoftware@lynnesbian.fedi.space # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from mastodon import Mastodon from os import path import shutil, os, sqlite3, signal, sys, json import markovify # import re scopes = ["write:statuses"] cfg = { "site": "https://botsin.space", "cw": None } try: cfg.update(json.load(open('config.json', 'r'))) except: pass if "client" not in cfg: print("No application info -- registering application with {}".format(cfg['site'])) client_id, client_secret = Mastodon.create_app("txtbooks", api_base_url=cfg['site'], scopes=scopes, website="https://git.lynnesbian.space/Lynnesbian/txtbooks") cfg['client'] = { "id": client_id, "secret": client_secret } if "secret" not in cfg: print("No user credentials -- logging in to {}".format(cfg['site'])) client = Mastodon(client_id = cfg['client']['id'], client_secret = cfg['client']['secret'], api_base_url=cfg['site']) print("Open this URL and authenticate to give the script access to your bot's account: {}".format(client.auth_request_url(scopes=scopes))) cfg['secret'] = client.log_in(code=input("Secret: "), scopes=scopes) json.dump(cfg, open("config.json", "w+")) print("Generating markovify data") class TextFixed(markovify.Text): def test_sentence_input(self, sentence): return True #all sentences are valid <3 with open("corpus.txt") as f: text = f.read() model = TextFixed(text) open("model.json", "w").write(model.to_json())