-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoteon
More file actions
executable file
·95 lines (94 loc) · 3.18 KB
/
Copy pathnoteon
File metadata and controls
executable file
·95 lines (94 loc) · 3.18 KB
1
2
3
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
88
89
90
91
92
93
94
#!/usr/bin/env python3
#A simple python script for taking notes from the command line.
#Released Under GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
import sys
import sqlite3
import datetime
now=datetime.datetime.now()
connec=sqlite3.connect('noteon.db')
c=connec.cursor()
#this function can be called either with no arguments or one argument which is the name of the note.
#the function checks to see if note with the name exists,else creates a new note.
def add_notes(name=None):
if name==None:
name=input("enter the name of the note to add:")
t=(name,)
c.execute("select * from note where name=?",t)
if c.fetchone()!=None:
print("A note with that name already exists,please enter another name")
else:
content=input("enter the note contents:")
time=now.strftime("%Y-%M-%D %H:%M")
for t in[(name,content,time)]:
c.execute("insert into note values(?,?,?)",t)
connec.commit()
#lists all the notes which is stored the database
def list_notes():
c.execute("select name,time from note")
row=c.fetchone()
if row!=None:
c.execute('select name,time from note')
for row in c:
print("{0} created on {1}".format(row[0],row[1]))
else:
print("no notes to display")
#This function can be called either with no arguments or one argument which is the name of the note to view.
#The function checks to see if note exists,if it does displays it
def view_notes(name=None):
if name==None:
name=input("enter the name of the note to view:")
t=(name,)
c.execute("select * from note where name=?",t)
if c.fetchone()!=None:
c.execute("select content from note where name=?",t)
for row in c:
print(format(row[0]))
else:
print("no note exists by that name please try again")
#This function can be called either with no arguments or one argument which is the name of the note to delete.
#The function checks to see if the note exiss,if it does deletes it.
def delete_notes(name=None):
if name==None:
name=input("enter the name of the note to delete")
t=(name,)
c.execute("select * from note where name=?",t)
if c.fetchone()!=None:
c.execute("delete from note where name=?",t)
connec.commit()
else:
print("A note by that name does not exist please try again")
#the help is stored in a external file this function prints it to the screen.
def print_help():
f=open("help.txt")
while True:
line=f.readline()
if len(line)==0:
break
print(line,end='')
f.close()
if(len(sys.argv)<2):
print("welcome to noteon a simple tool for taking notes \nUsage:noteon <argv> \nType,noteon help. for a list of arguments")
elif(len(sys.argv)==2):
if(sys.argv[1]=="add"):
add_notes()
elif(sys.argv[1]=="list"):
list_notes()
elif(sys.argv[1]=="view"):
view_notes()
elif(sys.argv[1]=="delete"):
delete_notes()
elif(sys.argv[1]=="help"):
print_help()
else:
print("wrong option typed\n Usage:noteon <argv> \nType,noteon help.for a list of arguments")
elif(len(sys.argv)==3):
if(sys.argv[1]=="add"):
add_notes(sys.argv[2])
elif(sys.argv[1]=="view"):
view_notes(sys.argv[2])
elif(sys.argv[1]=="delete"):
delete_notes(sys.argv[2])
else:
print("wrong usage\nType,noteon help. for a list of arguments")
else:
print("wrong usage\nUsage:noteon <argv>\nType,noteon.py help.for a list of arguments")