-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPriceScraping.py
86 lines (69 loc) · 2.67 KB
/
PriceScraping.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
# import csv as reader
#
# data_file = reader.
# ("hopsandamltchb.csv")
# print(data_file[0:2])
import csv
import pandas as pd
import chardet
from BeerElement import BeerElement
class BeerProgram:
def __init__(self,fileName, rowType, rowName, rowPrice, rowWeight):
self.compteur = 0
self.rowType = rowType
self.rowName = rowName
self.rowPrice = rowPrice
self.rowWeight = rowWeight
self.elements = {}
self.fileName = fileName
#Obtenir le poid de la choppe a Barrock
def getWeightChoppeB(self, string):
weightO, tmp = string.split("g - ",1)
return float(weightO)
def getPriceChoppeB(self, string):
tmp, priceO = string.split("g - ", 1)
priceO = priceO[:-1]
return float(priceO)
def containsElement (self, name):
for elem in self.elements:
if elem == name:
return True
return False
def addNewElement(self, type, name, stringPrice):
price = self.getPriceChoppeB(stringPrice)
weight = self.getWeightChoppeB(stringPrice)
if not self.containsElement(name):
self.elements[name] = BeerElement(type, name)
self.elements[name].setPrice(weight, price)
def readFile(self):
firstLine = True
pd = panda()
pd.read_csv("hopsandamltchb.csv", encoding=result['encoding'])
for row in reader:
self.compteur = 0
for element in row:
if not firstLine:
if self.compteur == self.rowType:
type = element
elif self.compteur == self.rowName:
name = element
elif self.compteur == self.rowPrice:
stringPrice = element
self.addNewElement(type, name, stringPrice)
self.compteur = self.compteur + 1
firstLine = False
def printElement(self):
print("Houblon: \n")
for name in self.elements:
if(self.elements[name].Type == "houblon"):
print("\n" + name)
for weight in self.elements[name].Price:
print("\t"+ str(weight) + "g - " + str(self.elements[name].Price[weight]) + "$")
print("\n Malt: ")
for name in self.elements:
if (self.elements[name].Type == "malt"):
print("\n" + name)
for weight in self.elements[name].Price:
print("\t" + str(weight) + "g - " + str(self.elements[name].Price[weight]) + "$")
def getElements(self):
return self.elements