Files

43 lines
1.2 KiB
Python

# My own microblogging interface that supports any POST endpoint
# with HTTP basic auth
# Usage:
# 1. Configure BLOG_POST_ENDPOINT, BLOG_POST_USER and BLOG_PORT_PASS
# variables in settings.toml
# 2.
# Created by Luxferre in 2025, released into public domain
import os, sys
POST_ENDPOINT = os.getenv('BLOG_POST_ENDPOINT', None)
if POST_ENDPOINT is None:
print('Please configure BLOG_POST_ENDPOINT variable in settings.toml')
sys.exit(1)
POST_USER = os.getenv('BLOG_POST_USER', None)
POST_PASS = os.getenv('BLOG_POST_PASS', None)
from deck.input import input, input_multi
from deck.http import requests, auth_header, form_encode
auth_headers = {}
if POST_USER is not None:
auth_headers = auth_header(POST_USER, POST_PASS)
# post a string
def blogpost_str(content):
payload = form_encode({'content': content})
response = requests.post(POST_ENDPOINT, data=payload, headers=auth_headers)
return (response.status_code, response.text)
# expect to post interactively without parameters
def blogpost(content=None):
if content is None:
print('Enter your post, ending with a dot:')
content = input_multi('> ')
print('Sending the post...')
return blogpost_str(content)
def bloged():
from app.ed import edbuf
return blogpost(edbuf())