feat: initial Mastodon client
This commit is contained in:
parent
e4fe74bd6b
commit
e73ef755fd
3 changed files with 32 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -165,3 +165,5 @@ dmypy.json
|
||||||
# Cython debug symbols
|
# Cython debug symbols
|
||||||
cython_debug/
|
cython_debug/
|
||||||
|
|
||||||
|
# Mastodon secrets
|
||||||
|
**/*.secret
|
|
@ -3,3 +3,5 @@ requests
|
||||||
markdown
|
markdown
|
||||||
Flask-Caching
|
Flask-Caching
|
||||||
aiohttp
|
aiohttp
|
||||||
|
|
||||||
|
mastodon-py
|
28
threads.py
28
threads.py
|
@ -6,6 +6,7 @@ import re
|
||||||
from .cache import cache
|
from .cache import cache
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
from mastodon import Mastodon
|
||||||
|
|
||||||
threads = Blueprint('threads', __name__, template_folder='templates')
|
threads = Blueprint('threads', __name__, template_folder='templates')
|
||||||
|
|
||||||
|
@ -59,8 +60,35 @@ async def home():
|
||||||
statuses = await fetch_statuses()
|
statuses = await fetch_statuses()
|
||||||
attribution = get_attribution()
|
attribution = get_attribution()
|
||||||
app = get_app_config()
|
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())
|
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('/<path:id>')
|
@threads.route('/<path:id>')
|
||||||
@cache.cached(timeout=300)
|
@cache.cached(timeout=300)
|
||||||
def thread(id):
|
def thread(id):
|
||||||
|
|
Loading…
Reference in a new issue