-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data.py
53 lines (48 loc) · 1.69 KB
/
get_data.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
import csv
from scraper import getCSV, scrape
from summarization import summarization
from sentiment import sentiment
import json
def get_data(url, limit):
pText = """"""
nText = """"""
positive = 0
negative = 0
neutral = 0
reviewLength = 0
getCSV(url, limit)
with open("Dataset/data.csv", mode="r") as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
temp = json.loads(sentiment(row["content"]))
if temp["errors"]:
continue
pScore = float(temp["documents"][0]["confidenceScores"]["positive"])
nScore = float(temp["documents"][0]["confidenceScores"]["negative"])
if pScore > 0.5:
pText = pText + row["content"]
positive += 1
elif nScore > 0.5:
nText = nText + row["content"]
negative += 1
else:
neutral += 1
reviewLength += 1
# if cn == 20:
# break
# print(pText)
result = dict()
nSummarization = json.loads(summarization(nText))
pSummarization = json.loads(summarization(pText))
if "snippets" in nSummarization:
result["negative"] = nSummarization["snippets"]
else:
result["negative"] = ["No negative reviews to show."]
if "snippets" in pSummarization:
result["positive"] = pSummarization["snippets"]
else:
result["positive"] = ["No positive reviews to show."]
result["pScore"] = round((positive / reviewLength) * 100, 2)
result["nScore"] = round((negative / reviewLength) * 100, 2)
result["neScore"] = round((neutral / reviewLength) * 100, 2)
return result