notepad

Check-in [1ec9053e4d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:First pass, global notes. It's easy to forget to manually sync, gotta think about that...
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:1ec9053e4da8317699702b82565e2f35b2dfe115402ffb0093dc7f15f3f9b0fe
User & Date: vandys 2019-02-06 18:53:05
Context
2019-02-10
18:54
Utility in support of global notes Leaf check-in: 45b60e7948 user: vandys tags: master, trunk
2019-02-06
18:53
First pass, global notes. It's easy to forget to manually sync, gotta think about that... check-in: 1ec9053e4d user: vandys tags: master, trunk
14:16
Stale comment check-in: 287dc7ad2a user: vandys tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to README.txt.

20
21
22
23
24
25
26












- Make var and var/DBNAME writable
    - chmod a+rwx var
    - chmod a=rw var/DBNAME

- Make sure your web server will run Python CGI from the installed
    directory.


















>
>
>
>
>
>
>
>
>
>
>
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

- Make var and var/DBNAME writable
    - chmod a+rwx var
    - chmod a=rw var/DBNAME

- Make sure your web server will run Python CGI from the installed
    directory.

Global Notes
============

Once you have a note (say, "Shopping"), you can make it global so all
accounts can see it:

python setglobal.py "<your-user>" "<title>"

Internally, this makes the user of the note "*".  You will continue to
see it, but so will all other accounts.

Changes to sync.py.

4
5
6
7
8
9
10











11
12
13
14
15
16
17
..
45
46
47
48
49
50
51


52

53







54
55
56
57

58
59
60
61
62
63
64
65
..
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
#	Accept POST of new entries to our note DB
#
import cgi, sys, json, time
import sqlite3
from config import DBNAME
w = sys.stdout.write












# Connect to DB
# (Use a name which outsiders won't know.)
conn = sqlite3.connect("var/" + DBNAME)

# This is a JSON API
w("Content-Type: application/json\n")

................................................................................
c.execute("select password from accounts where user=?", (user,))
tup = c.fetchone()
c.close()
if (tup is None) or (tup[0] != pw):
    fail("Bad login")

# Gather our current notes, keyed by note's index name (noteXXXX)


onotes = {}

c = conn.cursor()







c.execute(
 "select key,tm,title,content from notes where user=? and tm>?",
 (user, tm))
for tup in c:

    onotes[tup[0]] = {"tm": tup[1], "key": tup[0],
	"title": tup[2], "content": tup[3]}

# For each note which they've changed, either accept the change,
#  or send back the newer content which we've already received.
resp = {}
changes = False
c = conn.cursor()
................................................................................
	continue

    # Nothing newer, so just register note
    # (This includes deleted notes, which are like others with
    #  key/timestamp, but with title/content being null.)
    oent = onotes.get(key)
    if oent is None:

	c.execute("insert or replace into notes values (?,?,?,?,?)",
	    (key, user, note["tm"], note["title"], note["content"]))
	changes = True
	continue

    # We both have updates, but server already has newest.
    # Include this value in the response update back.
    if oent["tm"] > note["tm"]:
	resp[key] = oent







>
>
>
>
>
>
>
>
>
>
>







 







>
>

>

>
>
>
>
>
>
>

|


>
|







 







>

|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
..
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#	Accept POST of new entries to our note DB
#
import cgi, sys, json, time
import sqlite3
from config import DBNAME
w = sys.stdout.write

# Debugging
Debug = True
def log(s):
    global Debug

    if not Debug:
	return
    f = open("/tmp/note.log", "a")
    f.write("%s\n%s\n\n" % (time.ctime(), s))
    f.close()

# Connect to DB
# (Use a name which outsiders won't know.)
conn = sqlite3.connect("var/" + DBNAME)

# This is a JSON API
w("Content-Type: application/json\n")

................................................................................
c.execute("select password from accounts where user=?", (user,))
tup = c.fetchone()
c.close()
if (tup is None) or (tup[0] != pw):
    fail("Bad login")

# Gather our current notes, keyed by note's index name (noteXXXX)
# Notes owned by "*" are global notes; everybody can write on them and
#  the content is shared across accounts.
onotes = {}
GlobalNotes = set()
c = conn.cursor()

# List out global notes
c.execute('select key from notes where user="*"')
for tup in c:
    GlobalNotes.add(tup[0])

# Now get ones which currently apply
c.execute(
 'select key,tm,title,content from notes where (user=? or user="*") and tm>?',
 (user, tm))
for tup in c:
    key = tup[0]
    onotes[key] = {"tm": tup[1], "key": key,
	"title": tup[2], "content": tup[3]}

# For each note which they've changed, either accept the change,
#  or send back the newer content which we've already received.
resp = {}
changes = False
c = conn.cursor()
................................................................................
	continue

    # Nothing newer, so just register note
    # (This includes deleted notes, which are like others with
    #  key/timestamp, but with title/content being null.)
    oent = onotes.get(key)
    if oent is None:
	u = "*" if (key in GlobalNotes) else user
	c.execute("insert or replace into notes values (?,?,?,?,?)",
	    (key, u, note["tm"], note["title"], note["content"]))
	changes = True
	continue

    # We both have updates, but server already has newest.
    # Include this value in the response update back.
    if oent["tm"] > note["tm"]:
	resp[key] = oent