Ejemplo n.º 1
0
def load_from_brom():
    rb = xlrd.open_workbook('brom.xls', formatting_info=True)
    sheet = rb.sheet_by_index(0)

    sql = "delete from prices where sync_tag = 'brom'"
    common.ldb.execute(sql)
    dt_now = datetime.datetime.now()
    dt_for_db = dt_now.strftime('%Y-%m-%d %H:%M:%S')
    pos = 0
    org = common.organization_sql()
    org.find(caption="rmsvet")
    for i in range(1, sheet.nrows - 1):
        pos += 1
        newprice = common.prices_sql()
        c = common._U(sheet.cell(i, 2).value)
        #print i, type(sheet.cell(i,2).value), type(c)
        newprice.caption = c
        if not isinstance(c, unicode) and not isinstance(c, str):
            c = str(c)
        newprice.fantastic_url = urllib.quote(c)
        newprice.price = sheet.cell(i, 4).value
        newprice.description = sheet.cell(i, 12).value
        newprice.sync_tag = "brom"
        newprice.organization = org.id.val
        newprice.in_search = "y"
        newprice.price_date = dt_for_db
        newprice.write()
    print "Loading {p} complate".format(p=pos)
Ejemplo n.º 2
0
def load_from_brom():
    rb = xlrd.open_workbook('brom.xls',formatting_info=True)
    sheet = rb.sheet_by_index(0)

    sql = "delete from prices where sync_tag = 'brom'"
    common.ldb.execute(sql)
    dt_now = datetime.datetime.now()
    dt_for_db = dt_now.strftime('%Y-%m-%d %H:%M:%S')
    pos = 0
    org = common.organization_sql()
    org.find(caption = "rmsvet")
    for i in range(1, sheet.nrows - 1):
        pos += 1
        newprice = common.prices_sql()
        c = common._U(sheet.cell(i,2).value)
        #print i, type(sheet.cell(i,2).value), type(c)
        newprice.caption = c
        if not isinstance(c, unicode) and not isinstance(c, str):
            c = str(c)
        newprice.fantastic_url = urllib.quote(c)
        newprice.price = sheet.cell(i,4).value
        newprice.description = sheet.cell(i,12).value
        newprice.sync_tag = "brom"
        newprice.organization = org.id.val
        newprice.in_search = "y"
        newprice.price_date = dt_for_db
        newprice.write()
    print "Loading {p} complate".format(p = pos)
Ejemplo n.º 3
0
def add_img(id):
    p = cm.prices_sql()
    if p.find(item_partner_id=id):
        a = api.service.getItemsImages(item_id=id)
        #print a, id
        for e in a.item:
            if e.No is None:
                continue
            img = cm.images_sql()
            img.price_id = p.id.val
            img.url = "http://img.merlion.ru/items/" + e.FileName
            img.write()
Ejemplo n.º 4
0
def add_properties(id):
    p = cm.prices_sql()
    if p.find(item_partner_id=id):
        pr = cm.properties_sql()
        pr.delete(price_id=p.id.val)
        a = api.service.getItemsProperties(item_id=id)
        for e in a.item:
            if e.No is None:
                continue
            pr = cm.properties_sql()
            pr.price_id = p.id.val
            pr.caption = cm._U(e.PropertyName)
            pr.value = cm._U(e.Value)
            pr.write()
Ejemplo n.º 5
0
def load_images():
    rb = xlrd.open_workbook('froogle.xls', formatting_info=True)
    sheet = rb.sheet_by_index(0)
    sql = "delete from images where id <> ''"
    common.ldb.execute(sql)
    pos = 0
    price = common.prices_sql()
    for i in range(1, sheet.nrows - 1):
        cap = sheet.cell(i, 1).value
        if isinstance(cap, unicode):
            if price.find(caption=cap):
                pos += 1
                img = common.images_sql()
                img.price_id = price.id.val
                img.url = sheet.cell(i, 3).value
                img.write()
    print "Loading {p} complate".format(p=pos)
Ejemplo n.º 6
0
def load_images():
    rb = xlrd.open_workbook('froogle.xls',formatting_info=True)
    sheet = rb.sheet_by_index(0)
    sql = "delete from images where id <> ''"
    common.ldb.execute(sql)
    pos = 0
    price = common.prices_sql()
    for i in range(1, sheet.nrows - 1):
        cap = sheet.cell(i,1).value
        if isinstance(cap, unicode):
            if price.find(caption = cap):
                pos += 1
                img = common.images_sql()
                img.price_id = price.id.val
                img.url = sheet.cell(i,3).value
                img.write()
    print "Loading {p} complate".format(p = pos)
Ejemplo n.º 7
0
    <vendorCode>{{ yml_id }}</vendorCode>
</offer>
"""
#    <description>Программа для ведения бухгалтерского учета</description>
tree = ET.parse('yml.xml')
root = tree.getroot()

shop = root.find("shop")
offers = shop.find("offers")

shop.remove(offers)

offers = ET.Element("offers")

p = cm.properties_sql()
t = cm.prices_sql()

root.set("date", "2014-09-19 17:00")
def add_offers( yml_id ):
    p.find( value = yml_id )
    t.find( id = p.price_id.val )

    if 15 + len(t.fantastic_url.val) > 500:
        print "too length url ", yml_id
    el_str = pystache.render( templ, {"yml_id" : yml_id,
                                      "url" : t.fantastic_url.val,
                                      "price" : t.price,
                                      "name" : t.caption.val} )
    offer = ET.fromstring( el_str )
    offers.append( offer )
Ejemplo n.º 8
0
    <vendorCode>{{ yml_id }}</vendorCode>
</offer>
"""
#    <description>Программа для ведения бухгалтерского учета</description>
tree = ET.parse('yml.xml')
root = tree.getroot()

shop = root.find("shop")
offers = shop.find("offers")

shop.remove(offers)

offers = ET.Element("offers")

p = cm.properties_sql()
t = cm.prices_sql()

root.set("date", "2014-09-19 17:00")


def add_offers(yml_id):
    p.find(value=yml_id)
    t.find(id=p.price_id.val)

    if 15 + len(t.fantastic_url.val) > 500:
        print "too length url ", yml_id
    el_str = pystache.render(
        templ, {
            "yml_id": yml_id,
            "url": t.fantastic_url.val,
            "price": t.price,