mirror of
https://github.com/bendtherules/pytry.git
synced 2026-08-18 13:53:01 +00:00
All the previous files
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import time;
|
||||
class note:
|
||||
def __init__(self,note_id,title,contents,tags=[]):
|
||||
self.id=note_id;
|
||||
self.title=title;
|
||||
self.contents=contents;
|
||||
self.tags=tags;
|
||||
self.creationtime=time.localtime();
|
||||
#tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec supported
|
||||
def search(self,term,where=None):
|
||||
''' "term" is the search term.
|
||||
"where" is supported to search for only in title or contents or
|
||||
tags -currently unused.
|
||||
Currently searches for a whole word-better than searching
|
||||
for letters'''
|
||||
#ToDo1 search for the whole string and perfect match .. actually use
|
||||
#option for partial and whole check
|
||||
#ToDO2 make sure all checkings are string type or atleast permissible after notebook class
|
||||
#ToDo3 implement "where" in this function
|
||||
return bool(self.title.split(" ").count(term)) or bool(self.contents.split(" ").count(term)) or bool(self.tags.count(term)) ;
|
||||
def edit(self,title="",contents="",tags=[],choice=1):
|
||||
|
||||
'''Only mention required parameters.Choice must be given. Choice: 1 for replace, 2 for append.
|
||||
Call example:edit(title="untitled",choice=1) will make the title "untitled". Rest unaffected'''
|
||||
if title!="":
|
||||
if choice==1:
|
||||
self.title=title;
|
||||
elif choice==2:
|
||||
self.title+=title;
|
||||
if contents!="":
|
||||
if choice==1:
|
||||
self.contents=contents;
|
||||
elif choice==2:
|
||||
self.contents+=contents;
|
||||
if tags!=[]:
|
||||
if choice==1:
|
||||
self.tags=tags;
|
||||
elif choice==2:
|
||||
self.tags+=tags;
|
||||
self.creationtime=time.localtime();
|
||||
|
||||
def _print_(self,which="all"):
|
||||
#To print the details for debugging purpose..working
|
||||
if which=="all":
|
||||
print ("Id="+str(self.id)+"\nTitle="+self.title+"\ncontents="+self.contents+"\ntags="+str(self.tags)+"\ncreationtime="+str(self.creationtime));
|
||||
else:
|
||||
print which+"=",;# trailing comma(,) is used to print without newline
|
||||
#ToDo3 fix the above print so that a space is not printed between them
|
||||
exec("print(str(self."+which+"))");
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,54 @@
|
||||
import time;
|
||||
class note:
|
||||
def __init__(self,note_id,title,contents,tags=[]):
|
||||
self.id=note_id;
|
||||
self.title=title;
|
||||
self.contents=contents;
|
||||
self.tags=tags;
|
||||
self.creationtime=time.localtime();
|
||||
#tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec supported
|
||||
def search(self,term,where=None):
|
||||
''' "term" is the search term.
|
||||
"where" is supported to search for only in title or contents or
|
||||
tags -currently unused.
|
||||
Currently searches for a whole word-better than searching
|
||||
for letters'''
|
||||
#ToDo1 search for the whole string and perfect match .. actually use
|
||||
#option for partial and whole check
|
||||
#ToDO2 make sure all checkings are string type or atleast permissible after notebook class
|
||||
#ToDo3 implement "where" in this function
|
||||
return bool(self.title.split(" ").count(term)) or bool(self.contents.split(" ").count(term)) or bool(self.tags.count(term)) ;
|
||||
def edit(self,title="",contents="",tags=[],choice=1):
|
||||
|
||||
'''Only mention required parameters.Choice must be given. Choice: 1 for replace, 2 for append.
|
||||
Call example:edit(title="untitled",choice=1) will make the title "untitled". Rest unaffected'''
|
||||
if title!="":
|
||||
if choice==1:
|
||||
self.title=title;
|
||||
elif choice==2:
|
||||
self.title+=title;
|
||||
if contents!="":
|
||||
if choice==1:
|
||||
self.contents=contents;
|
||||
elif choice==2:
|
||||
self.contents+=contents;
|
||||
if tags!=[]:
|
||||
if choice==1:
|
||||
self.tags=tags;
|
||||
elif choice==2:
|
||||
self.tags+=tags;
|
||||
self.creationtime=time.localtime();
|
||||
|
||||
def _print_(self,which="all"):
|
||||
#To print the details for debugging purpose..working
|
||||
if which=="all":
|
||||
print ("Id="+str(self.id)+"\nTitle="+self.title+"\ncontents="+self.contents+"\ntags="+str(self.tags)+"\ncreationtime="+str(self.creationtime));
|
||||
else:
|
||||
print (which+"=",end='');# end='' is used to print without newline
|
||||
exec("print(str(self."+which+"))");
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,25 @@
|
||||
from note import note;
|
||||
class notebook:
|
||||
def __init__(self):
|
||||
self.note_id=0;
|
||||
self.note_list=[];
|
||||
self.counter=0;
|
||||
self.return_list=[];
|
||||
def create_note(self,title,contents,tags=[]):
|
||||
self.note_id+=1;
|
||||
self.note_list.append(note(self.note_id,title,contents,tags));
|
||||
def search(self,term,where=None):
|
||||
self.return_list=[];#used for removing traces of previous search
|
||||
for self.counter in range(self.note_id):#range(x) means to 0 to x-1
|
||||
if self.note_list[self.counter].search(term):
|
||||
self.note_list[self.counter]._print_();#used for debugging
|
||||
self.return_list.append(self.counter+1);#return_list return a list of id's where search is successfull
|
||||
return self.return_list;
|
||||
def open_note(self,id,which="all"):
|
||||
self.note_list[id-1]._print_(which);
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,25 @@
|
||||
from note_32 import note;
|
||||
class notebook:
|
||||
def __init__(self):
|
||||
self.note_id=0;
|
||||
self.note_list=[];
|
||||
self.counter=0;
|
||||
self.return_list=[];
|
||||
def create_note(self,title,contents,tags=[]):
|
||||
self.note_id+=1;
|
||||
self.note_list.append(note(self.note_id,title,contents,tags));
|
||||
def search(self,term,where=None):
|
||||
self.return_list=[];#used for removing traces of previous search
|
||||
for self.counter in range(self.note_id):#range(x) means to 0 to x-1
|
||||
if self.note_list[self.counter].search(term):
|
||||
self.note_list[self.counter]._print_();#used for debugging
|
||||
self.return_list.append(self.counter+1);#return_list return a list of id's where search is successfull
|
||||
return self.return_list;
|
||||
def open_note(self,id,which="all"):
|
||||
self.note_list[id-1]._print_(which);
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,4 @@
|
||||
Whenever possible, version-unspecific code is written.
|
||||
If there is a major incompatibility such that no one syntax will provide the same result in both versions, different version of the code is written.
|
||||
The un-numbered version is supposed to contain 2.7 version specific code during dev time, but from time-to-time it is (if possible) made 3.2 compatible and the version 3.2 is updated (may need slight change).
|
||||
.pyc files are not needed.
|
||||
Reference in New Issue
Block a user