-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.py
51 lines (45 loc) · 1.54 KB
/
product.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
from compareWord import compare
class ProductManager(object):
# Variables for score determination
p = 0.3
wordThreshold = 1-p
overallThreshold = 0.8
def __init__(self, wordGroups, URLs):
self.wordGroups = wordGroups
self.URLs = URLs
self.products = []
def calculateScore(self, keyWords, discoveredWords, price):
numWords = len(discoveredWords)
score = 0
# Make sure bot found something
if numWords > 0:
# Calculate word component of score
wordScore = 0
for word in keyWords:
if compare(word, discoveredWords):
wordScore += 100
if numWords < 4:
wordScore /= numWords-2
else:
wordScore /= numWords
# TODO: Calculate price component if word part passes, otherwise return score 0
# Price scoring requires knowledge of average prices for that part
# Search through all other listings with similar descriptions and
# if wordScore >= self.wordThreshold:
# wordScore -= price
# score = wordScore
return score
def addProduct(self, name, link, price, website, keyWords, discoveredWords):
score = self.calculateScore(keyWords, discoveredWords, price)
if score >= self.overallThreshold:
product = Product(name, link, price, website, score)
self.products.append(product)
class Product(object):
def __init__ (self, name, link, price, website, score):
self.name = name
self.link = link
self.price = price
self.website = website
self.score = score
def printInfo(self):
print(f'name: {self.name}, link: {self.link}, price: {self.price}, website: {self.website}, score: {self.score}')