#!/usr/bin/env python3 import os,sys, fileinput, datetime, urllib.parse sys.path.append('../lib/') from helpers import * qString = get_query_string() pathInfo = get_path_info() clientCert = get_client_cert(cert_reqd = True, restricted_auth = True) #ident=os.getenv("REMOTE_IDENT") filePath="/home/gemini/gemini/gemini.smallweb.space/tinylog/tinylog.gmi" if(qString == None): # Display the main page # Read and display gem file contents = read_file('tinylog-main.gmi') show_header_ok() print(contents) if isinstance(qString, dict): if ('edit' in qString): print("10 Enter your log. \r\n") elif ('status' in qString): show_header_ok() print(qString['status'][0]) print("=> tinylog Return") elif qString == {}: # The dict is empty which means there's probably a tinylog status in # the query string # get unparsed queryString userInput = get_query_string(unparsed = True) # insert new log into file mark = "author:" inserted = 0 # date now = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M UTC") data = urllib.parse.unquote(userInput) # write to file # TODO: catch errors and output for line in fileinput.FileInput(filePath, inplace=True): if inserted == 0 and mark in line: line += "\n## " + now + "\n" + data + "\n" inserted = 1 print(line, end="") # redirect back to this page with status update temp_redirect('tinylog?status=Tinylog Posted') gemini://gemini.smallweb.space/HOWTO/examples/tinylog-example.txt

-- Leo's gemini proxy

-- Connecting to gemini.smallweb.space:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/plain

-- Response ended

-- Page fetched on Sun May 19 14:43:46 2024