-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateSummaryReport.py
More file actions
39 lines (36 loc) · 1.27 KB
/
generateSummaryReport.py
File metadata and controls
39 lines (36 loc) · 1.27 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
import requests
import json
import MySQLdb
def readPropertiesFile():
global MYSQL_DB_HOSTANE, USERNAME, PASSWORD, DATABASE
dictionary = {}
with open("properties") as file:
for line in file:
splitLine = line.split("=")
dictionary[splitLine[0]] = splitLine[1].strip('\n').strip(' ')
MYSQL_DB_HOSTANE = dictionary["MYSQL_DB_HOSTANE"]
USERNAME = dictionary["USERNAME"]
PASSWORD = dictionary["PASSWORD"]
DATABASE = dictionary["DATABASE"]
def writeReviewSummary():
f = open("SummaryReport", 'write')
reviewGetQuery = "SELECT * FROM `reviews`"
conn = MySQLdb.connect(MYSQL_DB_HOSTANE, USERNAME, PASSWORD, DATABASE)
request = conn.cursor()
request.execute(reviewGetQuery)
totalProcessed = "Total reviews processed are: " + str(request.rowcount) + "\n" + "Their summary is as follows: \n"
header = "Review Id \t Review timestamp \t Sentiment \t Review Process Timestamp\n"
f.write(str(totalProcessed) + header)
for row in request:
reviewId = row[1]
reviewSentiment = row[2]
reviewTimestamp = row[3]
timestamp = row[4]
if(reviewSentiment==1):
sentiment = "POSITIVE"
else:
sentiment = "NEGATIVE"
body = (str(reviewId) + "\t" + str(reviewTimestamp) + "\t" + str(sentiment) + "\t" + str(timestamp) + "\n")
f.write(body)
readPropertiesFile()
writeReviewSummary()