| 3139 |
chandransh |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
'''
|
|
|
4 |
Created on 01-Sep-2011
|
|
|
5 |
|
|
|
6 |
@author: ashish
|
|
|
7 |
'''
|
|
|
8 |
import sys
|
| 3140 |
chandransh |
9 |
import csv
|
| 3486 |
chandransh |
10 |
import xlrd
|
| 3139 |
chandransh |
11 |
|
|
|
12 |
if __name__ == '__main__' and __package__ is None:
|
|
|
13 |
import os
|
|
|
14 |
sys.path.insert(0, os.getcwd())
|
|
|
15 |
|
|
|
16 |
from shop2020.clients.CatalogClient import CatalogClient
|
|
|
17 |
|
|
|
18 |
def get_title(item):
|
|
|
19 |
title = item.brand
|
|
|
20 |
if item.modelName:
|
|
|
21 |
title = title + ' ' + item.modelName
|
|
|
22 |
if item.modelNumber:
|
|
|
23 |
title = title + ' ' + item.modelNumber
|
|
|
24 |
return title
|
|
|
25 |
|
|
|
26 |
def get_hyphenated_name(item):
|
|
|
27 |
productUrl = item.brand
|
|
|
28 |
if item.modelName:
|
|
|
29 |
productUrl = productUrl + "-" + item.modelName
|
|
|
30 |
if item.modelNumber:
|
|
|
31 |
productUrl = productUrl + '-' + item.modelNumber
|
|
|
32 |
productUrl = productUrl.replace("/", "-")
|
|
|
33 |
productUrl = productUrl.replace(" ", "-")
|
|
|
34 |
productUrl = productUrl.replace("--", "-")
|
|
|
35 |
productUrl = productUrl.lower()
|
|
|
36 |
return productUrl
|
|
|
37 |
|
|
|
38 |
def get_url(item):
|
|
|
39 |
url = "http://www.saholic.com/mobile-phones/"
|
|
|
40 |
productUrl = get_hyphenated_name(item)
|
|
|
41 |
productUrl = productUrl + "-" + str(item.catalogItemId)
|
|
|
42 |
url = url + productUrl;
|
|
|
43 |
url = url.replace("--", "-");
|
|
|
44 |
return url;
|
|
|
45 |
|
|
|
46 |
def get_image_url(item):
|
|
|
47 |
url = "http://static0.saholic.com/images/"
|
|
|
48 |
url = url + str(item.catalogItemId) + "/"
|
|
|
49 |
url = url + get_hyphenated_name(item) + "-default-0.jpg"
|
|
|
50 |
return url
|
|
|
51 |
|
| 3486 |
chandransh |
52 |
def is_active(item):
|
|
|
53 |
return item.itemStatus in [2, 3, 6]
|
|
|
54 |
|
| 3502 |
chandransh |
55 |
def get_key(brand, model_number, color):
|
|
|
56 |
model_number_str = ''
|
|
|
57 |
try:
|
|
|
58 |
model_number_str = str(int(model_number))
|
|
|
59 |
except:
|
|
|
60 |
model_number_str = str(model_number)
|
|
|
61 |
if '(' in model_number_str:
|
|
|
62 |
model_number_str = model_number_str.split('(')[0]
|
|
|
63 |
return brand.strip().lower() + '|' + model_number_str.strip().lower() + '|' + color.strip().lower()
|
|
|
64 |
|
|
|
65 |
def load_item_numbers():
|
|
|
66 |
filename = "/home/ashish/itemNumbers.xls"
|
|
|
67 |
workbook = xlrd.open_workbook(filename)
|
|
|
68 |
sheet = workbook.sheet_by_index(0)
|
|
|
69 |
num_rows = sheet.nrows
|
|
|
70 |
itemNumberMap = {}
|
|
|
71 |
itemNumberTypeMap = {}
|
|
|
72 |
for rownum in range(1, num_rows):
|
|
|
73 |
itemNumber, unused_description, unused_pc, unused_pg, unused_tech, brand, model_number, color = sheet.row_values(rownum)[0:8]
|
|
|
74 |
key = get_key(brand, model_number, color)
|
|
|
75 |
itemNumberMap[key] = str(itemNumber)
|
|
|
76 |
if len(str(itemNumber)) == 13:
|
|
|
77 |
itemNumberTypeMap[key] = 'EAN'
|
|
|
78 |
else:
|
|
|
79 |
itemNumberTypeMap[key] = 'UPC'
|
|
|
80 |
print itemNumberMap
|
|
|
81 |
return itemNumberMap, itemNumberTypeMap
|
|
|
82 |
|
| 3139 |
chandransh |
83 |
def main():
|
| 3502 |
chandransh |
84 |
itemNumberMap, itemNumberTypeMap = load_item_numbers()
|
| 3139 |
chandransh |
85 |
catalog_client = CatalogClient().get_client()
|
|
|
86 |
item_details = []
|
| 3486 |
chandransh |
87 |
filename = "/home/ashish/featurevalues.xls"
|
|
|
88 |
workbook = xlrd.open_workbook(filename)
|
|
|
89 |
sheet = workbook.sheet_by_index(0)
|
|
|
90 |
num_rows = sheet.nrows
|
| 3140 |
chandransh |
91 |
|
| 3486 |
chandransh |
92 |
writer = csv.writer(open("junglee.csv", "wb"), delimiter='\t', quoting=csv.QUOTE_MINIMAL)
|
|
|
93 |
writer.writerow(["SKU","Title","Link","Price","Delivery Time","Recommended Browse Node","Standard Product ID",\
|
|
|
94 |
"Product ID Type","Category","Description","Shipping Cost","Image","List Price","Availability",\
|
|
|
95 |
"Brand","Manufacturer","Mfr part number","Model Number","Computer CPU speed","Hard disk size",\
|
|
|
96 |
"Included RAM size","Optical zoom","Digital zoom","Megapixels","Display size","Screen Resolution",\
|
|
|
97 |
"Display Technology","Flash drive Size","Memory Card Type","Camera type","Viewfinder type","Flash type",\
|
|
|
98 |
"Cellular Technology","Phone Operating System","Talk Time","Standby Time","User Input","Device Type",\
|
|
|
99 |
"Form Factor","Colour Name","Colour Map","Item package quantity","Age","Warranty","Assembly required",\
|
|
|
100 |
"Battery Type","Batteries Included","Batteries Required","Power Source","Power Adapter Included",\
|
|
|
101 |
"Shipping Weight","Weight","Length","Height","Width","Keywords1","Keywords2", "Keywords3","Keywords4",\
|
|
|
102 |
"Keywords5","Bullet point1","Bullet point2","Bullet point3","Bullet point4","Bullet point5",\
|
|
|
103 |
"Other image-url1","Other image-url2","Other image-url3","Other image-url4","Other image-url5",
|
|
|
104 |
"Offer note","Is Gift Wrap Available","Registered Parameter","Update Delete"])
|
|
|
105 |
|
|
|
106 |
for rownum in range(2, num_rows):
|
|
|
107 |
unused_categoryName, unused_entityName, entityID, unused_accessories, unused_softwareApplications, unused_pageTitle,\
|
|
|
108 |
unused_metaDescription, metaKeywords, snippets, shortSnippet, tagline, warranty,\
|
|
|
109 |
unused_skinSize, screenSize, unused_screenLeftUpperCornerDimension, unused_modelNameSynonyms, unused_modelNumberSynonyms,\
|
|
|
110 |
weight, size, formFactor, color, screenType, screenSize, screenResolution, numberOfColors, keyboardType,\
|
|
|
111 |
navigation, touchscreenType, sideControls, multimediaKeys, multipleSIM, voip, network2G,\
|
|
|
112 |
network3G, gprs, edge, g3, wifi, bluetooth, usb, musicFormats, earphone, speakerPhone,\
|
|
|
113 |
fmRadio, internetRadio, ringtoneTypes, fileFormats, streaming, liveTV, hdVideoPlayback,\
|
|
|
114 |
resolution, flash, imageFormats, numberOfCameras, secondaryCamera, additionalCameraFeatures,\
|
|
|
115 |
builtIn, ram, expansionType, expansionCapacity, batteryType, powerAdaptor, musicPlayback,\
|
|
|
116 |
videoPlayback, tvPlayback, talktime2G, talktime3G, standy2G, standby3G, types, markupLanguages,\
|
|
|
117 |
unused_http_protocols, unused_browser, unused_mail_protocols, opsys, unused_java, unused_flashPlayer, unused_drm, unused_securityFeatures, unused_gpsType, unused_mms, unused_sms, unused_ems,\
|
|
|
118 |
unused_instantMessaging, unused_email = sheet.row_values(rownum)[0:85]
|
|
|
119 |
|
| 3502 |
chandransh |
120 |
items = catalog_client.getItemsByCatalogId(entityID)
|
|
|
121 |
active_items = filter(is_active, items)
|
|
|
122 |
if not active_items:
|
|
|
123 |
continue
|
|
|
124 |
|
| 3486 |
chandransh |
125 |
if screenSize:
|
|
|
126 |
screenSize = screenSize.split()[0]
|
|
|
127 |
|
|
|
128 |
if screenResolution:
|
|
|
129 |
screenResolution = screenResolution.rsplit(' ', 1)[0]
|
|
|
130 |
|
|
|
131 |
if 'LCD' in screenType or 'Nova' in screenType or 'Retina' in screenType:
|
|
|
132 |
screenType = 'LCD'
|
|
|
133 |
elif 'LED' in screenType:
|
|
|
134 |
screenType = 'LED'
|
|
|
135 |
else:
|
|
|
136 |
screenType = ''
|
|
|
137 |
|
|
|
138 |
cellularTechnology = ''
|
|
|
139 |
if multipleSIM == 'Dual-SIM':
|
|
|
140 |
cellularTechnology = 'Dual SIM'
|
|
|
141 |
if not cellularTechnology:
|
|
|
142 |
if network3G != '':
|
|
|
143 |
cellularTechnology = '3G'
|
|
|
144 |
else:
|
|
|
145 |
cellularTechnology = 'GSM'
|
|
|
146 |
|
|
|
147 |
if 'Android' in opsys:
|
|
|
148 |
opsys = 'Android'
|
|
|
149 |
elif 'Symbian' in opsys:
|
|
|
150 |
opsys = 'Symbian'
|
|
|
151 |
elif 'BlackBerry' in opsys:
|
|
|
152 |
opsys = 'Blackberry'
|
|
|
153 |
elif 'Windows' in opsys:
|
|
|
154 |
opsys = 'Windows Phone'
|
|
|
155 |
elif 'bada' in opsys or 'Bada' in opsys:
|
|
|
156 |
opsys = 'Bada'
|
|
|
157 |
elif 'iOS' in opsys:
|
|
|
158 |
opsys = 'iOS'
|
|
|
159 |
else:
|
|
|
160 |
opsys = ''
|
|
|
161 |
|
|
|
162 |
userInput = "keypad"
|
|
|
163 |
if touchscreenType != "":
|
|
|
164 |
userInput = "touchscreen"
|
|
|
165 |
|
|
|
166 |
if formFactor == 'Candybar':
|
|
|
167 |
formFactor = 'candy-bar'
|
|
|
168 |
elif formFactor == 'Slider':
|
|
|
169 |
formFactor = 'slide'
|
|
|
170 |
elif formFactor == 'Flip':
|
|
|
171 |
formFactor = 'flip'
|
|
|
172 |
|
|
|
173 |
if warranty:
|
|
|
174 |
warranty = warranty + " manufacturer warranty"
|
|
|
175 |
|
|
|
176 |
if 'Li-Ion' in batteryType or 'Li-ion' in batteryType or 'Lithium-ion' in batteryType:
|
|
|
177 |
batteryType = 'lithium_ion'
|
|
|
178 |
elif 'Li-Po' in batteryType:
|
|
|
179 |
batteryType = 'lithium_metal'
|
|
|
180 |
else:
|
|
|
181 |
batteryType = ''
|
|
|
182 |
|
| 3505 |
chandransh |
183 |
weight_parts = weight.split()
|
|
|
184 |
if len(weight_parts) > 1:
|
|
|
185 |
weight = weight_parts[0]
|
|
|
186 |
try:
|
|
|
187 |
float(weight)
|
|
|
188 |
except:
|
|
|
189 |
weight = ''
|
|
|
190 |
|
| 3486 |
chandransh |
191 |
if size == "Not available" or size == '':
|
|
|
192 |
length, width, height = ["", "", ""]
|
|
|
193 |
else:
|
|
|
194 |
list = size.split()
|
|
|
195 |
length, width, height = [list[0], list[2], list[4]]
|
|
|
196 |
|
|
|
197 |
keywords = metaKeywords.split(",")
|
|
|
198 |
if len(keywords) < 5:
|
|
|
199 |
length = len(keywords)
|
|
|
200 |
while length < 5:
|
|
|
201 |
keywords.append('')
|
| 3502 |
chandransh |
202 |
length = length + 1
|
| 3486 |
chandransh |
203 |
|
| 3502 |
chandransh |
204 |
for item in active_items:
|
|
|
205 |
stdProductId = ''
|
|
|
206 |
stdProductIdType = ''
|
|
|
207 |
if not item.color:
|
|
|
208 |
item.color = ''
|
|
|
209 |
key = get_key(item.brand, item.modelNumber, item.color)
|
|
|
210 |
if itemNumberMap.has_key(key):
|
|
|
211 |
stdProductId = itemNumberMap[key]
|
|
|
212 |
stdProductIdType = itemNumberTypeMap[key]
|
|
|
213 |
item_details.append(
|
|
|
214 |
[item.id, get_title(item), get_url(item), item.sellingPrice, "1", "803546031", stdProductId,\
|
|
|
215 |
stdProductIdType, "Wireless", tagline, '0', get_image_url(item), item.mrp, "TRUE",\
|
|
|
216 |
item.brand, "", "", item.modelNumber, "", builtIn,\
|
|
|
217 |
ram, "", "", "", screenSize, screenResolution,\
|
|
|
218 |
screenType, "", "", "", "", "",\
|
| 3505 |
chandransh |
219 |
cellularTechnology, opsys,\
|
|
|
220 |
#talktime2G, standy2G, - use these values after converting them to minutes and hours respectively
|
|
|
221 |
'', '', userInput, "",\
|
| 3502 |
chandransh |
222 |
formFactor, item.color, "", "1", "", warranty, "FALSE",\
|
|
|
223 |
batteryType, "TRUE","TRUE", "battery-powered", "TRUE",\
|
|
|
224 |
"", weight, length, width, height, keywords[0], keywords[1], keywords[2], keywords[3],\
|
|
|
225 |
keywords[4], "", "","","","",\
|
|
|
226 |
"","","","","",\
|
|
|
227 |
"","","",""]);
|
| 3486 |
chandransh |
228 |
|
| 3140 |
chandransh |
229 |
for item_detail in item_details:
|
|
|
230 |
writer.writerow(item_detail)
|
| 3139 |
chandransh |
231 |
|
|
|
232 |
if __name__ == '__main__':
|
|
|
233 |
main()
|