diff --git a/.gitignore b/.gitignore index b8f814b..cace76f 100755 --- a/.gitignore +++ b/.gitignore @@ -165,3 +165,5 @@ dmypy.json # Cython debug symbols cython_debug/ +# Mastodon secrets +**/*.secret \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 410c178..fadf492 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,5 @@ requests markdown Flask-Caching aiohttp + +mastodon-py \ No newline at end of file diff --git a/threads.py b/threads.py index 03a81dd..d1971f9 100755 --- a/threads.py +++ b/threads.py @@ -6,6 +6,7 @@ import re from .cache import cache import asyncio import aiohttp +from mastodon import Mastodon threads = Blueprint('threads', __name__, template_folder='templates') @@ -59,8 +60,35 @@ async def home(): statuses = await fetch_statuses() attribution = get_attribution() app = get_app_config() + + Mastodon.create_app( + app['site_name'], + api_base_url = app['server'], + to_file = app['secret_file'] + ) + + mastodon = Mastodon(client_id = app['secret_file'],) + mastodon.log_in( + app['user'], + app['password'], + to_file = app['secret_file'] + ) + + response = mastodon.toot('Post from https://ayco.io/threads using mastodon.py!') + print('>>> ' + response.url) + return render_template('threads.html', threads=statuses, app=app, attribution=attribution, render_date=datetime.now()) + +@threads.route('/new') +@cache.cached(timeout=300) +async def new(): + attribution = get_attribution() + app = get_app_config() + return render_template('new.html', app=app, attribution=attribution, render_date=datetime.now()) + + + @threads.route('/') @cache.cached(timeout=300) def thread(id):