GemiNotes/addnote.py

28 lines
656 B
Python
Executable File

#!/usr/bin/python
import os
import sqlite3
import urllib.parse
clihash = os.environ.get('TLS_CLIENT_HASH', "")
qstr = urllib.parse.unquote(os.environ.get('QUERY_STRING', ""))
if clihash == "":
print("60 Please use a certificate to authenticate\r\n")
exit()
if qstr == "":
print("10 Enter note text.\r\n")
else:
con = sqlite3.connect('notes.db')
cur = con.cursor()
try:
cur.execute("INSERT INTO Notes (Hash,Note) VALUES (?,?)", (clihash, qstr))
con.commit()
except sqlite3.Error as e:
print("20 text/gemini; charset=utf-8\r\n")
print(e.args[0])
exit()
print("30 notesapp.py\r\n")