-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
228 lines (204 loc) · 9.06 KB
/
app.py
File metadata and controls
228 lines (204 loc) · 9.06 KB
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
220
221
222
223
224
225
226
227
228
import forms
from flask import Flask,render_template,url_for,request,redirect,flash
import datetime
import read_database
app = Flask(__name__)
from content_management import Content,Database, Write_Cont, Write_DB
from services_content_management import services_content, mall_content
from flask.ext.login import *
CONT_DICT = Content()
SERV_DICT = services_content()
MALL_DICT = mall_content()
app.secret_key = 'sdkjfjkja'
DATABASE_DICT = Database()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
global product
@app.route('/product')
def product():
"""
Controls the coming of the graph on the first search and of course the subsequent ones.
The product being searched comes via here
"""
product=request.args['product']
return redirect("/trend/{}_OverAll".format(product))
@app.route('/main_product', methods=['GET','POST'])
def main_product():
if request.method == 'POST':
product_name = request.form['productname']
import createproductdb
createproductdb.c.execute("SELECT * FROM products WHERE productname='{}'".format(product_name))
x = createproductdb.c.fetchall()
if (len(x)!=0):
return redirect("trend/{}_OverAll".format(product_name))
return redirect("/wearedoing/{}".format(product_name))
return render_template("product.html")
@app.route('/profile')
def fc():
return render_template('user_profile.html')
@app.route('/wearedoing/<productname>')
def wearedoingit(productname):
#doing the naive bayes thing here
return render_template("wearedoingit.html", productname = productname)
@app.route('/trend/<product>')
def product_Overall(product,chartID = 'chart_ID2',chart_type = 'line', chart_height = 500):
"""
Controls the coming of the graph on the first search and of course the subsequent ones.
The product being searched comes via here
"""
product_list = product.split('_')
product_name = product_list[0]
import createproductdb
createproductdb.c.execute("SELECT trust FROM products WHERE productname='{}'".format(product_name))
x = createproductdb.c.fetchall()
trust_value = x[0][0]
database = DATABASE_DICT[product_name]
category = product_list[1]
product_dict = read_database._check(database)
data = product_dict[category]
length_of_product = len(CONT_DICT[product_name])
title = {"text":"Overall Sentiment"}
chart = {"renderTo":chartID,"type": chart_type, "height":chart_height,"zoomType":'x'}
series = [{"type":"line", "name":"OverAll Sentiment" , "data":data}]
pageType = 'areachart'
return render_template('graph.html',pageType = pageType,length_of_product = length_of_product, chart = chart, chartID = chartID, title = title, series = series,product_name =product_name ,CONT_DICT = CONT_DICT, trust_value = trust_value)
@app.route('/<product>')
def addon(product):
'''This function is a plugin that can be used to open sentikart from fiipkart product page.'''
product_name = product
import createproductdb
createproductdb.c.execute("SELECT * FROM products WHERE productname='{}'".format(product_name))
x = createproductdb.c.fetchall()
if(len(x)!=0):
return redirect('trend/{}_OverAll'.format(product_name))
return redirect("/wearedoing/{}".format(product_name))
#@app.route('/product/daily')
#def product2(chartID = 'chart_ID2',chart_type = 'line', chart_height = 500,product = product):
"""
Controls the coming of the graph on the first search and of course the subsequent ones.
The product being searched comes via here
"""
# category = "OverAll"
# product_dict = read_database._daily(database)
# data = product_dict[category]
# title = {"text":"Overall Sentiment"}
# chart = {"renderTo":chartID,"type": chart_type, "height":chart_height,"zoomType":'x'}
# series = [{"type":"line", "name":"OverAll Sentiment" , "data":data}]
# pageType = 'areachart'
# return render_template('graph.html',pageType = pageType, chart = chart, chartID = chartID, title = title, series = series,product=product)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'),404
@app.route('/graph')
def graph(chartID = 'chart_ID',chart_type = 'bar',chart_height = 500):
# WORK IS LEFT
sentiment = dictionaryTest.main()
pageType = 'graph2'
chart = {"renderTo":chartID, "type": chart_type,"height": chart_height, "zoomType":'x'}
series = [{"name":'Label1',"data":[1,2,3]},{"name":'Label2',"data":[3,4,5]}]
graphtitle = {"text":'Product Summary'}
xAxis = {"categories":['Service','Overall Features','Camera']}
yAxis = {"title":{"text":'This is a test graph'}}
title = {"text":'Product Summary(GRAPH)'}
return render_template('graph.html',pageType = pageType, chart=chart,chartID=chartID,title = title, series = series,graphtitle = graphtitle, xAxis = xAxis,yAxis = yAxis)
#@app.route('/performance')
#def graph_line(chartID = 'chart_ID2',chart_type = 'line', chart_height = 500):
# pageType = 'graph2'
# chart = {"renderTo":chartID,"type": chart_type, "height":chart_height,"zoomType":'x'}
# dataset = []
# dataset2 = [2,3,2,4,2,1,3,2,1,-23]
# series = [{"name":'LOOKS',"data":dataset},{"name":'SERVICE',"data":dataset2}]
# xAxis = {"type":"datetime"}
# yAxis = {"text":'Product Summary(GRAPH)'}
# title = {"text":'Product Overall Graph'}
# return render_template('graph.html',pageType = pageType, chart = chart, chartID = chartID, title = title, series = series,xAxis=xAxis,yAxis=yAxis)
@app.route('/piechart/<product>')
def pie_chart(product,chartID = 'chart_ID', chart_type = 'pie',chart_height = 500):
# This is to be worked out
product_list = product.split('_')
product_name = product_list[0]
analysis_category = product_list[1]
pageType = 'piechart'
chart = {"renderTo":chartID,"type": chart_type, "height":chart_height,"zoomType":'x'}
data_dict = read_database._pie(DATABASE_DICT[product_name])
data1 = data_dict[analysis_category][0]
length_of_product = len(CONT_DICT[product_name])
data2 = data_dict[analysis_category][1]
data2 = [{"name":"Positive Sentiment","y" : data1},{"name":"Negative Sentiment","y":data2}]
series = [{"name" : "Sentiment", "colorpoint":"true", "data":data2}]
title = {"text":'Product {} graph - Pie chart'.format(product_name)}
return render_template('graph.html',pageType = pageType,length_of_product = length_of_product, chart = chart, chartID = chartID, title = title, series = series,product_name = product_name,CONT_DICT = CONT_DICT)
@app.route('/areagraph')
def area_graph(chartID = "chart_ID" , chart_type = 'line', chart_height = 500):
pageType = 'areachart'
category = 'OverAll'
a = read_database._check('sentiment_redmi')
import json
data = json.dumps(a[category])
data = a[category]
title = {"text":"This is a test graph "}
chart = {"renderTo":chartID,"type": chart_type, "height":chart_height,"zoomType":'x'}
series = [{"type":"line", "name":"OverAll Sentiment" , "data":data}]
return render_template('graph.html',pageType = pageType, chart = chart, chartID = chartID, series = series, title = title)
@app.route('/qanda')
def mainpage():
import createqandadb
import ast
queslist = createqandadb.returnWholeData()
for i in range(len(queslist)):
queslist[i] = list(queslist[i])
anslist = ast.literal_eval(queslist[i][3])
queslist[i][3] = anslist
ansuser = ast.literal_eval(queslist[i][4])
queslist[i][4] = ansuser
return render_template('qanda.html', queslist=queslist)
@app.route('/newquestion', methods=["GET","POST"])
def question_page():
import createqandadb
if request.method == 'POST':
mainquery = request.form['MainQuest']
description = request.form['description']
createqandadb.createQuestionEntry("BimalKant Lauhny", mainquery, description)
if mainquery!='':
return redirect('/answer_question')
return render_template('newquestion.html')
@app.route('/answer_question')
def answer_page():
import createqandadb
Unanswered = createqandadb.returnUnanswered()
return render_template('ansaques.html', Unanswered = Unanswered)
@app.route('/login')
def login():
return render_template('login.html')
@app.route('/services')
def services():
pageType = "normal"
return render_template('services.html', pageType=pageType, SERV_DICT = SERV_DICT, MALL_DICT = MALL_DICT)
@app.route('/services/<product>')
def services_product(product):
pageType = "product"
qproduct = product
if qproduct in SERV_DICT.keys():
database = SERV_DICT[qproduct]
else:
database = MALL_DICT[qproduct]
return render_template('services.html', pageType=pageType, SERV_DICT=SERV_DICT, product = product, MALL_DICT=MALL_DICT)
pageType = 'areachart'
category = 'OverAll'
a = read_database._check('sentiment_redmi')
import json
data = json.dumps(a[category])
data = a[category]
title = {"text":"This is a test graph "}
chart = {"renderTo":chartID,"type": chart_type, "height":chart_height,"zoomType":'x'}
series = [{"type":"line", "name":"OverAll Sentiment" , "data":data}]
return render_template('graph.html',pageType = pageType, chart = chart, chartID = chartID, series = series, title = title)
@app.route('/qanda')
def main_page():
return render_template('qanda.html')
if __name__=='__main__':
app.run(debug=True,port=8080,host='0.0.0.0',passthrough_errors=True)