Subversion Repositories SmartDukaan

Rev

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

#!/usr/bin/python

'''
Created on 01-Sep-2011

@author: ashish
'''
import sys
import csv
import xlrd

if __name__ == '__main__' and __package__ is None:
    import os
    sys.path.insert(0, os.getcwd())
    
from shop2020.clients.CatalogClient import CatalogClient

def get_title(item):
    title = item.brand
    if item.modelName:
        title = title + ' ' + item.modelName
    if item.modelNumber:
        title = title + ' ' + item.modelNumber
    return title

def get_hyphenated_name(item):
    productUrl = item.brand
    if item.modelName:
        productUrl = productUrl + "-" + item.modelName
    if item.modelNumber:
        productUrl = productUrl + '-' + item.modelNumber
    productUrl = productUrl.replace("/", "-")
    productUrl = productUrl.replace(" ", "-")
    productUrl = productUrl.replace("--", "-")
    productUrl = productUrl.lower()
    return productUrl

def get_url(item):
    url = "http://www.saholic.com/mobile-phones/"
    productUrl = get_hyphenated_name(item)
    productUrl = productUrl + "-" + str(item.catalogItemId)
    url = url + productUrl;
    url = url.replace("--", "-");
    return url;

def get_image_url(item):
    url = "http://static0.saholic.com/images/"
    url = url + str(item.catalogItemId) + "/"
    url = url + get_hyphenated_name(item) + "-default-0.jpg"
    return url

def is_active(item):
    return item.itemStatus in [2, 3, 6]

def main():
    catalog_client = CatalogClient().get_client()
    item_details = []
    filename = "/home/ashish/featurevalues.xls"
    workbook = xlrd.open_workbook(filename)
    sheet = workbook.sheet_by_index(0)
    num_rows = sheet.nrows
    
    writer = csv.writer(open("junglee.csv", "wb"), delimiter='\t', quoting=csv.QUOTE_MINIMAL)
    writer.writerow(["SKU","Title","Link","Price","Delivery Time","Recommended Browse Node","Standard Product ID",\
                 "Product ID Type","Category","Description","Shipping Cost","Image","List Price","Availability",\
                 "Brand","Manufacturer","Mfr part number","Model Number","Computer CPU speed","Hard disk size",\
                 "Included RAM size","Optical zoom","Digital zoom","Megapixels","Display size","Screen Resolution",\
                 "Display Technology","Flash drive Size","Memory Card Type","Camera type","Viewfinder type","Flash type",\
                 "Cellular Technology","Phone Operating System","Talk Time","Standby Time","User Input","Device Type",\
                 "Form Factor","Colour Name","Colour Map","Item package quantity","Age","Warranty","Assembly required",\
                 "Battery Type","Batteries Included","Batteries Required","Power Source","Power Adapter Included",\
                 "Shipping Weight","Weight","Length","Height","Width","Keywords1","Keywords2", "Keywords3","Keywords4",\
                 "Keywords5","Bullet point1","Bullet point2","Bullet point3","Bullet point4","Bullet point5",\
                 "Other image-url1","Other image-url2","Other image-url3","Other image-url4","Other image-url5",
                 "Offer note","Is Gift Wrap Available","Registered Parameter","Update Delete"])
    
    for rownum in range(2, num_rows):
        unused_categoryName, unused_entityName, entityID, unused_accessories, unused_softwareApplications, unused_pageTitle,\
        unused_metaDescription, metaKeywords, snippets, shortSnippet, tagline, warranty,\
        unused_skinSize, screenSize, unused_screenLeftUpperCornerDimension, unused_modelNameSynonyms, unused_modelNumberSynonyms,\
        weight, size, formFactor, color, screenType, screenSize, screenResolution, numberOfColors, keyboardType,\
        navigation, touchscreenType, sideControls, multimediaKeys, multipleSIM, voip, network2G,\
        network3G, gprs, edge, g3, wifi, bluetooth, usb, musicFormats, earphone, speakerPhone,\
        fmRadio, internetRadio, ringtoneTypes, fileFormats, streaming, liveTV, hdVideoPlayback,\
        resolution, flash, imageFormats, numberOfCameras, secondaryCamera, additionalCameraFeatures,\
        builtIn, ram, expansionType, expansionCapacity, batteryType, powerAdaptor, musicPlayback,\
        videoPlayback, tvPlayback, talktime2G, talktime3G, standy2G, standby3G, types, markupLanguages,\
        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,\
        unused_instantMessaging, unused_email = sheet.row_values(rownum)[0:85]

        if screenSize:
            screenSize = screenSize.split()[0]
        
        if screenResolution:
            screenResolution = screenResolution.rsplit(' ', 1)[0]

        if 'LCD' in screenType or 'Nova' in screenType or 'Retina' in screenType:
            screenType = 'LCD'
        elif 'LED' in screenType:
            screenType = 'LED'
        else:
            screenType = ''

        cellularTechnology = ''
        if multipleSIM == 'Dual-SIM':
            cellularTechnology = 'Dual SIM'
        if not cellularTechnology:
            if network3G != '':
                cellularTechnology = '3G'
            else:
                cellularTechnology = 'GSM'

        if 'Android' in opsys:
            opsys = 'Android'
        elif 'Symbian' in opsys:
            opsys = 'Symbian'
        elif 'BlackBerry' in opsys:
            opsys = 'Blackberry'
        elif 'Windows' in opsys:
            opsys = 'Windows Phone'
        elif 'bada' in opsys or 'Bada' in opsys:
            opsys = 'Bada'
        elif 'iOS' in opsys:
            opsys = 'iOS'
        else:
            opsys = ''
        
        userInput = "keypad"
        if touchscreenType != "":
            userInput = "touchscreen"

        if formFactor == 'Candybar':
            formFactor = 'candy-bar'
        elif formFactor == 'Slider':
            formFactor = 'slide'
        elif formFactor == 'Flip':
            formFactor = 'flip'

        if warranty:
            warranty = warranty + " manufacturer warranty"

        if 'Li-Ion' in batteryType or 'Li-ion' in batteryType or 'Lithium-ion' in batteryType:
            batteryType = 'lithium_ion'
        elif 'Li-Po' in batteryType:
            batteryType = 'lithium_metal'
        else:
            batteryType = ''
        
        if size == "Not available" or size == '':
            length, width, height = ["", "", ""]
        else:
            list = size.split()
            length, width, height = [list[0], list[2], list[4]] 
        
        keywords = metaKeywords.split(",")
        if len(keywords) < 5:
            length = len(keywords)
            while length < 5:
                keywords.append('')
                length = length + 1 
        
        items = catalog_client.getItemsByCatalogId(entityID)
        active_items = filter(is_active, items)
        if not active_items:
            continue
        
        suffix = ''
        color = ''
        if len(active_items) > 1:
            suffix = ' (multiple colors available)'
        else:
            color = active_items[0].color
            
        item = active_items[0]
        
        item_details.append(
                    [entityID, get_title(item) + suffix, get_url(item), item.sellingPrice, '1', '803546031', 'NA',\
                     'UPC', 'Wireless', tagline, '0', get_image_url(item), item.mrp, 'TRUE',\
                     item.brand, '', '', item.modelNumber, "", builtIn,\
                     ram, "", "", "", screenSize, screenResolution,\
                     screenType, "", "", "", "", "",\
                     cellularTechnology, opsys, talktime2G, standy2G, userInput, "",\
                     formFactor, color, "", "1", "", warranty, "FALSE",\
                     batteryType, "TRUE","TRUE", "battery-powered", "TRUE",\
                     "", weight, length, width, height, keywords[0], keywords[1], keywords[2], keywords[3],\
                     keywords[4], "", "","","","",\
                     "","","","","",\
                     "","","",""]);
    
    for item_detail in item_details:
        writer.writerow(item_detail)

if __name__ == '__main__':
    main()