Finish script to toot from same account.
This commit is contained in:
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
import markovify #https://github.com/jsvine/markovify
|
import markovify #https://github.com/jsvine/markovify
|
||||||
import sqlite3 #to read db
|
import sqlite3 #to read db
|
||||||
|
from mastodon import Mastodon
|
||||||
|
from configparser import ConfigParser
|
||||||
|
import os.path
|
||||||
|
|
||||||
# Open the db
|
# Open the db
|
||||||
conn = sqlite3.connect('requests.sqlite')
|
conn = sqlite3.connect('requests.sqlite')
|
||||||
@ -13,11 +16,44 @@ def get_descriptions():
|
|||||||
return(data)
|
return(data)
|
||||||
|
|
||||||
# Get descriptions and convert to strings from tuples
|
# 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.
|
# Build the model.
|
||||||
text_model = markovify.Text(b)
|
text_model = markovify.Text(b)
|
||||||
|
|
||||||
# Print three randomly-generated sentences of no more than 280 characters
|
# Print three randomly-generated sentences of no more than 280 characters
|
||||||
for i in range(3):
|
#for i in range(3):
|
||||||
print(text_model.make_short_sentence(280))
|
# 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))
|
||||||
|
Reference in New Issue
Block a user