spawn /usr/bin/nano to edit a post description
This commit is contained in:
parent
2e66d7f40c
commit
4221f2d010
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
from mastodon import Mastodon
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
from subprocess import call
|
||||
|
||||
# load JSON config file
|
||||
def load_config() -> dict:
|
||||
|
@ -29,6 +32,23 @@ def gen_url(config_data: dict, phlog_file: str) -> dict:
|
|||
urls = {'gopher':gopher_url, 'proxy':proxy_url}
|
||||
return urls
|
||||
|
||||
# spawn $EDITOR or nano by default to edit the post text
|
||||
def edit_post(post: str) -> str:
|
||||
EDITOR = os.environ.get('EDITOR', 'nano')
|
||||
|
||||
tf_file = tempfile.NamedTemporaryFile(suffix = '.tmp', delete = False)
|
||||
with open(tf_file.name, 'w') as tf:
|
||||
tf.write(post)
|
||||
|
||||
call([EDITOR, tf_file.name])
|
||||
|
||||
with open(tf_file.name, 'r') as tf:
|
||||
post = tf.read()
|
||||
tf.close()
|
||||
|
||||
os.unlink(tf_file.name)
|
||||
return post
|
||||
|
||||
# display post contents and verify with the user
|
||||
def post_check(post: str) -> bool:
|
||||
print('You are about to post')
|
||||
|
@ -46,14 +66,13 @@ def main():
|
|||
m = gen_masto_obj(config_data)
|
||||
|
||||
# generate URLs
|
||||
# TODO: prompt for phlog path
|
||||
phlog_file = input('Post location (leave blank for root): ')
|
||||
urls = gen_url(config_data, phlog_file)
|
||||
|
||||
# get post description, generate post text
|
||||
# TODO: Spawn $EDITOR, content warnings
|
||||
text = 'Test post, please ignore'
|
||||
post = f"{text}\n\nGopher: {urls['gopher']}\nHTML Proxy: {urls['proxy']}"
|
||||
# TODO: content warnings
|
||||
post = f"<Replace with your post description>\n\nGopher: {urls['gopher']}\nHTML Proxy: {urls['proxy']}"
|
||||
post = edit_post(post)
|
||||
|
||||
# verify the post with the user and post it
|
||||
if post_check(post):
|
||||
|
|
Loading…
Reference in New Issue