Inital Commit.
This commit is contained in:
parent
90328d6950
commit
7e994b220f
11 changed files with 162 additions and 0 deletions
3
commands.sql
Normal file
3
commands.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO "main"."todo"("ID","TODO","CREATION_DATE","DUE_DATE","PRIO","IMP") VALUES (NULL,'example task 1','1711408035','1711408095',100,0);
|
||||
INSERT INTO "main"."todo"("ID","TODO","CREATION_DATE","DUE_DATE","PRIO","IMP") VALUES (NULL,'example task 2','1711408035','1711408095',100,0);
|
||||
INSERT INTO "main"."todo"("ID","TODO","CREATION_DATE","DUE_DATE","PRIO","IMP") VALUES (NULL,'example task 3','1711408035','1711408095',100,0);
|
2
create_db.sh
Executable file
2
create_db.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
sqlite3 todo.db ".read create_db.sql"
|
||||
echo created database
|
10
create_db.sql
Normal file
10
create_db.sql
Normal file
|
@ -0,0 +1,10 @@
|
|||
CREATE TABLE "todo" (
|
||||
"ID" INTEGER UNIQUE,
|
||||
"TODO" TEXT NOT NULL,
|
||||
"CREATION_DATE" INTEGER NOT NULL,
|
||||
"DUE_DATE" INTEGER NOT NULL,
|
||||
"PRIO" INTEGER NOT NULL,
|
||||
"IMP" INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY("ID" AUTOINCREMENT)
|
||||
);
|
2
db_to_csv.sh
Executable file
2
db_to_csv.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
rm -v input.csv
|
||||
sqlite3 todo.db 'SELECT * FROM todo;' -csv> db.csv
|
3
dump.txt
Normal file
3
dump.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
example task 1
|
||||
example task 2
|
||||
example task 3
|
30
fresh_db.sh
Executable file
30
fresh_db.sh
Executable file
|
@ -0,0 +1,30 @@
|
|||
sqlite3 todo.db "DROP TABLE todo;"
|
||||
sqlite3 todo.db ".read create_db.sql"
|
||||
echo created database
|
||||
#!/bin/bash
|
||||
rm commands.sql -v
|
||||
# File to read
|
||||
file="dump.txt"
|
||||
|
||||
# Counter for line number
|
||||
line_number=1
|
||||
|
||||
# Read each line of the file
|
||||
while IFS= read -r line; do
|
||||
# Store the line in a variable
|
||||
variable_name="line_$line_number"
|
||||
declare "$variable_name"="$line"
|
||||
|
||||
# Increment the line number counter
|
||||
((line_number++))
|
||||
done < "$file"
|
||||
|
||||
# Print the variables to verify
|
||||
for ((i=1; i<line_number; i++)); do
|
||||
var="line_$i"
|
||||
date=$(date +%s)
|
||||
echo "INSERT INTO \"main\".\"todo\"(\"ID\",\"TODO\",\"CREATION_DATE\",\"DUE_DATE\",\"PRIO\",\"IMP\") VALUES (NULL,'${!var}','$date','$(($date+60))',100,0);" >> commands.sql
|
||||
done
|
||||
echo converted $file to sql statements
|
||||
sqlite3 todo.db ".read commands.sql"
|
||||
echo inserted sql statements to database
|
68
main.py
Normal file
68
main.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
import sqlite3
|
||||
from datetime import datetime
|
||||
import time
|
||||
import tkinter as tk
|
||||
|
||||
con = sqlite3.connect("todo.db")
|
||||
cur = con.cursor()
|
||||
|
||||
|
||||
def add_item():
|
||||
item = entry.get()
|
||||
if item:
|
||||
listbox.insert(tk.END, item)
|
||||
entry.delete(0, tk.END) # deletes input
|
||||
|
||||
|
||||
def remove_item():
|
||||
selected_index = listbox.curselection()
|
||||
if selected_index:
|
||||
listbox.delete(selected_index)
|
||||
|
||||
|
||||
def update_list():
|
||||
cur_time = (datetime.now() - datetime(1970, 1, 1)).total_seconds() + time.timezone
|
||||
|
||||
total_time = []
|
||||
remaining_time = []
|
||||
importance = []
|
||||
|
||||
res = cur.execute("SELECT * FROM todo").fetchall()
|
||||
for i, tmp1 in enumerate(res):
|
||||
total_time.append(res[i][3] - res[i][2])
|
||||
remaining_time.append(res[i][3] - cur_time)
|
||||
importance.append(total_time[i] / remaining_time[i] * res[i][4])
|
||||
if int(importance[i]) == 0:
|
||||
importance[i] = 1
|
||||
print("UPDATE todo SET IMP = %s WHERE ID = %s" % (int(importance[i]), i + 1))
|
||||
cur.execute("UPDATE todo SET IMP = %s WHERE ID = %s" % (int(importance[i]), i + 1))
|
||||
print(i)
|
||||
listbox.insert(tk.END, res[i][0])
|
||||
con.commit()
|
||||
|
||||
|
||||
# Create the main window
|
||||
root = tk.Tk()
|
||||
root.title("Ion-Todo-Planner")
|
||||
|
||||
# Create a listbox to display the items
|
||||
listbox = tk.Listbox(root, width=100)
|
||||
listbox.pack(padx=5, pady=5)
|
||||
|
||||
|
||||
# Create an entry for adding items
|
||||
entry = tk.Entry(root, width=50)
|
||||
entry.pack(padx=10, pady=5)
|
||||
|
||||
# Create buttons to add and remove items
|
||||
add_button = tk.Button(root, text="Add", command=add_item)
|
||||
add_button.pack(side=tk.LEFT, padx=5, pady=5)
|
||||
|
||||
remove_button = tk.Button(root, text="Remove", command=remove_item)
|
||||
remove_button.pack(side=tk.LEFT, padx=5, pady=5)
|
||||
|
||||
update_button = tk.Button(root, text="Update", command=update_list)
|
||||
update_button.pack(padx=5, pady=5)
|
||||
|
||||
# Run the Tkinter event loop
|
||||
root.mainloop()
|
16
sample.py
Normal file
16
sample.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
# This is a sample Python script.
|
||||
|
||||
# Press Shift+F10 to execute it or replace it with your code.
|
||||
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
||||
|
||||
|
||||
def print_hi(name):
|
||||
# Use a breakpoint in the code line below to debug your script.
|
||||
print(f'Hi, {name}') # Press Ctrl+8 to toggle the breakpoint.
|
||||
|
||||
|
||||
# Press the green button in the gutter to run the script.
|
||||
if __name__ == '__main__':
|
||||
print_hi('PyCharm')
|
||||
|
||||
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
BIN
todo.db
Normal file
BIN
todo.db
Normal file
Binary file not shown.
25
txt_to_cmd.sh
Executable file
25
txt_to_cmd.sh
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
rm commands.sql -v
|
||||
# File to read
|
||||
file="dump.txt"
|
||||
|
||||
# Counter for line number
|
||||
line_number=1
|
||||
|
||||
# Read each line of the file
|
||||
while IFS= read -r line; do
|
||||
# Store the line in a variable
|
||||
variable_name="line_$line_number"
|
||||
declare "$variable_name"="$line"
|
||||
|
||||
# Increment the line number counter
|
||||
((line_number++))
|
||||
done < "$file"
|
||||
|
||||
# Print the variables to verify
|
||||
for ((i=1; i<line_number; i++)); do
|
||||
var="line_$i"
|
||||
date=$(date +%s)
|
||||
echo "INSERT INTO \"main\".\"todo\"(\"ID\",\"TODO\",\"CREATION_DATE\",\"DUE_DATE\",\"PRIO\",\"IMP\") VALUES (NULL,'${!var}','$date','$(($date+60))',100,0);" >> commands.sql
|
||||
done
|
||||
echo converted $file to sql statements
|
3
write_cmd_to_db.sh
Executable file
3
write_cmd_to_db.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
sqlite3 todo.db ".read commands.sql"
|
||||
echo inserted sql statements to database
|
||||
rm commands.sql -v
|
Reference in a new issue