-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
113 lines (79 loc) · 2.04 KB
/
app.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from flask import Flask, render_template, request, redirect
import datetime
import os
app = Flask(__name__)
@app.route("/")
def homepage():
try:
f = open("tasks.txt", "r")
except IOError:
os.system("touch tasks.txt")
f = open("tasks.txt", "r")
try:
cal = open("cal.txt", "r")
except IOError:
os.system("touch cal.txt")
cal = open("cal.txt", "r")
try:
dia = open("dairy.txt", "r")
except IOError:
os.system("touch dairy.txt")
dia = open("dairy.txt", "r")
f = f.read()
f = f.split(".")
# events = [list(i.split(',')) for i in cal]
events = []
for i in cal:
a = i.split(',')
events.append([int(a[0]), int(a[1]), a[2]])
Diary = []
for i in dia:
if ":-" in i:
i = i.split(":-")
Diary.append(i)
dia = []
for i in range(len(Diary) - 1, -1, -2):
dia.append(Diary[i - 1])
dia.append(Diary[i])
events.sort(key = lambda row:(row[1],row[0]))
imp = [w[:len(w) - 1] for w in f if w.endswith('@')]
f = [w for w in f if not w.endswith('@')]
return render_template("index.html", tasks = f, imp = imp, events = events, diary = dia)
@app.route("/addtask", methods = ["POST"])
def addtask():
task = request.form['newtask']
f = open("tasks.txt", "a")
f.write("." + task)
f.close()
return redirect("/")
@app.route("/addcalevent", methods = ["POST"])
def addcalevent():
cal = open("cal.txt", "a")
date = request.form['date']
month = request.form['month']
event = request.form['event']
cal.write(date + ", " + month + ", " + event + "\n")
return redirect("/")
@app.route("/del/<task>")
def delete(task):
f = open("tasks.txt", "r")
f = f.read()
tasks = f.split(".")
tasks.remove(task)
# f.close()
f = open("tasks.txt", "w")
f.write(".".join(tasks))
f.close()
return redirect("/")
@app.route("/adddiary",methods = ['POST'])
def diary():
dia = open("dairy.txt", 'a')
now = str(datetime.datetime.now())
# now = ""
tag = request.form['tag']
today = request.form['today']
dia.write(now + "\n" + tag + ":- " + today + "\n")
dia.close()
return redirect("/")
if __name__ == "__main__":
app.run(debug = True)