-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (52 loc) · 1.59 KB
/
main.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
import json, os
from flask import Flask, render_template, request
from deta import Deta
app = Flask(__name__)
deta = Deta("c0uJEdiLS8zv_tATyVLnLAD5TL2QTqcNkPhWCXRZQbZwY")
# This how to connect to or create a database.
db = deta.Base("sachin_db")
@app.route("/pib/")
def pib():
context = deta.Base("pib_db").fetch().items
nc = []
for c in context[:10]:
for a in json.loads(c['msg']):
print(a)
print("--"*5)
# for c in context[:10]:
# for a in json.loads(c['msg'])[0]['infos']:
# nc.append(a)
print("----"*20)
return render_template('agri.html', context=nc)
@app.route("/")
def hello_world():
return notes()
@app.route("/delete/<key>")
def delete(key):
db.delete(key)
return notes()
@app.route("/notes", methods=['GET', 'POST'])
def notes():
if request.method == 'POST':
print(request.form['msg'])
if request.form['key']:
db.put({
"title" : request.form['title'],
"msg" : request.form['msg'],
"date" : request.form['date']
},request.form['key'])
else:
db.put({
"title" : request.form['title'],
"msg" : request.form['msg'],
"date" : request.form['date']
})
context = {
"data" : db.fetch().items
}
return render_template('notes.html', context = context)
@app.route("/test", methods=['GET', 'POST'])
def test():
return render_template('test.html')
if __name__ == '__main__':
app.run()