-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransformation.py
More file actions
142 lines (124 loc) · 6.15 KB
/
transformation.py
File metadata and controls
142 lines (124 loc) · 6.15 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
import json
from re import sub
transList = []
class Transform:
def __init__(self, file):
self.get_gneralData(file)
self.get_ImgeData(file)
self.get_VideoData(file)
self.get_attachData(file)
self.get_specData(file)
def listData(self,file2):
with open(file2) as file3:
data = json.load(file3)
return data
def generalData(self,model, category, subcategory, description, manufacturer="Vermeer", msrp=0, year=2021,
countries=["US"]):
gendict = {
"manufacturer": manufacturer,
"model": model,
"category": category,
"subcategory": subcategory,
"msrp": msrp,
"description": description,
"year": year,
"countries": countries
}
return gendict
def get_gneralData(self,file1):
extractData = self.listData(file1)
#genList = []
for entry in extractData:
if entry["productDetailist"]:
model = entry["productDetailist"][0]["title"]
category = entry["industry"]["title"]
subcategory = entry["product"]["title"]
description = entry["productDetailist"][0]["description"]
generalNode = self.generalData(model, category, subcategory, description)
#genList.append(generalNode)
#print(genList[0])
def transformImgeData(self,src, dec="", longdec=""):
mydict = {"dec": dec, "longdec": longdec, "src": src}
return mydict
def get_ImgeData(self,file4):
extractData1 = self.listData(file4)
for entry in extractData1:
Imgelist = []
if entry["productDetailist"]:
src = entry["productDetailist"][0]["baseImage"]
bseImgNode = self.transformImgeData(src)
Imgelist.append(bseImgNode)
for media in entry["productDetailist"][0]["medias"]:
if media["mediaType"] == "Image":
dec = media['title']
src = media['image']
mediaNode = self.transformImgeData(src, dec)
Imgelist.append(mediaNode)
#print(Imgelist)
def transformVideoData(self,src, dec="", longdec=""):
mydict1 = {"dec": dec, "longdec": longdec, "src": src}
return mydict1
def get_VideoData(self,file5):
extractData2 = self.listData(file5)
for entry in extractData2:
videoList = []
if entry["productDetailist"]:
for media in entry["productDetailist"][0]["medias"]:
if media["mediaType"] == "Video":
dec = media['title']
src = media['videoCode']
mediaNode = self.transformVideoData(src, dec)
videoList.append(mediaNode)
#print(videoList)
def attachmentData(self,attachmentDescription, attachmentLocation, attachmentLongDescription="", attachmentSequence=""):
mydict2 = {"attachmentDescription": attachmentDescription, "attachmentLocation": attachmentLocation,
"attachmentLongDescription": attachmentLongDescription, "attachmentSequence": attachmentSequence}
return mydict2
def get_attachData(self,file6):
extractData3 = self.listData(file6)
for entry in extractData3:
attachList = []
if entry["productDetailist"]:
for attachment in entry["productDetailist"][0]["literatures"]:
attachmentDescription = attachment["title"]
attachmentLocation = attachment["literatureItem"]
attachmentnode = self.attachmentData(attachmentDescription, attachmentLocation)
attachList.append(attachmentnode)
#print(attachList)
def format_desc(self,pValue, sValue, pSymbol, scSymbol):
if pValue != None or (sValue != None and sValue != ""):
return (str(pValue) + str(pSymbol) + str(" ") + str(sValue) + str(scSymbol)
def convert_to_camel_case(self,s):
s = sub(r"(_|-)+", " ", s).title().replace(" ", "")
return ''.join([s[0].lower(), s[1:]])
def get_specData(self,file7):
extractData4 = self.listData(file7)
for entry in extractData4:
if entry["productDetailist"]:
for specification in entry["productDetailist"][0]["pdSpecification"]:
group_name = specification["groupName"]
pValue = specification["primaryDisplayValue"]
sValue = specification["secondaryDisplayValue"]
pSymbol = specification["primarySymbol"]
scSymbol = specification["secondarySymbol"]
spec1 = specification["specName"]
spec = self.format_desc(pValue, sValue, pSymbol, scSymbol)
label1 = self.convert_to_camel_case(specification["specName"])
if 'Engine' in group_name or 'Power Unit' in group_name:
enginedict = {str(label1): {'label': specification['specName'], 'desc': spec}}
elif 'Dimensions' in group_name or 'Capacities' in group_name:
dimensiondict = {str(label1): {'label': specification['specName'], 'desc': spec}}
print(dimensiondict)
elif 'Transmission System' in group_name or 'Clutch' in group_name or 'drive system' in group_name:
drivetraindict = {str(label1): {'label': specification['specName'], 'desc': spec}}
elif 'Features' in group_name:
feList = []
feList.append(str(spec1) + str("-") + str(spec))
# print(feList)
elif 'Option' in group_name:
opList = []
opList.append(str(spec1) + str("-") + str(spec))
else:
operationaldict = {str(label1): {'label': specification['specName'], 'desc': spec}}
if __name__ == "__main__":
transform1 = Transform("list1.json")