-
Notifications
You must be signed in to change notification settings - Fork 4
/
old.py
190 lines (190 loc) · 6.03 KB
/
old.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#
# __author__ = 'Zhongxuan Wang'
# __doc__ = 'iGlossary'
#
# app = Flask(__name__)
# # app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///words.db'
# # Remember, every time you make changes to the column (such as adding one col or removing one col, change the value),
# # you have to do the following: open terminal from pycharm, python3.7, from app import db, db.create_all() and exit.
# # db = SQLAlchemy(app)
# # db.create_all()
#
# datetime_format = '%b-%d-%Y %H:%M'
#
# '''
# This part requires your email information in order to receive email notifications. (This is left blank intentionally)
# '''
# email_account = ''
# email_password = ''
#
# # This is sorely not usable. Just for later inference
#
# class TODO(db.Model):
# id = db.Column(db.Integer, primary_key=True)
# content = db.Column(db.String(500), nullable=False)
#
# time_created = db.Column(db.String, default=time_created_str)
# time_due = db.Column(db.String(500), nullable=False)
#
# # By default, the email warning is disabled
# email_warning = db.Column(db.Integer, default=0)
#
# def __repr__(self):
# return self.id
#
# def __str__(self):
# return self.__repr__()
#
# def get_time_color(self):
# time_dif = self.get_time_difference()
# if time_dif['days'] < 0 or time_dif['seconds'] < 0:
# return 'black'
# elif time_dif['days'] > 30:
# return "#0000ff"
# elif time_dif['days'] > 7:
# return "#0080ff"
# elif time_dif['days'] > 2:
# return '#00ff00'
# elif time_dif['days'] >= 1:
# return '#bfff00'
# # >Half day
# elif time_dif['seconds'] >= 43200:
# return "#ffff00"
# # >3h
# elif time_dif['seconds'] >= 10800:
# send_email(self)
# return "#ffbf00"
# # >1h
# elif time_dif['seconds'] >= 3600:
# send_email(self)
# return "#ff8000"
# else:
# send_email(self)
# return "#ff0000"
#
# def get_time_difference(self):
# return get_time_difference(datetime.strptime(self.time_due.__str__(), datetime_format))
#
#
# '''
# This will return a new date & time that after adding the values in time dictionaries
# '''
#
#
# def get_time(**time):
# # TODO could I optimize those statements using comprehension for?
# for item in ['hour', 'minute', 'day', 'month', 'year']:
# if item not in time:
# time[item] = 0
# time_now = datetime.now() + relativedelta(hours=time['hour'], minutes=time['minute'], days=time['day'],
# months=time['month'], years=time['year'])
# return time_now.strftime(datetime_format)
#
#
# def get_time_difference(time):
# time_now = datetime.now().replace(microsecond=0)
# diff = time - time_now
# return {'days': diff.days, 'seconds': diff.seconds}
#
#
# @app.route('/', methods=['GET', 'POST'])
# def index():
# if request.method == 'POST':
# return redirect('issues/404.html')
# elif request.method == 'GET':
# tasks = TODO.query.order_by(TODO.time_created).all()
# time_now = datetime.now().strftime(datetime_format)
# return render_template("index.html", tasks=tasks, mintime=time_now, maxtime=get_time(year=100),
# display_time=get_time(hour=3))
# else:
# return "Invalid method: " + request.method
#
#
# @app.route('/addTask/<content>/<due_date>', methods=['POST'])
# def addTask(content, due_date):
# if request.method == 'POST':
# # content = request.form['content']
# try:
# datetime.strptime(due_date, datetime_format)
# except:
# print("The time is not in correct format")
# task = TODO(content=content, time_due=due_date)
#
# # Add to database
# try:
# db.session.add(task)
# db.session.commit()
# return redirect('/')
# except:
# print("Unable to add the task")
# else:
# return render_template('issues/unable_to.html', issue="method not applicable")
#
#
# @app.route('/editTask/<int:tid>/<content>/<due_date>/<email_warning>', methods=['POST'])
# def editTask(tid, content, due_date, email_warning):
# task = TODO.query.get_or_404(tid)
#
# # Accessing through form in edit
# task.content = content
# task.time_due = due_date
# task.email_warning = email_warning
#
# try:
# db.session.commit()
# return redirect('/')
# except:
# print("Unable to edit the task")
#
#
# @app.route('/editTask/<int:tid>', methods=['GET'])
# def edit_task_jump(tid):
# return render_template('edit.html', task=TODO.query.get_or_404(tid), maxtime=get_time(year=100))
#
#
# @app.route('/cmTask/<int:tid>', methods=['GET'])
# def cmTask(tid):
# if request.method == 'GET':
# task = TODO.query.get_or_404(tid)
#
# try:
# db.session.delete(task)
# db.session.commit()
# return redirect('/')
# except:
# return render_template('issues/unable_to.html', issue='complete the task')
# else:
# return render_template('issues/unable_to.html', issue="method not applicable")
#
#
# @app.route('/setting/<email_add>', methods=['POST'])
# def setting(email_add):
# write_file('email.cfg', email_add)
# return ''
#
#
# @app.route('/setting/', methods=['GET'])
# def setting_redirect():
# email = '' + read_file('email.cfg')
# return render_template('setting.html', email=email)
#
#
# def read_file(filename):
# try:
# with open(filename) as f:
# return f.readline()
# except IOError:
# print("IO ERROR Raised. Reading file failed,")
# f = open(filename, "w")
# f.write('email@example.com')
# f.close()
# return 'content'
#
#
# def write_file(filename, file_content):
# try:
# with open(filename, 'w') as f:
# f.write(file_content)
# except IOError:
# print("IO ERROR Raised. Writing file failed,")
# return ''