]> Softwares of Agnibho - librevax.git/blob - librevax.py
ab1420fc75d8bf1c166d314e19bc948ed1f126e1
[librevax.git] / librevax.py
1 # LibreVax
2 # Copyright (C) 2024 Dr. Agnibho Mondal
3 # This file is part of LibreVax.
4 # LibreVax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5 # LibreVax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6 # You should have received a copy of the GNU General Public License along with LibreVax. If not, see <https://www.gnu.org/licenses/>.
7
8 from flask import Flask, render_template, request, session, redirect, g
9 from urllib.parse import urlencode
10 from datetime import datetime
11 import json, sqlite3
12 import advice, auth, inventory, multicenter, patient, personnel, transaction, vaccination
13
14 app=Flask(__name__)
15 app.config.from_file("config/config.json", load=json.load)
16
17 @app.before_request
18 def preload():
19 g.user=session.get("user", None)
20 g.mid=session.get("mid", None)
21 g.center=session.get("center", None)
22 g.enable_delete=app.config.get("ENABLE_DELETE", False)
23
24 @app.route("/")
25 def index():
26 try:
27 if((ret:=problem())!="go"):
28 return ret
29 cursor=get_db().cursor()
30 (ok, mc)=multicenter.read(cursor, session["mid"])
31 if(not ok):
32 raise exception(mc)
33 (ok, pat)=patient.list(cursor)
34 if(not ok):
35 raise exception(pat)
36 return render_template("index.html", center=mc, patient=pat)
37 except Exception as e:
38 raise(e)
39 return render_template("error.html", data=e)
40
41 @app.get("/login")
42 def login_get(error=False):
43 try:
44 cursor=get_db().cursor()
45 (ok, data)=multicenter.list(cursor)
46 if(not ok):
47 raise exception(data)
48 if(len(data)<=0):
49 data.append("")
50 return render_template("login.html", data=data, error=error)
51 except Exception as e:
52 return render_template("error.html", data=e)
53
54 @app.post("/login")
55 def login_post():
56 cursor=get_db().cursor()
57 if(auth.login(cursor, request.form["user"], request.form["password"], request.form["center"])):
58 return redirect("/")
59 else:
60 return login_get(True)
61
62 @app.route("/logout")
63 def logout():
64 auth.logout()
65 return redirect("/login")
66
67 @app.get("/admin")
68 def admin(msg=None):
69 cursor=get_db().cursor()
70 (ok, mc)=multicenter.list(cursor)
71 if(not ok):
72 raise Exception(mc)
73 users=auth.list(cursor)
74 return render_template("admin.html", users=users, center=mc, msg=msg)
75
76 @app.post("/newuser")
77 def newuser():
78 try:
79 cursor=get_db().cursor()
80 if(auth.new(cursor, request.form["user"], request.form["pwd"])):
81 return admin(msg="New user added")
82 else:
83 return admin(msg="Failed to add")
84 except Exception as e:
85 raise(e)
86 return render_template("error.html", data=e)
87
88 @app.post("/changepass")
89 def changepass():
90 try:
91 cursor=get_db().cursor()
92 if("user" in request.form.keys()):
93 if(auth.change(cursor, request.form["user"], request.form["new"])):
94 return admin(msg="Password changed")
95 else:
96 return admin(msg="Incorrect Password")
97 elif(request.form["new"]==request.form["check"]):
98 user=request.form.get("user", session["user"])
99 if(auth.change(cursor, user, request.form["new"], request.form["old"])):
100 return admin(msg="Password changed")
101 else:
102 return admin(msg="Incorrect Password")
103 else:
104 return admin(msg="Failed to change password")
105 except Exception as e:
106 raise(e)
107 return render_template("error.html", data=e)
108
109 @app.post("/switchcenter")
110 def switchcenter():
111 try:
112 cursor=get_db().cursor()
113 if(auth.switch(cursor, request.form)):
114 return admin(msg="Switched center to "+g.center)
115 else:
116 raise Exception("Failed to switch")
117 except Exception as e:
118 raise(e)
119 return render_template("error.html", data=e)
120
121 @app.get("/center/<action>")
122 @app.get("/center/<action>/<mid>")
123 def center_view(action, mid=None):
124 if((ret:=problem())!="go"):
125 return ret
126 try:
127 cursor=get_db().cursor()
128 if(action=="list"):
129 (ok, data)=multicenter.list(cursor)
130 if(not ok):
131 raise exception(data)
132 return render_template("multicenter-view.html", data=data, action=action)
133 elif(action=="view"):
134 if(mid is not None):
135 (ok, data)=multicenter.read(cursor, mid)
136 if(not ok):
137 raise Exception(data)
138 (ok, invt)=inventory.list(cursor, mid)
139 if(not ok):
140 raise Exception(invt)
141 (ok, pers)=personnel.list(cursor, mid)
142 if(not ok):
143 raise Exception(pers)
144 return render_template("multicenter-view.html", data=data, inventory=invt, personnel=pers, action=action)
145 else:
146 raise Exception("Invalid parameter")
147 elif(action=="edit"):
148 if(mid is not None):
149 (ok, data)=multicenter.read(cursor, mid)
150 if(not ok):
151 raise Exception(data)
152 return render_template("multicenter-edit.html", data=data, action=action)
153 else:
154 raise Exception("Invalid parameter")
155 elif(action=="new"):
156 return render_template("multicenter-edit.html", data=[], action=action)
157 except Exception as e:
158 raise(e)
159 return render_template("error.html", data=e)
160
161 @app.get("/personnel/<action>")
162 @app.get("/personnel/<action>/<sid>")
163 def personnel_view(action, sid=None):
164 if((ret:=problem())!="go"):
165 return ret
166 try:
167 cursor=get_db().cursor()
168 if(action=="list"):
169 (ok, data)=personnel.list(cursor, g.mid)
170 if(not ok):
171 raise exception(data)
172 return render_template("personnel-view.html", data=data, action=action)
173 elif(action=="view"):
174 if(sid is not None):
175 (ok, data)=personnel.read(cursor, sid)
176 if(not ok):
177 raise Exception(data)
178 return render_template("personnel-view.html", data=data, action=action)
179 else:
180 raise Exception("Invalid parameter")
181 elif(action=="edit"):
182 if(sid is not None):
183 (ok, data)=personnel.read(cursor, sid)
184 if(not ok):
185 raise Exception(data)
186 (ok, center)=multicenter.list(cursor)
187 if(not ok):
188 raise Exception(center)
189 return render_template("personnel-edit.html", data=data, center=center, action=action)
190 else:
191 raise Exception("Invalid parameter")
192 elif(action=="new"):
193 (ok, center)=multicenter.list(cursor)
194 if(not ok):
195 raise Exception(center)
196 return render_template("personnel-edit.html", data=[], center=center, action=action)
197 except Exception as e:
198 raise(e)
199 return render_template("error.html", data=e)
200
201 @app.post("/personnel/new")
202 @app.post("/personnel/edit/<sid>")
203 def personnel_edit(sid=None):
204 if((ret:=problem())!="go"):
205 return ret
206 try:
207 cursor=get_db().cursor()
208 if(sid is None):
209 active="active" in request.form.keys()
210 (ok, data)=personnel.create(cursor, request.form, active)
211 if(not ok):
212 raise Exception(data)
213 sid=data
214 else:
215 active="active" in request.form.keys()
216 (ok, data)=personnel.update(cursor, sid, request.form, active)
217 if(not ok):
218 raise Exception(data)
219 return redirect("/personnel/view/"+str(sid))
220 except Exception as e:
221 return render_template("error.html", data=e)
222
223 @app.post("/center/new")
224 @app.post("/center/edit/<mid>")
225 def center_edit(mid=None):
226 if((ret:=problem())!="go"):
227 return ret
228 try:
229 cursor=get_db().cursor()
230 if(mid is None):
231 (ok, data)=multicenter.create(cursor, request.form)
232 if(not ok):
233 raise Exception(data)
234 mid=data
235 else:
236 (ok, data)=multicenter.update(cursor, mid, request.form)
237 if(not ok):
238 raise Exception(data)
239 return redirect("/center/view/"+str(mid))
240 except Exception as e:
241 return render_template("error.html", data=e)
242
243 @app.get("/inventory/<action>")
244 @app.get("/inventory/<action>/<id>")
245 def inventory_view(action, id=None):
246 if((ret:=problem())!="go"):
247 return ret
248 try:
249 cursor=get_db().cursor()
250 if(action=="list"):
251 if(id is not None):
252 (ok, data)=inventory.list(cursor, id)
253 if(not ok):
254 raise exception(data)
255 (ok, center)=multicenter.read(cursor, id)
256 if(not ok):
257 raise exception(center)
258 return render_template("inventory-view.html", data=data, center=center, action=action)
259 else:
260 raise Exception("Invalid parameter")
261 elif(action=="view"):
262 if(id is not None):
263 (ok, data)=inventory.read(cursor, id)
264 if(not ok):
265 raise Exception(data)
266 return render_template("inventory-view.html", data=data, action=action)
267 else:
268 raise Exception("Invalid parameter")
269 elif(action=="edit"):
270 if(id is not None):
271 (ok, data)=inventory.read(cursor, id)
272 if(not ok):
273 raise Exception(data)
274 return render_template("inventory-edit.html", data=data, mid=data["mid"], action=action)
275 else:
276 raise Exception("Invalid parameter")
277 elif(action=="new"):
278 if(id is not None):
279 (ok, center)=multicenter.list(cursor)
280 if(not ok):
281 raise Exception(center)
282 return render_template("inventory-edit.html", data=[], mid=id, action=action, center=center)
283 else:
284 raise Exception("Invalid parameter")
285 except Exception as e:
286 raise(e)
287 return render_template("error.html", data=e)
288
289 @app.post("/inventory/new/<mid>")
290 @app.post("/inventory/edit/<iid>")
291 def inventory_edit(mid=None, iid=None):
292 if((ret:=problem())!="go"):
293 return ret
294 try:
295 cursor=get_db().cursor()
296 if(iid is None):
297 (ok, data)=inventory.create(cursor, request.form)
298 if(not ok):
299 raise Exception(data)
300 iid=data
301 else:
302 (ok, data)=inventory.update(cursor, iid, request.form)
303 if(not ok):
304 raise Exception(data)
305 return redirect("/inventory/view/"+str(iid))
306 except Exception as e:
307 raise(e)
308 return render_template("error.html", data=e)
309
310 @app.get("/patient/<action>")
311 @app.get("/patient/<action>/<pid>")
312 def patient_view(action, pid=None):
313 if((ret:=problem())!="go"):
314 return ret
315 try:
316 cursor=get_db().cursor()
317 if(action=="list"):
318 try:
319 page=int(request.args["page"])
320 except Exception:
321 page=1
322 if(request.args.get("all", False)):
323 (ok, data)=patient.list(cursor, request.args, g.mid)
324 else:
325 (ok, data)=patient.list(cursor, request.args)
326 if(ok):
327 param=dict(request.args)
328 param.pop("page", None)
329 return render_template("patient-list.html", num=app.config["LIST_LENGTH"], data=data, page=page, args=request.args, param=urlencode(param))
330 else:
331 raise Exception(data)
332 elif(action=="view"):
333 if(pid is not None):
334 (ok, data)=patient.read(cursor, pid)
335 if(not ok):
336 raise Exception(data)
337 (ok, vac)=vaccination.list_by_patient(cursor, pid)
338 if(not ok):
339 raise Exception(vac)
340 (ok, adv)=advice.list(cursor, pid)
341 if(not ok):
342 raise Exception(adv)
343
344 return render_template("patient-view.html", data=data, vaccination=vac, advice=adv, action=action)
345 else:
346 raise Exception("Invalid parameter")
347 elif(action=="edit"):
348 if(pid is not None):
349 (ok, data)=patient.read(cursor, pid)
350 if(not ok):
351 raise Exception(data)
352 (ok, center)=multicenter.list(cursor)
353 if(not ok):
354 raise exception(center)
355 return render_template("patient-edit.html", data=data, center=center, action=action)
356 else:
357 raise Exception("Invalid parameter")
358 elif(action=="new"):
359 (ok, last)=patient.last(cursor)
360 if(not ok):
361 raise Exception(last)
362 data={"lastCid": last["cid"]}
363 (ok, center)=multicenter.list(cursor)
364 if(not ok):
365 raise exception(center)
366 return render_template("patient-edit.html", data=data, center=center, action=action)
367 except Exception as e:
368 raise (e)
369 return render_template("error.html", data=e)
370
371 @app.post("/patient/new")
372 @app.post("/patient/edit/<pid>")
373 def patient_edit(pid=None):
374 if((ret:=problem())!="go"):
375 return ret
376 try:
377 cursor=get_db().cursor()
378 if(pid is None):
379 (ok, data)=patient.create(cursor, request.form)
380 if(not ok):
381 raise Exception(data)
382 pid=data
383 else:
384 (ok, data)=patient.update(cursor, pid, request.form)
385 if(not ok):
386 raise Exception(data)
387 return redirect("/patient/view/"+str(pid))
388 except Exception as e:
389 return render_template("error.html", data=e)
390
391 @app.get("/note/<pid>")
392 def note_get(pid):
393 if((ret:=problem())!="go"):
394 return ret
395 try:
396 cursor=get_db().cursor()
397 (ok, data)=patient.read(cursor, pid)
398 if(ok):
399 return render_template("note.html", data=data)
400 else:
401 return render_template("error.html", data=data)
402 except Exception as e:
403 raise(e)
404 return render_template("error.html", data=e)
405
406 @app.post("/note/<pid>")
407 def note_post(pid):
408 if((ret:=problem())!="go"):
409 return ret
410 try:
411 cursor=get_db().cursor()
412 (ok, data)=patient.note(cursor, pid, request.form)
413 if(not ok):
414 return render_template("error.html", data=data)
415 return redirect("/patient/view/"+str(pid))
416 except Exception as e:
417 raise(e)
418 return render_template("error.html", data=e)
419
420 @app.get("/vaccination/<action>")
421 @app.get("/vaccination/<action>/<id>")
422 def vaccination_view(action, id=None):
423 if((ret:=problem())!="go"):
424 return ret
425 try:
426 cursor=get_db().cursor()
427 if(action=="list"):
428 if(id is not None):
429 (ok, data)=vaccination.list_by_patient(cursor, id)
430 if(not ok):
431 raise exception(data)
432 (ok, pat)=patient.read(cursor, data["pid"])
433 if(not ok):
434 raise exception(patient)
435 (ok, inv)=inventory.list(cursor, data["iid"])
436 if(not ok):
437 raise exception(inventory)
438 return render_template("vaccination-view.html", data=data, patient=pat, inventory=inv, action=action)
439 else:
440 raise Exception("Invalid parameter")
441 elif(action=="view"):
442 if(id is not None):
443 (ok, data)=vaccination.read(cursor, id)
444 if(not ok):
445 raise Exception(data)
446 (ok, inv)=inventory.read(cursor, data["iid"])
447 if(not ok):
448 raise Exception(inventory)
449 (ok, pat)=patient.read(cursor, data["pid"])
450 if(not ok):
451 raise Exception(patient)
452 (ok, consultant)=personnel.read(cursor, data["consultant"])
453 if(not ok):
454 raise Exception(consultant)
455 (ok, vaccinator)=personnel.read(cursor, data["vaccinator"])
456 if(not ok):
457 raise Exception(vaccinator)
458 return render_template("vaccination-view.html", data=data, inventory=inv, patient=pat, consultant=consultant, vaccinator=vaccinator, action=action)
459 else:
460 raise Exception("Invalid parameter")
461 elif(action=="edit"):
462 if(id is not None):
463 (ok, data)=vaccination.read(cursor, id)
464 if(not ok):
465 raise Exception(data)
466 (ok, inv)=inventory.list(cursor, g.mid)
467 if(not ok):
468 raise Exception(inv)
469 (ok, consultant)=personnel.list(cursor, g.mid, "consultant")
470 if(not ok):
471 raise Exception(consultant)
472 (ok, vaccinator)=personnel.list(cursor, g.mid, "vaccinator")
473 if(not ok):
474 raise Exception(vaccinator)
475 return render_template("vaccination-edit.html", data=data, inventory=inv, consultant=consultant, vaccinator=vaccinator, action=action)
476 else:
477 raise Exception("Invalid parameter")
478 elif(action=="new"):
479 if(id is not None):
480 (ok, inv)=inventory.list(cursor, g.mid)
481 if(not ok):
482 raise Exception(inv)
483 (ok, consultant)=personnel.list(cursor, g.mid, "consultant")
484 if(not ok):
485 raise Exception(consultant)
486 (ok, vaccinator)=personnel.list(cursor, g.mid, "vaccinator")
487 if(not ok):
488 raise Exception(vaccinator)
489 data={"pid": id, "date":datetime.now().strftime("%Y-%m-%dT%H:%M:%S")}
490 if(len(inv)<=0):
491 raise Exception("Please add a vaccine to inventory before vaccination.")
492 return render_template("vaccination-edit.html", data=data, inventory=inv, consultant=consultant, vaccinator=vaccinator, action=action)
493 else:
494 raise Exception("Invalid parameter")
495 except Exception as e:
496 raise(e)
497 return render_template("error.html", data=e)
498
499 @app.post("/vaccination/new/<pid>")
500 @app.post("/vaccination/edit/<vid>")
501 def vaccination_edit(vid=None, pid=None):
502 if((ret:=problem())!="go"):
503 return ret
504 try:
505 cursor=get_db().cursor()
506 if(vid is None):
507 given="given" in request.form.keys()
508 (ok, data)=vaccination.create(cursor, request.form, given)
509 if(not ok):
510 raise Exception(data)
511 vid=data
512 else:
513 given="given" in request.form.keys()
514 (ok, data)=vaccination.update(cursor, vid, request.form, given)
515 if(not ok):
516 raise Exception(data)
517 return redirect("/vaccination/view/"+str(vid))
518 except Exception as e:
519 raise(e)
520 return render_template("error.html", data=e)
521
522
523 @app.get("/advice/<action>")
524 @app.get("/advice/<action>/<id>")
525 def advice_view(action, id=None):
526 if((ret:=problem())!="go"):
527 return ret
528 try:
529 cursor=get_db().cursor()
530 if(action=="list"):
531 if(id is not None):
532 (ok, data)=advice.list(cursor, id)
533 if(not ok):
534 raise exception(data)
535 (ok, pat)=patient.read(cursor, id)
536 if(not ok):
537 raise exception(patient)
538 return render_template("advice-view.html", data=data, patient=pat, action=action)
539 else:
540 raise Exception("Invalid parameter")
541 elif(action=="view"):
542 if(id is not None):
543 (ok, data)=advice.read(cursor, id)
544 if(not ok):
545 raise Exception(data)
546 (ok, pat)=patient.read(cursor, data["pid"])
547 if(not ok):
548 raise Exception(pat)
549 (ok, consultant)=personnel.read(cursor, data["consultant"])
550 if(not ok):
551 raise Exception(consultant)
552 return render_template("advice-view.html", data=data, patient=pat, consultant=consultant, action=action)
553 else:
554 raise Exception("Invalid parameter")
555 elif(action=="edit"):
556 if(id is not None):
557 (ok, data)=advice.read(cursor, g.mid)
558 if(not ok):
559 raise Exception(data)
560 (ok, consultant)=personnel.list(cursor, g.mid, "consultant")
561 if(not ok):
562 raise Exception(consultant)
563 return render_template("advice-edit.html", data=data, consultant=consultant, action=action)
564 else:
565 raise Exception("Invalid parameter")
566 elif(action=="new"):
567 if(id is not None):
568 (ok, consultant)=personnel.list(cursor, g.mid, "consultant")
569 if(not ok):
570 raise Exception(consultant)
571 data={"pid": id, "date":datetime.now().strftime("%Y-%m-%dT%H:%M:%S")}
572 return render_template("advice-edit.html", data=data, consultant=consultant, action=action)
573 else:
574 raise Exception("Invalid parameter")
575 except Exception as e:
576 raise(e)
577 return render_template("error.html", data=e)
578
579 @app.post("/advice/new/<pid>")
580 @app.post("/advice/edit/<aid>")
581 def advice_edit(aid=None, pid=None):
582 if((ret:=problem())!="go"):
583 return ret
584 try:
585 cursor=get_db().cursor()
586 if(aid is None):
587 (ok, data)=advice.create(cursor, request.form, pid)
588 if(not ok):
589 raise Exception(data)
590 aid=data
591 else:
592 (ok, data)=advice.update(cursor, aid, request.form)
593 if(not ok):
594 raise Exception(data)
595 return redirect("/advice/view/"+str(aid))
596 except Exception as e:
597 raise(e)
598 return render_template("error.html", data=e)
599
600 @app.get("/delete/<cat>/<id>")
601 def delete(cat, id):
602 if((ret:=problem())!="go"):
603 return ret
604 try:
605 if(not g.enable_delete):
606 raise Exception("Deleting record is not allowed.")
607 cursor=get_db().cursor()
608 if(cat=="advice"):
609 (ok, data)=advice.delete(cursor, id)
610 if(not ok):
611 return render_template("error.html", data=data)
612 elif(cat=="inventory"):
613 (ok, data)=inventory.delete(cursor, id)
614 if(not ok):
615 return render_template("error.html", data=data)
616 elif(cat=="center"):
617 (ok, data)=multicenter.delete(cursor, id)
618 if(not ok):
619 return render_template("error.html", data=data)
620 elif(cat=="patient"):
621 (ok, data)=patient.delete(cursor, id)
622 if(not ok):
623 return render_template("error.html", data=data)
624 elif(cat=="personnel"):
625 (ok, data)=personnel.delete(cursor, id)
626 if(not ok):
627 return render_template("error.html", data=data)
628 elif(cat=="transaction"):
629 (ok, data)=transaction.delete(cursor, id)
630 if(not ok):
631 return render_template("error.html", data=data)
632 elif(cat=="vaccination"):
633 (ok, data)=vaccination.delete(cursor, id)
634 if(not ok):
635 return render_template("error.html", data=data)
636 return redirect("/")
637 except Exception as e:
638 raise(e)
639 return render_template("error.html", data=e)
640
641 @app.route("/card/<pid>")
642 def card(pid):
643 if((ret:=problem())!="go"):
644 return ret
645 try:
646 cursor=get_db().cursor()
647 (ok, data)=patient.read(cursor, pid)
648 if(not ok):
649 raise Exception(data)
650 (ok, vac)=vaccination.list_by_patient(cursor, pid)
651 if(not ok):
652 raise Exception(vac)
653 (ok, adv)=advice.list(cursor, pid)
654 if(not ok):
655 raise Exception(adv)
656 (ok, center)=multicenter.read(cursor, g.mid)
657 if(not ok):
658 raise Exception(center)
659 return render_template("card.html", data=data, vaccination=vac, advice=adv, center=center)
660 except Exception as e:
661 raise(e)
662 return render_template("error.html", data=e)
663
664 @app.route("/report/<mid>")
665 def report(mid):
666 if((ret:=problem())!="go"):
667 return ret
668 try:
669 date=request.args.get("date", datetime.now().strftime("%Y-%m-%d"))
670 cursor=get_db().cursor()
671 (ok, data)=vaccination.list_by_date(cursor, date)
672 if(not ok):
673 raise Exception(data)
674 (ok, center)=multicenter.read(cursor, g.mid)
675 if(not ok):
676 raise Exception(center)
677 return render_template("report.html", data=data, center=center, date=date)
678 except Exception as e:
679 raise(e)
680 return render_template("error.html", data=e)
681
682
683 def get_db():
684 db=getattr(g, "_database", None)
685 if db is None:
686 db=g._database=sqlite3.connect("data/database.db", isolation_level=None)
687 db.row_factory=sqlite3.Row
688 return db
689
690 @app.teardown_appcontext
691 def close_connection(exception):
692 db=getattr(g, "_database", None)
693 if db is not None:
694 db.close()
695
696 def problem(access=""):
697 if(auth.access()==auth.auth.ALL):
698 return "go"
699 else:
700 return redirect("/login")
701
702 @app.template_filter("format_date")
703 def format_date(date):
704 try:
705 if("T" in date):
706 dt=datetime.strptime(date, "%Y-%m-%dT%H:%M:%S")
707 return dt.strftime("%b %d, %Y, %I:%M %p")
708 else:
709 dt=datetime.strptime(date, "%Y-%m-%d")
710 return dt.strftime("%b %d, %Y")
711 except Exception:
712 return date
713
714 def init_db():
715 with app.app_context():
716 db=get_db()
717 with app.open_resource("etc/schema.sql", mode="r") as f:
718 db.cursor().executescript(f.read())
719 db.commit()