Ejemplo n.º 1
0
def huddersfield_main():
    new_lists = []
    with open("huddersfield.json", "r", encoding="latin1") as f:
        new_lists = json.load(f)
    for item in new_lists:
        try:
            write_data = {}
            write_data.update({
                'cloth_pattern_number': item['cloth_pattern_number'],
                'image_url': item['image_url'],
                'cloth_bunch': item['cloth_bunch'],
                'composition_1': item['composition1'] if 'composition1' in item else "",
                'supplier_name': 'Huddersfield Fine Worsteds',
                "weight_gms": item['weight'] if 'weight_gm' in item else "",
                "design": item['design'] if 'design' in item else "",
                'colour': item['colour'] if 'colour' in item else "",
                "width": "",
                "weight_ozs": "",
                "selvedge": "",
                "dye": "",
                "weave": item['weave'] if 'weave' in item else "",
                "price_per_meter":item['price'] if 'price' in item else ""
            })
        except Exception as e:
            print("error in scrapped data")
        try:
            pyMsql.save_scabal(write_data)
        except Exception as e:
            print("Error to save database")

    return
Ejemplo n.º 2
0
def Standeven_main():
    new_list = []
    with open("standeven_new.json", "r", encoding="latin1") as f:
        new_list = json.load(f)

    for item in new_list:
        print(item['cloth_pattern_number'])
        write_data = {
            'cloth_pattern_number': item['cloth_pattern_number'],
            'image_url': item['image_url'],
            'cloth_bunch': item['cloth_bunch'],
            'composition_1':
            item['composition1'] if 'composition1' in item else "",
            'supplier_name': 'Standeven',
            "weight_gms": item['weight'] if 'weight' in item else "",
            "design": item['design'] if 'design' in item else "",
            'colour': item['colour'] if 'colour' in item else "",
            "width": item['width'] if 'width' in item else "",
            "weight_ozs": "",
            "selvedge": "",
            "dye": "",
            "weave": item['weave'] if 'weave' in item else "",
            "price_per_meter": float(get_price(item['cloth_pattern_number']))
        }
        try:
            pyMsql.save_scabal(write_data)
        except Exception as e:
            print("save data error", e, item['cloth_pattern_number'])
Ejemplo n.º 3
0
def lovat_main():

    with open("Lovat_new.json", "r", encoding="latin1") as f:
        lovat_list = json.load(f)
    for lovat in lovat_list:
        write_data = {
            'cloth_pattern_number': lovat['cloth_pattern_number'],
            'image_url': lovat['image_url'],
            'cloth_bunch': lovat['cloth_bunch'],
            'composition_1':
            lovat['composition1'] if 'composition1' in lovat else "",
            'supplier_name': 'Lovat',
            "weight_gms": lovat['weight'] if 'weight' in lovat else "",
            "design": lovat['design'] if 'design' in lovat else "",
            'colour': lovat['colour'] if 'colour' in lovat else "",
            "width": lovat['width'] if 'width' in lovat else "",
            "weight_ozs": "",
            "selvedge": "",
            "dye": "",
            "weave": lovat['weave'] if 'weave' in lovat else "",
            "price_per_meter": float(get_price(lovat['cloth_bunch']))
        }

        pyMsql.save_scabal(write_data)

    return
Ejemplo n.º 4
0
def fox_main():
    fox_code_list = gsheet.parse_from_google_for_fox()
    new_fox_list = []
    with open("fox_brother_new_update_last.json", "r", encoding="latin1") as f:
        new_fox_list = json.load(f)

    print(len(new_fox_list))
    cnt = 0
    empty_pattenr_count = 1
    for fox in new_fox_list:
        pattern_number = get_cloth_pattern_number(fox_code_list, fox)
        if len(str(pattern_number)) == 0:
            pattern_number = "None_Fox_" + str(empty_pattenr_count)
            empty_pattenr_count += 1
        try:
            write_data = {
                "cloth_pattern_number":
                pattern_number,
                "image_url":
                fox['image_url'],
                "cloth_bunch":
                fox['qds'],
                "supplier_name":
                fox['supplier_name'],
                "colour":
                "",
                "composition_1":
                fox['composition1'] if 'composition1' in fox else "",
                "composition_2":
                fox['cloth_bunch'],
                "price_per_meter":
                fox['price_per_meter'] if 'price_per_meter' in fox else "",
                "weight_gms":
                fox['weight'] if 'weight' in fox else "",
                "design":
                "",
                "width":
                fox['width'] if 'width' in fox else "",
                "weight_ozs":
                "",
                "selvedge":
                "",
                "dye":
                "",
                "weave":
                "",
            }
        except Exception as e:
            print("error =>", e)
        print("***", cnt)
        cnt = cnt + 1
        try:
            pyMsql.save_scabal(write_data)
            print("saved to wp database: article_id =>",
                  write_data['cloth_pattern_number'])
        except Exception as e:
            print("error =>", e, pattern_number)

    return
Ejemplo n.º 5
0
def Lora_main():

    with open("loro_piana.json", "r", encoding="latin1") as f:
        loro_list = json.load(f)
    for loro in loro_list:
        pyMsql.save_scabal(loro)
    print(len(loro_list))
    return
Ejemplo n.º 6
0
def harrison_main():
    g_itemInfo = []
    img_list = []
    with open("harrsion_datas_new.json", "r", encoding="latin1") as f:
        img_list = json.load(f)
    with open("harrison_price.json", "r", encoding="latin1") as f:
        g_itemInfo = json.load(f)

    for image_item in img_list:
        item_info = get_item_info(g_itemInfo,
                                  str(image_item['pattern_number']))
        write_data = {}
        write_data.update({
            "cloth_pattern_number": image_item['pattern_number'],
            "image_url": image_item['image_url'],
            "cloth_bunch": image_item['bunch'],
            "supplier_name": image_item['Supplier'],
            "colour": "",
            "composition_1": "",
            "price_per_meter": "",
            "weight_gms": "",
            "design": "",
            "width": "",
            "weight_ozs": "",
            "selvedge": "",
            "dye": "",
            "weave": "",
        })
        if len(item_info) > 0:
            write_data.update({
                "composition_1":
                item_info['composition'] if 'composition' in item_info else '',
                "price_per_meter":
                item_info['price_per_meter']
                if 'price_per_meter' in item_info else '',
                'width':
                item_info['width'] if 'width' in item_info else '',
                'weight_gms':
                item_info['weight gms'] if 'weight gms' in item_info else '',
                'weight_ozs':
                item_info['weight ozs'] if 'weight ozs' in item_info else ''
            })
        try:
            pyMsql.save_scabal(write_data)
            print("saved to wp database: article_id =>",
                  write_data['cloth_pattern_number'])
        except Exception as e:
            print("error =>", e, image_item['pattern_number'])
Ejemplo n.º 7
0
def scabal_patch_three():
    for item in patch_list_three:
        article_id = item['id']
        try:
            fabric_api_data = pyFabrics.get_fabric_info_by_id(article_id)
            if len(fabric_api_data['FABRICS']) > 0:
                fabric_data_detail = pyFabrics.get_fabric_data_detail(fabric_api_data['FABRICS'][0])
                fabric_data_detail.update({
                    "price_per_meter": float(item['ppm']),
                    "supplier_name": "Scabal",
                    'image_url': pyScrapScabal.get_image_url(fabric_data_detail['cloth_pattern_number'])
                })
                pyMsql.save_scabal(fabric_data_detail)
                print(fabric_data_detail)
                print("saved to wp database: article_id =>", article_id)
        except Exception as e:
            print("Error in Scabal Main =>", e)
Ejemplo n.º 8
0
def scabal_main():
    scabal_list = gsheet.parse_from_google()
    for scabal_item in scabal_list:
        for article_id in range(scabal_item['articles_from'], scabal_item['articles_to'] + 1):
            try:
                fabric_api_data = pyFabrics.get_fabric_info_by_id(article_id)
                if len(fabric_api_data['FABRICS']) > 0:
                    fabric_data_detail = pyFabrics.get_fabric_data_detail(fabric_api_data['FABRICS'][0])
                    fabric_data_detail.update({
                        "price_per_meter": float(scabal_item['price_per_meter_gbp']),
                        "supplier_name": "Scabal",
                        'image_url': pyScrapScabal.get_image_url(fabric_data_detail['cloth_pattern_number'])
                    })
                    pyMsql.save_scabal(fabric_data_detail)
                    print("saved to wp database: article_id =>", article_id)
            except Exception as e:
                print("Error in Scabal Main =>", e)
Ejemplo n.º 9
0
def scabal_patch_two():

    with open("scabal_missed_pattern_number.txt", "r") as f:
        for line in f.readlines():
            pathch_two_list.append(line.rstrip())

    scabal_list = gsheet.parse_from_google_patch()
    for scabal_item in scabal_list:
        try:
            if str(scabal_item['cloth_pattern_number']) in pathch_two_list:
                scabal_item.update({
                        "supplier_name": "Scabal",
                    'image_url': pyScrapScabal.get_image_url(scabal_item['cloth_pattern_number'])
                })
                pyMsql.save_scabal(scabal_item)
                print("saved to wp database: article_id =>", scabal_item['cloth_pattern_number'])
        except Exception as e:
            print("Error in Scabal Main =>", e)
Ejemplo n.º 10
0
def holland_main():
    new_holand_list = []
    with open("holland_sherry_new_update.json", "r") as f:
        new_holand_list = json.load(f)
    org_holland_list = gsheet.parse_from_google_for_holland()

    for new_holand in new_holand_list:
        write_data = {
            'cloth_pattern_number':
            new_holand['cloth_pattern_number'],
            'image_url':
            new_holand['image_url'],
            'cloth_bunch':
            new_holand['cloth_bunch'],
            'composition_1':
            new_holand['composition1'] if 'composition1' in new_holand else "",
            'supplier_name':
            'Holland and Sherry',
            "weight_gms":
            new_holand['weight_gm'] if 'weight_gm' in new_holand else "",
            "design":
            new_holand['design'] if 'design' in new_holand else "",
            "width":
            "",
            "weight_ozs":
            "",
            "selvedge":
            "",
            "dye":
            "",
            "weave":
            ""
        }
        org_holland = check_exist_in_list(org_holland_list, new_holand)
        if len(org_holland) > 0:
            write_data.update({
                'price_per_meter':
                org_holland['price_per_meter'],
            })
        try:
            pyMsql.save_scabal(write_data)
        except Exception as e:
            print("Error to save database")
    return
Ejemplo n.º 11
0
def dormeuil_main():
    org_dormeuil_list = gsheet.parse_from_google_for_dormeuil()
    new_list = []
    with open("dormeuil_data.json", "r", encoding="latin1") as f:
        new_list = json.load(f)

    # for org in org_dormeuil_list:
    #     try:
    #         pyMsql.save_scabal(org)
    #     except Exception as e:
    #         print("error in =>", org['cloth_pattern_number'])

    for new_item in new_list:
        if len(check_exist_in_list(org_dormeuil_list, new_item)) == 0:
            write_data = {
                'cloth_pattern_number':
                new_item['cloth_pattern_number'],
                'image_url':
                new_item['image_url'],
                'composition_1':
                str(new_item['composition_1']).upper(),
                'weight_ozs':
                new_item['weight'],
                'cloth_bunch':
                new_item['bunch'],
                'supplier_name':
                'Dormeuil',
                'price_per_meter':
                get_bunch_number_price(new_item['cloth_pattern_number']),
                'design':
                '',
                'width':
                ''
            }
            try:
                pyMsql.save_scabal(write_data)
            except Exception as e:
                print("error in =>", new_item['cloth_pattern_number'])