Permalink
Browse files

Minor tweaks

  • Loading branch information...
1 parent 7946060 commit 23e5e0bd5aab29029f4bd6c21913d9715cdfa93c @dmpop committed Sep 9, 2012
Showing with 88 additions and 88 deletions.
  1. +49 −49 pygmynote.py
  2. +38 −38 pygmynote3.py
  3. +1 −1 sniptopygmynote.py
View
98 pygmynote.py
@@ -51,7 +51,7 @@
if DEBUG == True:
print 'Use pysqlite2, with python %s' % sys.version
-DB = 'pygmynote.db'
+DB = 'bitpocket/pygmynote.db'
ENC = 'utf-8'
if os.path.exists(DB):
@@ -104,7 +104,7 @@ def escapechar(sel):
conn.commit()
print 'Today\'s deadlines:'
-cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due = '" + today + "' AND type <> 'H' ORDER BY id ASC")
+cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due = '" + today + "' AND type <> '0' ORDER BY id ASC")
for row in cursor:
print '\n%s -- \033[1;32m%s\033[1;m %s \033[1;30m[%s]\033[1;m' % (row[0], row[1], row[2], row[3])
@@ -139,38 +139,38 @@ def escapechar(sel):
# Insert new record
- notetext = escapechar(raw_input('Note: '))
- notetags = escapechar(raw_input('Tags: '))
- notedue = raw_input('Due date (yyyy-mm-dd). Press Enter to skip: ')
- notetype = "A"
+ ntext = escapechar(raw_input('Note: '))
+ ntags = escapechar(raw_input('Tags: '))
+ ndue = raw_input('Due date (yyyy-mm-dd). Press Enter to skip: ')
+ nstatus = "1"
sqlquery = \
"INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')"\
- % (notetext, notedue, notetags, notetype)
+ % (ntext, ndue, ntags, nstatus)
cursor.execute(sqlquery)
conn.commit()
print '\nRecord has been added.'
elif command == 'f':
# Insert new record with file
- notetext = escapechar(raw_input('Note: '))
- notetags = escapechar(raw_input('Tags: '))
- notefile = escapechar(raw_input('Enter path to file: '))
- notetype="A"
- f=open(notefile.rstrip(), 'rb')
+ ntext = escapechar(raw_input('Note: '))
+ ntags = escapechar(raw_input('Tags: '))
+ nfile = escapechar(raw_input('Enter path to file: '))
+ nstatus="1"
+ f=open(nfile.rstrip(), 'rb')
ablob = f.read()
f.close()
- cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + notetext + "', '" + notetags + "', '" + notetype + "', '" + notefile[-3:] + "', ?)", [sqlite.Binary(ablob)])
+ cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + ntext + "', '" + ntags + "', '" + nstatus + "', '" + nfile[-3:] + "', ?)", [sqlite.Binary(ablob)])
conn.commit()
print '\nRecord has been added.'
elif command == 's':
# Save file
- recordid = raw_input('Record id: ')
- outputfile=raw_input('Specify full path and file name (e.g., /home/user/loremipsum.odt): ')
- f=open(outputfile, 'wb')
- cursor.execute ("SELECT file FROM notes WHERE id='" + recordid + "'")
+ recid = raw_input('Record id: ')
+ outfile=raw_input('Specify full path and file name (e.g., /home/user/loremipsum.odt): ')
+ f=open(outfile, 'wb')
+ cursor.execute ("SELECT file FROM notes WHERE id='" + recid + "'")
ablob = cursor.fetchone()
f.write(ablob[0])
f.close()
@@ -181,9 +181,9 @@ def escapechar(sel):
# Search records by note
- notetext = raw_input('Search notes for: ')
+ ntext = raw_input('Search notes for: ')
cursor.execute("SELECT id, note, tags FROM notes WHERE note LIKE '%"
- + notetext + "%'ORDER BY id ASC")
+ + ntext + "%'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])
@@ -195,9 +195,9 @@ def escapechar(sel):
# Search records by tag
- searchtag = raw_input ('Search by tag: ')
+ stag = raw_input ('Search by tag: ')
cursor.execute("SELECT id, note, tags FROM notes WHERE tags LIKE '%"
- + searchtag + "%' AND type='A' ORDER BY id ASC")
+ + 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])
@@ -209,9 +209,9 @@ def escapechar(sel):
# Show private records
- searchtag = 'private'
+ stag = 'private'
cursor.execute("SELECT id, note, tags FROM notes WHERE tags LIKE '%"
- + searchtag + "%' AND type='A' ORDER BY id ASC")
+ + 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])
@@ -223,7 +223,7 @@ def escapechar(sel):
# Show active records
- cursor.execute("SELECT id, note, tags FROM notes WHERE type='A' ORDER BY id ASC")
+ cursor.execute("SELECT id, note, tags FROM notes WHERE 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])
@@ -235,7 +235,7 @@ def escapechar(sel):
# Show hidden records
- cursor.execute("SELECT id, note, tags FROM notes WHERE type='H' ORDER BY id ASC")
+ cursor.execute("SELECT id, note, tags FROM notes WHERE type='0' 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])
@@ -247,36 +247,36 @@ def escapechar(sel):
# Update note
- recordid = raw_input('Record id: ')
- notetype = raw_input('Update note (n), tags (t), due date (d), or mark as hidden (h): ')
- if notetype == 'n':
- cursor.execute ("SELECT id, note FROM notes WHERE id='" + recordid + "'")
+ recid = raw_input('Record id: ')
+ nstatus = raw_input('Update note [0], tags [1], due date [2], or archive [3]: ')
+ if nstatus == '0':
+ cursor.execute ("SELECT id, note FROM notes WHERE id='" + recid + "'")
row = cursor.fetchone()
print 'Current contents: %s' % row[1]
- noteupdate = raw_input('Note: ')
- sqlstr = escapechar(noteupdate)
+ noteupd = raw_input('Note: ')
+ sqlstr = escapechar(noteupd)
cursor.execute("UPDATE notes SET note='" + sqlstr
- + "' WHERE id='" + recordid + "'")
- elif notetype == 't':
- tagupdate = raw_input('Tags: ')
- sqlstr = escapechar(tagupdate)
+ + "' WHERE id='" + recid + "'")
+ elif nstatus == '1':
+ tagupd = raw_input('Tags: ')
+ sqlstr = escapechar(tagupd)
cursor.execute("UPDATE notes SET tags='" + sqlstr
- + "' WHERE id='" + recordid + "'")
- elif notetype == 'd':
- dueupdate = raw_input('Due date: ')
- cursor.execute("UPDATE notes SET due='" + dueupdate
- + "' WHERE id='" + recordid + "'")
+ + "' WHERE id='" + recid + "'")
+ elif nstatus == '2':
+ dueupd = raw_input('Due date: ')
+ cursor.execute("UPDATE notes SET due='" + dueupd
+ + "' WHERE id='" + recid + "'")
else:
- notetype = 'H'
- cursor.execute("UPDATE notes SET type='" + notetype
- + "' WHERE id='" + recordid + "'")
+ nstatus = '0'
+ cursor.execute("UPDATE notes SET type='" + nstatus
+ + "' WHERE id='" + recid + "'")
conn.commit()
print '\nRecord has been updated.'
elif command == 'tl':
# Show tasks
- cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due <> '' AND tags NOT LIKE '%private%' AND type = 'A' ORDER BY due ASC")
+ cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due <> '' AND tags NOT LIKE '%private%' AND type = '1' ORDER BY due ASC")
print '\n-----'
now = datetime.datetime.now()
calendar.prmonth(now.year, now.month)
@@ -290,7 +290,7 @@ def escapechar(sel):
# Show records with attachments
- cursor.execute("SELECT id, note, tags, ext FROM notes WHERE ext <> 'None' AND type='A' ORDER BY id ASC")
+ cursor.execute("SELECT id, note, tags, ext FROM notes WHERE ext <> 'None' 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 \033[1;43m%s\033[1;m' % (row[0], row[1], row[2], row[3])
@@ -302,8 +302,8 @@ def escapechar(sel):
# Delete note by its ID
- recordid = raw_input('Delete note ID: ')
- cursor.execute("DELETE FROM notes WHERE ID='" + recordid + "'")
+ recid = raw_input('Delete note ID: ')
+ cursor.execute("DELETE FROM notes WHERE ID='" + recid + "'")
print '\nRecord has been deleted.'
conn.commit()
elif command == 'w':
@@ -314,8 +314,8 @@ def escapechar(sel):
if os.path.exists('pygmynote.txt'):
os.remove('pygmynote.txt')
for row in cursor:
- filename = 'pygmynote.txt'
- file = open(filename, 'a')
+ fname = 'pygmynote.txt'
+ file = open(fname, 'a')
file.write('%s\t%s\t[%s]\t%s\n' % (row[0], row[1], row[2], row[3]))
file.close()
print '\nRecords have been saved in the pygmynote.txt file.'
View
76 pygmynote3.py
@@ -96,7 +96,7 @@ def escapechar(sel):
conn.commit()
print ("Today\"s deadlines:")
-cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due = '" + today + "' AND type <> 'H' ORDER BY id ASC")
+cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due = '" + today + "' AND type <> '0' ORDER BY id ASC")
for row in cursor:
print ("\n%s -- \033[1;32m%s\033[1;m %s \033[1;30m[%s]\033[1;m" % (row[0], row[1], row[2], row[3]))
@@ -131,38 +131,38 @@ def escapechar(sel):
# Insert new record
- notetext = escapechar(input('Note: '))
- notetags = escapechar(input('Tags: '))
- notedue = input('Due date (yyyy-mm-dd). Press Enter to skip: ')
- notetype = 'A'
+ ntext = escapechar(input('Note: '))
+ ntags = escapechar(input('Tags: '))
+ ndue = input('Due date (yyyy-mm-dd). Press Enter to skip: ')
+ nstatus = '1'
sqlquery = \
"INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')"\
- % (notetext, notedue, notetags, notetype)
+ % (ntext, ndue, ntags, nstatus)
cursor.execute(sqlquery)
conn.commit()
print ('\nRecord has been added.')
elif command == 'f':
# Insert new record with file
- notetext = escapechar(input('Note: '))
- notetags = escapechar(input('Tags: '))
+ ntext = escapechar(input('Note: '))
+ ntags = escapechar(input('Tags: '))
notefile = escapechar(input('Enter path to file: '))
- notetype='A'
+ nstatus='1'
f=open(notefile.rstrip(), 'rb')
ablob = f.read()
f.close()
- cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + notetext + "', '" + notetags + "', '" + notetype + "', '" + notefile[-3:] + "', ?)", [sqlite.Binary(ablob)])
+ cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + ntext + "', '" + ntags + "', '" + nstatus + "', '" + notefile[-3:] + "', ?)", [sqlite.Binary(ablob)])
conn.commit()
print ('\nRecord has been added.')
elif command == 's':
# Save file
- recordid = input('Record id: ')
- outputfile=input('Specify full path and file name (e.g., /home/user/loremipsum.odt): ')
- f=open(outputfile, 'wb')
- cursor.execute ("SELECT file FROM notes WHERE id='" + recordid + "'")
+ recid = input('Record id: ')
+ outfile=input('Specify full path and file name (e.g., /home/user/loremipsum.odt): ')
+ f=open(outfile, 'wb')
+ cursor.execute ("SELECT file FROM notes WHERE id='" + recid + "'")
ablob = cursor.fetchone()
f.write(ablob[0])
f.close()
@@ -173,9 +173,9 @@ def escapechar(sel):
# Search records by note
- notetext = input('Search notes for: ')
+ ntext = input('Search notes for: ')
cursor.execute("SELECT id, note, tags FROM notes WHERE note LIKE '%"
- + notetext + "%'ORDER BY id ASC")
+ + ntext + "%'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]))
@@ -187,9 +187,9 @@ def escapechar(sel):
# Search records by tag
- searchtag = input ('Search by tag: ')
+ stag = input ('Search by tag: ')
cursor.execute("SELECT id, note, tags FROM notes WHERE tags LIKE '%"
- + searchtag + "%' AND type='A' ORDER BY id ASC")
+ + 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]))
@@ -201,9 +201,9 @@ def escapechar(sel):
# Show private records
- searchtag = 'private'
+ stag = 'private'
cursor.execute("SELECT id, note, tags FROM notes WHERE tags LIKE '%"
- + searchtag + "%' AND type='A' ORDER BY id ASC")
+ + 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]))
@@ -215,7 +215,7 @@ def escapechar(sel):
# Show active records
- cursor.execute("SELECT id, note, tags FROM notes WHERE type='A' ORDER BY id ASC")
+ cursor.execute("SELECT id, note, tags FROM notes WHERE 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]))
@@ -227,7 +227,7 @@ def escapechar(sel):
# Show hidden records
- cursor.execute("SELECT id, note, tags FROM notes WHERE type='H' ORDER BY id ASC")
+ cursor.execute("SELECT id, note, tags FROM notes WHERE type='0' 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]))
@@ -239,36 +239,36 @@ def escapechar(sel):
# Update note
- recordid = input('Record id: ')
- notetype = input('Update note (n), tags (t), due date (d), or mark as hidden (h): ')
- if notetype == 'n':
- cursor.execute ("SELECT id, note FROM notes WHERE id='" + recordid + "'")
+ recid = input('Record id: ')
+ nstatus = input('Update note [0], tags [1], due date [2], or archive [3]: ')
+ if nstatus == '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)
cursor.execute("UPDATE notes SET note='" + sqlstr
- + "' WHERE id='" + recordid + "'")
- elif notetype == 't':
+ + "' WHERE id='" + recid + "'")
+ elif nstatus == '1':
tagupdate = input('Tags: ')
sqlstr = escapechar(tagupdate)
cursor.execute("UPDATE notes SET tags='" + sqlstr
- + "' WHERE id='" + recordid + "'")
- elif notetype == 'd':
+ + "' WHERE id='" + recid + "'")
+ elif nstatus == '2':
dueupdate = input('Due date: ')
cursor.execute("UPDATE notes SET due='" + dueupdate
- + "' WHERE id='" + recordid + "'")
+ + "' WHERE id='" + recid + "'")
else:
- notetype = 'H'
- cursor.execute("UPDATE notes SET type='" + notetype
- + "' WHERE id='" + recordid + "'")
+ nstatus = '0'
+ cursor.execute("UPDATE notes SET type='" + nstatus
+ + "' WHERE id='" + recid + "'")
conn.commit()
print ('\nRecord has been updated.')
elif command == 'tl':
# Show tasks
- cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due <> '' AND tags NOT LIKE '%private%' AND type = 'A' ORDER BY due ASC")
+ cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due <> '' AND tags NOT LIKE '%private%' AND type = '1' ORDER BY due ASC")
print ("\n-----")
now = datetime.datetime.now()
calendar.prmonth(now.year, now.month)
@@ -282,7 +282,7 @@ def escapechar(sel):
# Show records with attachments
- cursor.execute("SELECT id, note, tags, ext FROM notes WHERE ext <> 'None' AND type='A' ORDER BY id ASC")
+ cursor.execute("SELECT id, note, tags, ext FROM notes WHERE ext <> 'None' 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 \033[1;43m%s\033[1;m' % (row[0], row[1], row[2], row[3]))
@@ -294,8 +294,8 @@ def escapechar(sel):
# Delete note by its ID
- recordid = input('Delete note ID: ')
- cursor.execute("DELETE FROM notes WHERE ID='" + recordid + "'")
+ recid = input('Delete note ID: ')
+ cursor.execute("DELETE FROM notes WHERE ID='" + recid + "'")
print ('\nRecord has been deleted.')
conn.commit()
elif command == 'w':
View
2 sniptopygmynote.py
@@ -24,7 +24,7 @@ def escapechar(sel):
notetext = escapechar(snip)
notedue = ""
-notetype = "A"
+notetype = "1"
sqlquery = \
"INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')"\
% (notetext, notedue, notetags, notetype)

0 comments on commit 23e5e0b

Please sign in to comment.