-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
219 lines (167 loc) · 6.48 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
from flask import Flask, request, jsonify , render_template , redirect , Response , send_file
import pandas as pd
import pyrebase
# from db import *
from datetime import date , datetime
app = Flask(__name__)
df = pd.read_csv('data.csv')
info = {}
dataupdate = {}
fdata = []
dflist = []
dataupdate = {}
cfg = {
'apiKey': "AIzaSyBwRBcKz9DC68UVsMBygkANr_QixS0ZaKA",
'authDomain': "mypy-19226.firebaseapp.com",
'databaseURL':'https://mypy-19226-default-rtdb.firebaseio.com/',
'projectId': "mypy-19226",
'storageBucket': "mypy-19226.appspot.com",
'messagingSenderId': "990787705081",
'appId': "1:990787705081:web:ab15b33b11bbea973dea28",
'measurementId': "G-298F64SX86"
}
dumtext = {'Card':{
'title': '`Title: this is a card title`',
'text': 'This is the body text of a card. You can even use line\n breaks and emoji! 💁',
'buttonText': 'Click me',
'buttonUrl': 'https://assistant.google.com/'
}}
struct = {
'date': str(datetime.now().strftime("%Y-%m-%d")),
'time': str(datetime.now().strftime("%H:%M:%S")),
'name':'',
'url':'',
'email':'',
'phno':'',
'service':''
}
firebase = pyrebase.initialize_app(cfg)
db = firebase.database()
auth = firebase.auth()
Storage = firebase.storage()
def get_db():
data = db.child('data').child('leadsinfo').get()
for person in data.each():
# print('/**//*////**//*/*/*//**/*/*//*/*/*///*/*/*/*/*/*//*/*/*//*/*/*/')
# print(person.val())
# print(person.key())
df = pd.DataFrame(person.val())
df = df.T
print(df)
dflist.append(df)
fdf = pd.concat(dflist, ignore_index = True)
# print('-----------------------******---------------------------')
# print(fdf)
fdf.to_csv('data.csv')
# print('-----------------------------------------------------')
#### CREATING YOUR OWN USER ID ######
def database2(data):
db.child('data').child('leadsinfo').child(str(datetime.now().strftime("%Y-%m-%d"))).child(str(datetime.now().strftime("%H:%M:%S"))).set(data)
print('successfully pushed data')
get_db()
fdf = pd.concat(dflist, ignore_index = True)
# print('-----------------------------------------------------')
# print(fdf)
# print('-----------------------------------------------------')
def get_specfic(date):
data = db.child('data').child('leadsinfo').child(str(date)).get()
# print('++++++++++++++++++++++++++++++++++++++++++++++++Specfic++++++++++++++++++++++++++++++++++++++++++++++++++++')
# print(date)
# print(data.val())
df = pd.DataFrame(data.val())
df = df.T
df.reset_index(drop=True, inplace=True)
# print(df)
return df
# print(date.today())
# print(datetime.now())
# print(dataupdate[str(date.today())][str(datetime.now())])
#@app.route('/')
@app.route("/index")
def index():
with open("tempdata.csv") as file:
return render_template('index.html', csv=file)
@app.route('/', methods=['POST', 'GET'])
def check():
return render_template('login.html')
@app.route('/date', methods=['POST', 'GET'])
def date():
return render_template('edit_user.html')
@app.route('/viewwhole', methods=['POST', 'GET'])
def viewwhole():
get_db()
with open("data.csv") as file:
return render_template('viewwhole.html', csv=file)
@app.route('/login', methods=['POST', 'GET'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
if username == 'admin' and password == 'admin':
return render_template('result.html')
else:
return render_template('result.html')
else:
return render_template('login.html')
@app.route('/select', methods=['POST', 'GET'])
def select():
if request.method == 'POST':
print('****************************************************')
print(request.form['uname'])
rest = get_specfic(request.form['uname'])
rest = pd.DataFrame(rest)
rest.to_csv('tempdata.csv')
print('****************************************************')
return redirect('/index')
else:
return render_template('select.html')
get_db()
@app.route('/downloadcsv', methods=['GET'])
def downloadcsv():
if request.method=='GET':
get_db()
return send_file('data.csv', attachment_filename='data.csv', as_attachment=True)
@app.route('/specfic', methods=['GET'])
def specfic():
if request.method=='GET':
return send_file('tempdata.csv', attachment_filename='tempdata.csv', as_attachment=True)
@app.route('/api', methods=['GET', 'POST'])
def api():
print('requested --------------------------------------------------')
data = request.get_json()
#print(data)
intent = data['queryResult']['intent']['displayName']
#print(intent)
if intent == 'Default Welcome Intent - name - custom':
name = data['queryResult']['parameters']['person']['name']
print(f'This is the name: {name}')
struct['name'] = name
return jsonify(dumtext)
elif intent == 'Default Welcome Intent - url':
url = data['queryResult']['parameters']['url']
print(f'This is the url: {url}')
struct['url'] = url
return jsonify(dumtext)
elif intent == 'Default Welcome Intent -email':
email = data['queryResult']['parameters']['email']
print(f'This is the email: {email}')
struct['email'] = email
return jsonify(dumtext)
elif intent == 'Default Welcome Intent-service':
service = data['queryResult']['queryText']
print(f'This is the service: {service}')
struct['service'] = service
return jsonify(dumtext)
elif intent == 'Default Welcome Intent-phno':
print('...............................................')
phno = data['queryResult']['parameters']['phone-number']
print(f'This is the phno: {phno}')
struct['phno'] = phno
#print('+++++++++++++++++++++++++++++++++++++++')
#print(info)
database2(struct)
#updater(info)
#print('+++++++++++++++++++++++++++++++++++++++')
return jsonify(dumtext)
if __name__ == "__main__":
app.run(debug=True)