Permalink
Browse files

Minor tweaks

  • Loading branch information...
1 parent 4ca02e4 commit 7b313b100d7b91b61d326127f26bdb4894dfb3bc @dmpop committed Sep 9, 2012
Showing with 57 additions and 87 deletions.
  1. +26 −41 pygmynote.py
  2. +31 −46 pygmynote3.py
View
@@ -51,7 +51,7 @@
if DEBUG == True:
print 'Use pysqlite2, with python %s' % sys.version
-DB = 'bitpocket/pygmynote.db'
+DB = 'pygmynote.db'
ENC = 'utf-8'
if os.path.exists(DB):
@@ -127,8 +127,7 @@ def escapechar(sel):
n Search records by note
t Search records by tag
a Show active records
-p Show records with the \"private" tag
-h Show archived records
+ar Show archived records
tl Show tasks
at Show records with attachments
w Export records as CSV file
@@ -139,28 +138,28 @@ def escapechar(sel):
# Insert new record
- ntext = escapechar(raw_input('Note: '))
- ntags = escapechar(raw_input('Tags: '))
- ndue = raw_input('Due date (yyyy-mm-dd). Press Enter to skip: ')
- ntype = "1"
+ rtxt = escapechar(raw_input('Note: '))
+ rtags = escapechar(raw_input('Tags: '))
+ rdue = raw_input('Due date (yyyy-mm-dd). Press Enter to skip: ')
+ rtype = "1"
sqlquery = \
"INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')"\
- % (ntext, ndue, ntags, ntype)
+ % (rtxt, rdue, rtags, rtype)
cursor.execute(sqlquery)
conn.commit()
print '\nRecord has been added.'
elif command == 'f':
# Insert new record with file
- ntext = escapechar(raw_input('Note: '))
- ntags = escapechar(raw_input('Tags: '))
- nfile = escapechar(raw_input('Enter path to file: '))
- ntype="1"
- f=open(nfile.rstrip(), 'rb')
+ rtxt = escapechar(raw_input('Note: '))
+ rtags = escapechar(raw_input('Tags: '))
+ rfile = escapechar(raw_input('Enter path to file: '))
+ rtype="1"
+ f=open(rfile.rstrip(), 'rb')
ablob = f.read()
f.close()
- cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + ntext + "', '" + ntags + "', '" + ntype + "', '" + nfile[-3:] + "', ?)", [sqlite.Binary(ablob)])
+ cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + rtxt + "', '" + rtags + "', '" + rtype + "', '" + rfile[-3:] + "', ?)", [sqlite.Binary(ablob)])
conn.commit()
print '\nRecord has been added.'
elif command == 's':
@@ -181,9 +180,9 @@ def escapechar(sel):
# Search records by note
- ntext = raw_input('Search notes for: ')
+ rtxt = raw_input('Search notes for: ')
cursor.execute("SELECT id, note, tags FROM notes WHERE note LIKE '%"
- + ntext + "%'ORDER BY id ASC")
+ + rtxt + "%'ORDER BY id ASC")
print '\n-----'
for row in cursor:
print '\n\033[1;32m%s\033[1;m %s \033[1;30m[%s]\033[1;m' % (row[0], row[1], row[2])
@@ -205,20 +204,6 @@ def escapechar(sel):
print '\n-----'
print '\033[1;34mRecord count:\033[1;m %s' % counter
counter = 0
- elif command == 'p':
-
-# Show private records
-
- stag = 'private'
- cursor.execute("SELECT id, note, tags FROM notes WHERE tags LIKE '%"
- + stag + "%' AND type='1' ORDER BY id ASC")
- print '\n-----'
- for row in cursor:
- print '\n\033[1;32m%s\033[1;m %s \033[1;30m[%s]\033[1;m' % (row[0], row[1], row[2])
- counter = counter + 1
- print '\n-----'
- print '\033[1;34mRecord count:\033[1;m %s' % counter
- counter = 0
elif command == 'a':
# Show active records
@@ -231,9 +216,9 @@ def escapechar(sel):
print '\n-----'
print '\033[1;34mRecord count:\033[1;m %s' % counter
counter = 0
- elif command == 'h':
+ elif command == 'ar':
-# Show hidden records
+# Show archived records
cursor.execute("SELECT id, note, tags FROM notes WHERE type='0' ORDER BY id ASC")
print '\n-----'
@@ -245,30 +230,30 @@ def escapechar(sel):
counter = 0
elif command == 'u':
-# Update note
+# Update record
recid = raw_input('Record id: ')
- ntype = raw_input('Update note [0], tags [1], due date [2], or archive [3]: ')
- if ntype == '0':
+ rtype = raw_input('Update note [0], tags [1], due date [2], or archive [3]: ')
+ if rtype == '0':
cursor.execute ("SELECT id, note FROM notes WHERE id='" + recid + "'")
row = cursor.fetchone()
print 'Current contents: %s' % row[1]
noteupd = raw_input('Note: ')
sqlstr = escapechar(noteupd)
cursor.execute("UPDATE notes SET note='" + sqlstr
+ "' WHERE id='" + recid + "'")
- elif ntype == '1':
+ elif rtype == '1':
tagupd = raw_input('Tags: ')
sqlstr = escapechar(tagupd)
cursor.execute("UPDATE notes SET tags='" + sqlstr
+ "' WHERE id='" + recid + "'")
- elif ntype == '2':
+ elif rtype == '2':
dueupd = raw_input('Due date: ')
cursor.execute("UPDATE notes SET due='" + dueupd
+ "' WHERE id='" + recid + "'")
else:
- ntype = '0'
- cursor.execute("UPDATE notes SET type='" + ntype
+ rtype = '0'
+ cursor.execute("UPDATE notes SET type='" + rtype
+ "' WHERE id='" + recid + "'")
conn.commit()
print '\nRecord has been updated.'
@@ -300,15 +285,15 @@ def escapechar(sel):
counter = 0
elif command == 'd':
-# Delete note by its ID
+# Delete record by its ID
recid = raw_input('Delete note ID: ')
cursor.execute("DELETE FROM notes WHERE ID='" + recid + "'")
print '\nRecord has been deleted.'
conn.commit()
elif command == 'w':
-# Save all notes as pygmynote.txt
+# Save all records in pygmynote.txt
cursor.execute("SELECT id, note, tags, due FROM notes ORDER BY id ASC")
if os.path.exists('pygmynote.txt'):
View
@@ -119,8 +119,7 @@ def escapechar(sel):
n Search records by note
t Search records by tag
a Show active records
-p Show records with the \"private" tag
-h Show archived records
+ar Show archived records
tl Show tasks
at Show records with attachments
w Export records as CSV file
@@ -131,28 +130,28 @@ def escapechar(sel):
# Insert new record
- ntext = escapechar(input('Note: '))
- ntags = escapechar(input('Tags: '))
- ndue = input('Due date (yyyy-mm-dd). Press Enter to skip: ')
- ntype = '1'
+ rtxt = escapechar(input('Note: '))
+ rtags = escapechar(input('Tags: '))
+ rdue = input('Due date (yyyy-mm-dd). Press Enter to skip: ')
+ rtype = '1'
sqlquery = \
"INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')"\
- % (ntext, ndue, ntags, ntype)
+ % (rtxt, rdue, rtags, rtype)
cursor.execute(sqlquery)
conn.commit()
print ('\nRecord has been added.')
elif command == 'f':
# Insert new record with file
- ntext = escapechar(input('Note: '))
- ntags = escapechar(input('Tags: '))
- notefile = escapechar(input('Enter path to file: '))
- ntype='1'
- f=open(notefile.rstrip(), 'rb')
+ rtxt = escapechar(input('Note: '))
+ rtags = escapechar(input('Tags: '))
+ rfile = escapechar(input('Enter path to file: '))
+ rtype='1'
+ f=open(rfile.rstrip(), 'rb')
ablob = f.read()
f.close()
- cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + ntext + "', '" + ntags + "', '" + ntype + "', '" + notefile[-3:] + "', ?)", [sqlite.Binary(ablob)])
+ cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + rtxt + "', '" + rtags + "', '" + rtype + "', '" + rfile[-3:] + "', ?)", [sqlite.Binary(ablob)])
conn.commit()
print ('\nRecord has been added.')
elif command == 's':
@@ -173,9 +172,9 @@ def escapechar(sel):
# Search records by note
- ntext = input('Search notes for: ')
+ rtxt = input('Search notes for: ')
cursor.execute("SELECT id, note, tags FROM notes WHERE note LIKE '%"
- + ntext + "%'ORDER BY id ASC")
+ + rtxt + "%'ORDER BY id ASC")
print ("\n-----")
for row in cursor:
print ("\n\033[1;32m%s\033[1;m %s \033[1;30m[%s]\033[1;m" % (row[0], row[1], row[2]))
@@ -197,20 +196,6 @@ def escapechar(sel):
print ('\n-----')
print ('\033[1;34mRecord count:\033[1;m %s' % counter)
counter = 0
- elif command == 'p':
-
-# Show private records
-
- stag = 'private'
- cursor.execute("SELECT id, note, tags FROM notes WHERE tags LIKE '%"
- + stag + "%' AND type='1' ORDER BY id ASC")
- print ("\n-----")
- for row in cursor:
- print ("\n\033[1;32m%s\033[1;m %s \033[1;30m[%s]\033[1;m" % (row[0], row[1], row[2]))
- counter = counter + 1
- print ('\n-----')
- print ('\033[1;34mRecord count:\033[1;m %s' % counter)
- counter = 0
elif command == 'a':
# Show active records
@@ -223,9 +208,9 @@ def escapechar(sel):
print ('\n-----')
print ('\033[1;34mRecord count:\033[1;m %s' % counter)
counter = 0
- elif command == 'h':
+ elif command == 'ar':
-# Show hidden records
+# Show archived records
cursor.execute("SELECT id, note, tags FROM notes WHERE type='0' ORDER BY id ASC")
print ('\n-----')
@@ -237,30 +222,30 @@ def escapechar(sel):
counter = 0
elif command == 'u':
-# Update note
+# Update record
recid = input('Record id: ')
- ntype = input('Update note [0], tags [1], due date [2], or archive [3]: ')
- if ntype == '0':
+ rtype = input('Update note [0], tags [1], due date [2], or archive [3]: ')
+ if rtype == '0':
cursor.execute ("SELECT id, note FROM notes WHERE id='" + recid + "'")
row = cursor.fetchone()
print ('Current contents: %s' % row[1])
- noteupdate = input('Note: ')
- sqlstr = escapechar(noteupdate)
+ noteupd = input('Note: ')
+ sqlstr = escapechar(noteupd)
cursor.execute("UPDATE notes SET note='" + sqlstr
+ "' WHERE id='" + recid + "'")
- elif ntype == '1':
- tagupdate = input('Tags: ')
- sqlstr = escapechar(tagupdate)
+ elif rtype == '1':
+ tagupd = input('Tags: ')
+ sqlstr = escapechar(tagupd)
cursor.execute("UPDATE notes SET tags='" + sqlstr
+ "' WHERE id='" + recid + "'")
- elif ntype == '2':
- dueupdate = input('Due date: ')
- cursor.execute("UPDATE notes SET due='" + dueupdate
+ elif rtype == '2':
+ dueupd = input('Due date: ')
+ cursor.execute("UPDATE notes SET due='" + dueupd
+ "' WHERE id='" + recid + "'")
else:
- ntype = '0'
- cursor.execute("UPDATE notes SET type='" + ntype
+ rtype = '0'
+ cursor.execute("UPDATE notes SET type='" + rtype
+ "' WHERE id='" + recid + "'")
conn.commit()
print ('\nRecord has been updated.')
@@ -292,15 +277,15 @@ def escapechar(sel):
counter = 0
elif command == 'd':
-# Delete note by its ID
+# Delete record by its ID
recid = input('Delete note ID: ')
cursor.execute("DELETE FROM notes WHERE ID='" + recid + "'")
print ('\nRecord has been deleted.')
conn.commit()
elif command == 'w':
-# Save all notes as pygmynote.txt
+# Save all records in pygmynote.txt
cursor.execute("SELECT id, note, tags, due FROM notes ORDER BY id ASC")
if os.path.exists('pygmynote.txt'):

0 comments on commit 7b313b1

Please sign in to comment.