Initial commit

This commit is contained in:
Ivan Odintsoff 2022-09-10 10:55:14 -03:00
parent a3f4bb21a6
commit 8bb3caefbd
6 changed files with 151 additions and 0 deletions

27
addnote.py Executable file
View File

@ -0,0 +1,27 @@
#!/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")

29
complete.py Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/python
import os
import sqlite3
clihash = os.environ.get('TLS_CLIENT_HASH', "")
qstr = os.environ.get('QUERY_STRING', "")
if clihash == "":
print("60 Please use a certificate to authenticate\r\n")
exit()
if qstr == "":
print("30 notesapp.py\r\n")
exit()
if qstr.isnumeric():
con = sqlite3.connect('notes.db')
cur = con.cursor()
try:
cur.execute("UPDATE Notes SET Completed = CASE Completed WHEN 1 THEN 0 ELSE 1 END WHERE NoteIndex=? and Hash=?", (qstr, clihash))
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")

29
delete.py Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/python
import os
import sqlite3
clihash = os.environ.get('TLS_CLIENT_HASH', "")
qstr = os.environ.get('QUERY_STRING', "")
if clihash == "":
print("60 Please use a certificate to authenticate\r\n")
exit()
if qstr == "":
print("30 notesapp.py\r\n")
exit()
if qstr.isnumeric():
con = sqlite3.connect('notes.db')
cur = con.cursor()
try:
cur.execute("DELETE FROM Notes WHERE NoteIndex=? and Hash=?", (qstr, clihash))
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")

23
notes.gmi Normal file
View File

@ -0,0 +1,23 @@
# GemiNotes
## A simple app for taking notes, creating tasks, saving and accessing them through Gemini.
In order to login, you will need a client certificate. Please check your Gemini browser documentation on how to issue and use one.
Features:
* Personal tasks/notes list with your client certificate.
* Mark tasks as completed.
* Delete tasks/notes
Soon:
* Link multiple certificates for login (so you can use multiple devices).
* Different task statuses.
* Export options.
### Disclaimer
This app still in tests, so the database is in a shared host and the notes are not encrypted. So I wouldn't use it for sensitive data or anything too much personal :)
=> ./notesapp.py 🔑 Login here

36
notesapp.py Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/python
import os
import sqlite3
clihash = os.environ.get('TLS_CLIENT_HASH', "")
if clihash == "":
print("60 Please use a certificate to authenticate\r\n")
exit()
con = sqlite3.connect('notes.db')
cur = con.cursor()
rows = cur.execute("SELECT NoteIndex, Note, Completed FROM Notes WHERE hash = :thehash", {"thehash": clihash}).fetchall()
print("20 text/gemini; charset=utf-8\r\n")
print("# GemiNotes")
print('## My notes')
if (not rows):
print("You don't have any notes yet.")
else:
for row in rows:
if row[2] == 1:
checkbox = "🔳 [Done] "
else:
checkbox = ""
print("### {} {}".format(checkbox, row[1]))
print('=> delete.py?{} ❌ Delete note'.format(row[0]))
print('=> complete.py?{} ✔ Change task completion'.format(row[0]))
# Add button to set as completed
print("")
print("=> addnote.py ✍ Add new note")
cur.close()
con.close()

7
schema.sql Normal file
View File

@ -0,0 +1,7 @@
BEGIN TRANSACTION;
CREATE TABLE Notes (
NoteIndex INTEGER PRIMARY KEY AUTOINCREMENT,
Hash TEXT,
Note TEXT,
Completed INTEGER);
COMMIT;