Subversion Repositories SmartDukaan

Rev

Rev 3140 | Rev 3502 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
3139 chandransh 55
def main():
56
    catalog_client = CatalogClient().get_client()
57
    item_details = []
3486 chandransh 58
    filename = "/home/ashish/featurevalues.xls"
59
    workbook = xlrd.open_workbook(filename)
60
    sheet = workbook.sheet_by_index(0)
61
    num_rows = sheet.nrows
3140 chandransh 62
 
3486 chandransh 63
    writer = csv.writer(open("junglee.csv", "wb"), delimiter='\t', quoting=csv.QUOTE_MINIMAL)
64
    writer.writerow(["SKU","Title","Link","Price","Delivery Time","Recommended Browse Node","Standard Product ID",\
65
                 "Product ID Type","Category","Description","Shipping Cost","Image","List Price","Availability",\
66
                 "Brand","Manufacturer","Mfr part number","Model Number","Computer CPU speed","Hard disk size",\
67
                 "Included RAM size","Optical zoom","Digital zoom","Megapixels","Display size","Screen Resolution",\
68
                 "Display Technology","Flash drive Size","Memory Card Type","Camera type","Viewfinder type","Flash type",\
69
                 "Cellular Technology","Phone Operating System","Talk Time","Standby Time","User Input","Device Type",\
70
                 "Form Factor","Colour Name","Colour Map","Item package quantity","Age","Warranty","Assembly required",\
71
                 "Battery Type","Batteries Included","Batteries Required","Power Source","Power Adapter Included",\
72
                 "Shipping Weight","Weight","Length","Height","Width","Keywords1","Keywords2", "Keywords3","Keywords4",\
73
                 "Keywords5","Bullet point1","Bullet point2","Bullet point3","Bullet point4","Bullet point5",\
74
                 "Other image-url1","Other image-url2","Other image-url3","Other image-url4","Other image-url5",
75
                 "Offer note","Is Gift Wrap Available","Registered Parameter","Update Delete"])
76
 
77
    for rownum in range(2, num_rows):
78
        unused_categoryName, unused_entityName, entityID, unused_accessories, unused_softwareApplications, unused_pageTitle,\
79
        unused_metaDescription, metaKeywords, snippets, shortSnippet, tagline, warranty,\
80
        unused_skinSize, screenSize, unused_screenLeftUpperCornerDimension, unused_modelNameSynonyms, unused_modelNumberSynonyms,\
81
        weight, size, formFactor, color, screenType, screenSize, screenResolution, numberOfColors, keyboardType,\
82
        navigation, touchscreenType, sideControls, multimediaKeys, multipleSIM, voip, network2G,\
83
        network3G, gprs, edge, g3, wifi, bluetooth, usb, musicFormats, earphone, speakerPhone,\
84
        fmRadio, internetRadio, ringtoneTypes, fileFormats, streaming, liveTV, hdVideoPlayback,\
85
        resolution, flash, imageFormats, numberOfCameras, secondaryCamera, additionalCameraFeatures,\
86
        builtIn, ram, expansionType, expansionCapacity, batteryType, powerAdaptor, musicPlayback,\
87
        videoPlayback, tvPlayback, talktime2G, talktime3G, standy2G, standby3G, types, markupLanguages,\
88
        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,\
89
        unused_instantMessaging, unused_email = sheet.row_values(rownum)[0:85]
90
 
91
        if screenSize:
92
            screenSize = screenSize.split()[0]
93
 
94
        if screenResolution:
95
            screenResolution = screenResolution.rsplit(' ', 1)[0]
96
 
97
        if 'LCD' in screenType or 'Nova' in screenType or 'Retina' in screenType:
98
            screenType = 'LCD'
99
        elif 'LED' in screenType:
100
            screenType = 'LED'
101
        else:
102
            screenType = ''
103
 
104
        cellularTechnology = ''
105
        if multipleSIM == 'Dual-SIM':
106
            cellularTechnology = 'Dual SIM'
107
        if not cellularTechnology:
108
            if network3G != '':
109
                cellularTechnology = '3G'
110
            else:
111
                cellularTechnology = 'GSM'
112
 
113
        if 'Android' in opsys:
114
            opsys = 'Android'
115
        elif 'Symbian' in opsys:
116
            opsys = 'Symbian'
117
        elif 'BlackBerry' in opsys:
118
            opsys = 'Blackberry'
119
        elif 'Windows' in opsys:
120
            opsys = 'Windows Phone'
121
        elif 'bada' in opsys or 'Bada' in opsys:
122
            opsys = 'Bada'
123
        elif 'iOS' in opsys:
124
            opsys = 'iOS'
125
        else:
126
            opsys = ''
127
 
128
        userInput = "keypad"
129
        if touchscreenType != "":
130
            userInput = "touchscreen"
131
 
132
        if formFactor == 'Candybar':
133
            formFactor = 'candy-bar'
134
        elif formFactor == 'Slider':
135
            formFactor = 'slide'
136
        elif formFactor == 'Flip':
137
            formFactor = 'flip'
138
 
139
        if warranty:
140
            warranty = warranty + " manufacturer warranty"
141
 
142
        if 'Li-Ion' in batteryType or 'Li-ion' in batteryType or 'Lithium-ion' in batteryType:
143
            batteryType = 'lithium_ion'
144
        elif 'Li-Po' in batteryType:
145
            batteryType = 'lithium_metal'
146
        else:
147
            batteryType = ''
148
 
149
        if size == "Not available" or size == '':
150
            length, width, height = ["", "", ""]
151
        else:
152
            list = size.split()
153
            length, width, height = [list[0], list[2], list[4]] 
154
 
155
        keywords = metaKeywords.split(",")
156
        if len(keywords) < 5:
157
            length = len(keywords)
158
            while length < 5:
159
                keywords.append('')
160
                length = length + 1 
161
 
162
        items = catalog_client.getItemsByCatalogId(entityID)
163
        active_items = filter(is_active, items)
164
        if not active_items:
165
            continue
166
 
167
        suffix = ''
168
        color = ''
169
        if len(active_items) > 1:
170
            suffix = ' (multiple colors available)'
171
        else:
172
            color = active_items[0].color
173
 
174
        item = active_items[0]
175
 
176
        item_details.append(
177
                    [entityID, get_title(item) + suffix, get_url(item), item.sellingPrice, '1', '803546031', 'NA',\
178
                     'UPC', 'Wireless', tagline, '0', get_image_url(item), item.mrp, 'TRUE',\
179
                     item.brand, '', '', item.modelNumber, "", builtIn,\
180
                     ram, "", "", "", screenSize, screenResolution,\
181
                     screenType, "", "", "", "", "",\
182
                     cellularTechnology, opsys, talktime2G, standy2G, userInput, "",\
183
                     formFactor, color, "", "1", "", warranty, "FALSE",\
184
                     batteryType, "TRUE","TRUE", "battery-powered", "TRUE",\
185
                     "", weight, length, width, height, keywords[0], keywords[1], keywords[2], keywords[3],\
186
                     keywords[4], "", "","","","",\
187
                     "","","","","",\
188
                     "","","",""]);
189
 
3140 chandransh 190
    for item_detail in item_details:
191
        writer.writerow(item_detail)
3139 chandransh 192
 
193
if __name__ == '__main__':
194
    main()