123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- from colorama import Fore, Back, Style
- from prettytable import PrettyTable
- from datetime import datetime
- import sqlite3
- import json
- import os
- _print = None
- userInput = None
- SLM = ('''
- mmmm m m m
- #" " # ## ##
- "#mmm # # ## #
- "# # # "" #
- "mmm#" #mmmmm # #
- ''')
- connDB = sqlite3.connect( 'base.sql' )
- cursor = connDB.cursor()
- with open('userConfig.json', 'r') as jsf:
- config = json.load(jsf)
- language = config["language"]
- with open('./defaultConfigs/language/' + language + '.json', 'r') as f:
- config = json.load(f)
- help_c = config["help_c"]
- f_n = config ["f_n"]
- update = config["update"]
- areYouSure_c = config ["areYouSure_c"]
- bye = config["bye"]
- delmenu_c = config["delmenu_c"]
- help_c = help_c["work_mode"] + '\n' + Fore.GREEN + help_c["read"] + Fore.BLUE + '\n' + help_c["write"] + Fore.YELLOW + '\n'+ help_c["update"] + Fore.MAGENTA + '\n' + help_c["deleteAll"] + '\n'+ Fore.RED + help_c["exit"] + Fore.RESET
- enter = '>SLM>'
- inpt = 'input> '
- delmenu = 'delMenu> '
- upmenu = 'upMenu> '
- def upDate(userInput, _print):
- print( 'test help' )
- while True:
- _print = str( input( enter + upmenu ) )
- if _print != 'q':
- if _print == 'Execute':
- checkUp(_print)
- elif _print == 'Edit':
- changeContent(userInput, _print)
- elif _print == 'Group':
- egitGroup(userInput, _print)
- elif _print == 'q':
- break
- else:
- print( 'Unknown command: ' + _print + '\n' +'Enter \'help\'' )
- def checkUp(_print):
- read()
- _print = str(input( update["stt"] ))
- toBase = [(_print)]
- cursor.execute(' UPDATE notes SET status = 1 WHERE id = ? ', toBase )
- connDB.commit()
- def changeContent(userInput, _print):
- read()
- _print = str(input( update["changeContent"] ))
- userInput = str(input( update["toChangeContent"] ))
- toBase = [userInput, _print]
- cursor.execute(' UPDATE notes SET content = ? WHERE id = ? ', toBase )
- connDB.commit()
- def egitGroup(userInput, _print):
- read()
- _print = str(input( update["changeContent"] ))
- userInput = str(input( update["group"] ))
- toBase = [userInput, _print]
- cursor.execute(' UPDATE notes SET groups = ? WHERE id = ? ', toBase )
- connDB.commit()
- def timer(userInput, _print):
- read()
-
- def editTimer(userInput, _print):
- pass
- def delMenu(_print):
- print( 'test help' )
- while True:
- _print = str( input( enter + delmenu ) )
- if _print != 'q':
- if _print == 'del':
- delete(_print)
- elif _print == 'delAll':
- deleteAll(_print)
- elif _print == 'q':
- break
- else:
- print( 'Unknown command: ' + _print + '\n' +'Enter \'help\'' )
- def delete(_print):
- read()
-
- _print = str(input( delmenu_c['delete_c'] ))
- toBase = [(_print)]
- cursor.execute(' DELETE FROM notes WHERE id = ? ', toBase)
- connDB.commit()
- def deleteAll(_print):
- areYouSure = str( input( areYouSure_c ) )
- if areYouSure == 'yes':
- cursor.execute(' DELETE FROM notes ')
- connDB.commit()
- else:
- pass
- def read():
- table = PrettyTable()
- cursor.execute(' SELECT * FROM notes WHERE status = 0 ')
- result = cursor.fetchall()
- table.field_names = [ f_n['id'], f_n['content'], f_n['time'], f_n['date'], f_n['status'], f_n['group'] ]
- for item in result:
- table.add_row( [ item[0], item[1], item[2], item[3], item[5], item[4] ] )
- table.align = 'c'
- table.align['Id'] = 'r'
- print( table )
- def write(userInput):
- while True:
- userInput = str( input( enter + inpt ) )
- if userInput != 'q':
- time = str(input( config["time"] ))
- date = str(input( config["date"] ))
-
- if time == '':
- time = '---'
- if date == '':
- date = '---'
-
-
-
- status = False
- toBase = [(userInput, date, time, status)]
- cursor.executemany(' INSERT INTO notes ( content, date, time, status ) VALUES ( ?, ?, ?, ? )', toBase )
- connDB.commit()
- elif userInput == 'q':
- break
- else:
- pass
- def clearShell():
- os.system(['clear'][os.name == os.sys.platform])
- def helper():
- print( help_c )
- def menu(_print, userInput):
- while True:
- _print = input( enter )
- if _print == 'r':
- read()
- elif _print == 'w':
- write(userInput)
- elif _print == 'd':
- delMenu(_print)
- elif _print == 'u':
- upDate(userInput, _print)
- elif _print == 'q':
- break
- elif _print == 'help':
- helper()
- elif _print == 'clear':
- clearShell()
- else:
- print( 'Unknown command: ' + _print + '\n' +'Enter \'help\'' )
- clearShell()
- print( Fore.GREEN + config["welkome"] + Fore.RESET )
- print( help_c )
- menu(_print, userInput)
- connDB.close()
- clearShell()
- print( bye + '\n' + SLM )
|