Exemple #1
0
def add_todo():
	home_dir = str(Path.home())
	conn = sqlite3.connect(home_dir + "/task.db")
	cur = conn.cursor()

	sql = "insert into todo (what, due, importance, category, finished) values (?, ?, ?, ?, ?)"

	while True:
		what = str(input("What? "))
		if what != '':
			break

	while True:
		due = str(input("Due? (yyyy-mm-dd hh:mm:ss) "))
		if dc.isdue(due):
			break
		elif due == '':
			due = '0000-00-00 00:00:00'
			break
		else:
			print('Invaild input! Please check your input')

	while True:
		importance = str(input("Importance? (1 ~ 5) "))
		if importance == '':
			importance = 0
			break
		elif importance.isdigit() and 1 <= int(importance) <= 5:
			break
		else:
			print('Invaild input! Please check your input')

	category = str(input("Category? "))
	if category == '':
		category = 'GENERAL'

	data = [what, due, int(importance), category, 'n']

	cur.execute(sql, data)
	conn.commit()

	print("")
Exemple #2
0
def cmd_line():
	"""Usr inputs option among -a(add todo), -l(list todo), -m(modify todo), -d(delete todo), -c(show category)"""

	usage = "Usage: %prog [options]"
	parser = OptionParser(usage=usage, version="%prog 0.0.5")
	parser.add_option("-a", dest="add", action='store', type=str, default=False, help="add a new todo",
						metavar="[what] [due(yyyy-mm-dd hh:mm:ss)] [importance(0~5)] [category]")
	parser.add_option("-l", dest="list", action='store', type=str, default=False, help="list todos by option",
						metavar="what || due || importance || category [category]")
	parser.add_option("-m", dest="modify", action='store', type=str, default=False, help="modify the todo",
						metavar="[org_what] [what] [due(yyyy-mm-dd hh:mm:ss)] [importance(0~5)] [category] [finished(y/n)]")
	parser.add_option("-d", dest="delete", action='store', type=str, default=False, help="delete the todo",
						metavar="[what]")
	parser.add_option("-c", dest="category", action='store_true', default=False, help="show categories")

	options, args = parser.parse_args()

	# no option
	if len(args) == 0 and not (options.add or options.list or options.modify or options.delete or options.category):
		lg.print_logo()
		run_program()

	if options.add:
		sql = "insert into todo (what, due, importance, category, finished) values (?, ?, ?, ?, ?)"
		what, due, importance, category = options.add, args[0]+" "+args[1], args[2], args[3]
		if not dc.isdue(due):
			print('Invaild input! Please check your input(yyyy-mm-dd hh:mm:ss)')
			exit()
		data = [what, due, importance, category, "n"]
		cur.execute(sql, data)
		print("ADDED")
		conn.commit()

	if options.list:
		op = options.list
		if op == 'what':
			li.list_todo_what()
		elif op == 'due':
			li.list_todo_due()
		elif op == 'importance':
			li.list_todo_importance()
		elif op == 'category':
			# check whether category is exsited in todo table
			c = args[0]
			cmp_data = "select distinct category from todo"
			cur.execute(cmp_data)
			cmp_records = cur.fetchall()
			cmp_list = []
			for i in range(len(cmp_records)):
				cmp_list.append(cmp_records[i][0])
			if not c in cmp_list:
				print("There is not", c)
			li.list_todo_category(c)

	if options.modify:
		modify_data = options.modify
		# check whether there is the modify val in table
		chk_is_there(modify_data)

		what, due, importance, category, finished = args[0], args[1]+" "+args[2], args[3], args[4], args[5]
		sql = "update todo set what = ?, due = ?, importance = ?, category = ?, finished = ? where what = ?"
		cur.execute(sql, [what, due, int(importance), category, finished, modify_data])
		print("MODIFIED")
		conn.commit()

	if options.delete:
		delete_data = options.delete
		# check whether there is the delete_data val in table
		chk_is_there(delete_data)

		del_record = "delete from todo where what = ?"
		cur.execute(del_record, [delete_data])
		print("DELETED")
		conn.commit()

	if options.category:
		ctg.show_category()
Exemple #3
0
def modify_todo():
    home_dir = str(Path.home())
    conn = sqlite3.connect(home_dir + "/task.db")
    cur = conn.cursor()

    slct_data = "select * from todo where 1 order by finished asc, what asc"
    cur.execute(slct_data)
    records = cur.fetchall()
    li.print_list(records)

    modify = str(
        input("What todo do you want to modify? Please enter 'what' "))

    # check whether there is the modify val in table
    cmp_data = "select distinct what from todo"
    cur.execute(cmp_data)
    cmp_records = cur.fetchall()
    cmp_list = []
    for i in range(len(cmp_records)):
        cmp_list.append(cmp_records[i][0])
    while True:
        if not modify in cmp_list:
            modify = str(
                input("There is not" + ' \'' + modify + '\' ' +
                      "Please enter the 'what' in table"))
        else:
            break

    org_data = "select * from todo where what = ?"
    cur.execute(org_data, [modify])
    org_record = cur.fetchall()
    # table col : id, what, due, importance, category, finished

    what_m = str(input("What? "))
    if what_m == '':
        what_m = org_record[0][1]

    while True:
        due_m = str(input("Due? (yyyy-mm-dd hh:mm:ss) "))
        if dc.isdue(due_m):
            break
        elif due_m == '':
            due_m = org_record[0][2]
            break
        else:
            print('Invaild input! Please check your input')

    while True:
        importance_m = str(input("Importance? (1 ~ 5) "))
        if importance_m == '':
            importance_m = org_record[0][3]
            break
        elif importance_m.isdigit() and 1 <= int(importance_m) <= 5:
            break
        else:
            print('Invaild input! Please check your input')

    category_m = str(input("Category? "))

    if category_m == '':
        category_m = org_record[0][4]

    while True:
        finished_m = str(input("Finished (y: yes, n: no)? "))
        if finished_m == '':
            finished_m = org_record[0][5]
            break
        elif finished_m == 'y' or finished_m == 'n':
            break
        else:
            print('Invaild input! Please check your input')

    sql = "update todo set what = ?, due = ?, importance = ?, category = ?, finished = ? where what = ?"

    cur.execute(
        sql,
        [what_m, due_m,
         int(importance_m), category_m, finished_m, modify])
    conn.commit()
    print("")