diff --git a/bin/311_ebooks.py b/bin/311_ebooks.py index 97aaa18..f005354 100644 --- a/bin/311_ebooks.py +++ b/bin/311_ebooks.py @@ -2,6 +2,9 @@ import markovify #https://github.com/jsvine/markovify import sqlite3 #to read db +from mastodon import Mastodon +from configparser import ConfigParser +import os.path # Open the db conn = sqlite3.connect('requests.sqlite') @@ -13,11 +16,44 @@ def get_descriptions(): return(data) # Get descriptions and convert to strings from tuples -b = ["".join(str(x)) for x in get_descriptions()] +b = ["".join(str(x).replace("\\r\\n","")) for x in get_descriptions()] # Build the model. text_model = markovify.Text(b) # Print three randomly-generated sentences of no more than 280 characters -for i in range(3): - print(text_model.make_short_sentence(280)) +#for i in range(3): +# print(text_model.make_short_sentence(280)) + +# Next up use this to toot: https://github.com/halcy/Mastodon.py + +# parse existing file +config = ConfigParser() +config.read('auth.ini') + +# read values from a section +server = config.get('mastodon', 'server') +email = config.get('mastodon', 'email') +password = config.get('mastodon', 'password') + +# Register the app (once) +if not os.path.isfile('hackgfk_311_ebooks_clientcred.secret'): + Mastodon.create_app( + 'hackgfk_311_ebooks', + api_base_url = server, + to_file = 'hackgfk_311_ebooks_clientcred.secret' + ) + +# Log in +mastodon = Mastodon( + client_id = 'hackgfk_311_ebooks_clientcred.secret', + api_base_url = server, +) +mastodon.log_in( + email, + password, + to_file = 'hackgfk_311_ebooks_usercred.secret' +) + +# Send toot +mastodon.toot(text_model.make_short_sentence(280))