Example #1
0
def info_ccmn():
    global err_log
    global err_flag
    err_flag = False

    print("Executing " + os.path.basename(__file__) + "...")
    print("Current datetime " + str(datetime.datetime.now()))
    print('開始 長江有色金屬網現貨#1鎳 報價資料收集程序...')

    #LOG File
    log_name = "scrp_ccmn_" + datetime.datetime.now().strftime(
        "%Y%m%d") + ".txt"
    err_log = open(log_name, 'a', encoding='UTF-8')

    tStart = time.time()  #計時開始
    err_log.write("\n\n\n*** LOG datetime  " + str(datetime.datetime.now()) +
                  " ***\n")
    err_log.write("Executing " + os.path.basename(__file__) + "...\n\n")

    chrome_options = Options()
    #chrome_options.add_argument('--headless')
    #chrome_options.add_argument('--disable-gpu')
    driver = webdriver.Chrome(chrome_options=chrome_options)

    price = []
    #讀取~1美元對新台幣即期賣出價
    try:
        price = scrp_ccmn01(driver)
        print(price)
    except Exception as e:
        err_flag = True
        print("info_ccmn -> scrp_ccmn01 資料抓取錯誤,例外訊息如下:")
        print(e.args)
        print("\n\n")
        err_log.write("info_ccmn -> scrp_ccmn01 資料抓取錯誤,例外訊息如下:\n")
        err_log.write(str(e.args))
        err_log.write("\n\n")

    #關閉瀏覽器視窗
    driver.quit()

    #寫入資料庫
    if len(price) > 0:
        #print(price)
        db_process2(price)

    tEnd = time.time()  #計時結束
    err_log.write("\n\n\n結轉耗時 %f sec\n" % (tEnd - tStart))  #會自動做進位
    err_log.write("*** End LOG ***\n\n")

    # Close File
    err_log.close()

    #如果執行過程無錯誤,最後刪除log file
    if err_flag == False:
        os.remove(log_name)

    print('\n\n\n本次 長江有色金屬網現貨#1鎳 市場報價資訊抓取結束,等待下次執行...\n\n\n')
Example #2
0
def cnfeol13_getdata(datalist, arg_itemno):
    global err_flag
    global err_log

    arg_flag01 = True
    for i1, i2 in enumerate(datalist):
        tempidx_1 = datalist[i1][1]
        print(month_01, tempidx_1)
        if tempidx_1 == month_01 and arg_flag01:
            arg_1 = datalist[i1][3]
            arg_flag01 = False

    if not arg_flag01:
        print(arg_1)
        list01 = max_min_Val(arg_1)
        price_list = [[arg_itemno, today_03, list01[0], list01[1], list01[2]]]
        print(price_list)
    else:
        price_list = []

    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #3
0
def cnfeol10_getdata(datalist):
    global err_flag
    global err_log

    for i1, i2 in enumerate(datalist):
        if len(datalist[i1]) == 4:
            tempidx_1 = datalist[i1][0]
            arg_1 = datalist[i1][1]
            if tempidx_1 == '高碳75c7.0P<0.2':
                target_str = re.compile(r'([0-9]+-[0-9]+)(北方地区)')
                mo = target_str.search(arg_1)
                if mo:
                    print(tempidx_1, arg_1)
                    print(mo.group(1))
                    list01 = max_min_Val(arg_1)

    price_list = [['02014', today, list01[0], list01[1], list01[2]]]
    print(price_list)

    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #4
0
def cnfeol05_getdata(datalist):
    global err_flag
    global err_log

    for i1, i2 in enumerate(datalist):
        tempidx_1 = datalist[i1][6]
        arg_1 = datalist[i1][4]
        if (tempidx_1 == '内蒙'):
            print(arg_1)
            list01 = max_min_Val(arg_1)
        elif (tempidx_1 == '江苏'):
            print(arg_1)
            list02 = max_min_Val(arg_1)
        elif (tempidx_1 == '辽宁'):
            print(arg_1)
            list03 = max_min_Val(arg_1)
        elif (tempidx_1 == '山东'):
            print(arg_1)
            list04 = max_min_Val(arg_1)
    price_list = [['02003', today, list01[0], list01[1], list01[2]],
                  ['02004', today, list02[0], list02[1], list02[2]],
                  ['02005', today, list03[0], list03[1], list03[2]],
                  ['02006', today, list04[0], list04[1], list04[2]]]
    print(price_list)

    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #5
0
def cnfeol04_getdata(NewsContent):
    global err_flag
    global err_log

    target_Hstr = re.compile(r'NI8-10%([0-9]+)-([0-9]+)(-)/([0-9]+)-([0-9]+)')
    High_Ni = target_Hstr.search(NewsContent)

    target_Lstr = re.compile(
        r'NI1.5-1.8%([0-9]+)-([0-9]+)(-)/([0-9]+)-([0-9]+)')
    Low_Ni = target_Lstr.search(NewsContent)

    print(High_Ni)
    H_max = High_Ni.group(3)
    H_min = High_Ni.group(4)
    H_vul = str((decimal.Decimal(H_max) + decimal.Decimal(H_min)) / 2)

    print(Low_Ni)
    L_max = Low_Ni.group(3)
    L_min = Low_Ni.group(4)
    L_vul = str((decimal.Decimal(L_max) + decimal.Decimal(L_min)) / 2)

    price_list = [['02001', today, H_vul, H_max, H_min],
                  ['02002', today, L_vul, L_max, L_min]]
    print(price_list)

    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #6
0
def cnfeol03_getdata(datalist):
    global err_flag
    global err_log

    for i1, i2 in enumerate(datalist):
        tempidx_1 = datalist[i1][0]
        tempidx_2 = datalist[i1][1]
        arg_1 = datalist[i1][4]
        if (tempidx_1 == '南非铬矿') and (tempidx_2 == '42-44%精矿'):
            print(arg_1)
            list01 = max_min_Val(arg_1)
        elif (tempidx_1 == '南非铬矿') and (tempidx_2 == '40-42%精矿'):
            print(arg_1)
            list02 = max_min_Val(arg_1)
        elif (tempidx_1 == '土耳其铬矿') and (tempidx_2 == '40-42%块矿'):
            print(arg_1)
            list03 = max_min_Val(arg_1)
        elif (tempidx_1 == '伊朗铬矿') and (tempidx_2 == '40-42%块矿'):
            print(arg_1)
            list04 = max_min_Val(arg_1)
    price_list = [['02060', today, list01[0], list01[1], list01[2]],
                  ['02061', today, list02[0], list02[1], list02[2]],
                  ['02062', today, list03[0], list03[1], list03[2]],
                  ['02063', today, list04[0], list04[1], list04[2]]]
    print(price_list)
    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #7
0
def cnfeol02_ship_getdata(datalist):
    global err_flag
    global err_log

    print(datalist)

    arg_Zambales = datalist[1][2]
    list_Zambales = max_min_Val(arg_Zambales)
    arg_Surigao = datalist[2][1]
    list_Surigao = max_min_Val(arg_Surigao)
    arg_Sulawesi = datalist[3][2]
    list_Sulawesi = max_min_Val(arg_Sulawesi)

    price_list = [
        ['02054', today, list_Zambales[0], list_Zambales[1], list_Zambales[2]],
        ['02055', today, list_Surigao[0], list_Surigao[1], list_Surigao[2]],
        ['02056', today, list_Sulawesi[0], list_Sulawesi[1], list_Sulawesi[2]]
    ]
    print(price_list)

    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #8
0
def cnfeol07_getdata(datalist):
    global err_flag
    global err_log

    arg_1 = datalist[2][6]
    list01 = max_min_Val(arg_1)
    price_list = [['02008', today, list01[0], list01[1], list01[2]]]
    print(price_list)
    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #9
0
def cnfeol08_getdata(datalist):
    global err_flag
    global err_log

    max_vul = datalist[1][2]
    min_vul = datalist[1][1]
    vul = str((decimal.Decimal(max_vul) + decimal.Decimal(min_vul)) / 2)
    price_list = [['02009', today, vul, max_vul, min_vul]]
    print(price_list)

    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #10
0
def cnfeol06_getdata(NewsContent):
    global err_flag
    global err_log

    target_Hstr = re.compile(r'华北([0-9]+)-([0-9]+)')
    High_Cr = target_Hstr.search(NewsContent)

    print(High_Cr)
    H_max = High_Cr.group(1)
    H_min = High_Cr.group(2)
    H_vul = str((decimal.Decimal(H_max) + decimal.Decimal(H_min)) / 2)

    price_list = [['02007', today, H_vul, H_max, H_min]]
    print(price_list)

    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #11
0
def cnfeol02_indonesia_getdata(datalist):
    global err_flag
    global err_log

    arg_FOB01 = datalist[1][4]
    list_FOB01 = max_min_Val(arg_FOB01)

    arg_CIF01 = datalist[3][2]
    list_CIF01 = max_min_Val(arg_CIF01)

    price_list = [[
        '02030', today, list_FOB01[0], list_FOB01[1], list_FOB01[2]
    ], ['02031', today, list_CIF01[0], list_CIF01[1], list_CIF01[2]]]

    #寫入資料庫
    if len(price_list) > 0:
        print(price_list)
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #12
0
def cnfeol09_getdata(datalist):
    global err_flag
    global err_log

    arg_flag01 = True
    arg_flag02 = True
    arg_flag03 = True
    arg_flag04 = True
    for i1, i2 in enumerate(datalist):
        if len(datalist[i1]) == 7:
            tempidx_1 = datalist[i1][1]
            tempidx_2 = datalist[i1][6]
            arg_1 = datalist[i1][4]
            if tempidx_1 == 'femn65c7.0P≤0.2' and tempidx_2 == '山西' and arg_flag01:
                list01 = max_min_Val(arg_1)
                arg_flag01 = False
            elif tempidx_1 == 'femn75c7.0P≤0.2' and tempidx_2 == '广西' and arg_flag02:
                list02 = max_min_Val(arg_1)
                arg_flag02 = False
            elif tempidx_1 == 'femn75c7.0P≤0.2' and tempidx_2 == '山西' and arg_flag03:
                list03 = max_min_Val(arg_1)
                arg_flag03 = False
            elif tempidx_1 == 'femn75c7.0P≤0.2' and tempidx_2 == '贵州' and arg_flag04:
                list04 = max_min_Val(arg_1)
                arg_flag04 = False

    price_list = [['02010', today, list01[0], list01[1], list01[2]],
                  ['02011', today, list02[0], list02[1], list02[2]],
                  ['02012', today, list03[0], list03[1], list03[2]],
                  ['02013', today, list04[0], list04[1], list04[2]]]
    print(price_list)
    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)
Example #13
0
def cnfeol02_philippines_getdata(datalist):
    global err_flag
    global err_log

    print(datalist)

    arg_FOB01 = datalist[1][4]
    list_FOB01 = max_min_Val(arg_FOB01)

    arg_FOB02 = datalist[2][3]
    list_FOB02 = max_min_Val(arg_FOB02)

    arg_FOB03 = datalist[3][3]
    list_FOB03 = max_min_Val(arg_FOB03)

    arg_FOB04 = datalist[4][3]
    list_FOB04 = max_min_Val(arg_FOB04)

    arg_FOB05 = datalist[5][3]
    list_FOB05 = max_min_Val(arg_FOB05)

    arg_FOB06 = datalist[6][3]
    list_FOB06 = max_min_Val(arg_FOB06)

    arg_FOB07 = datalist[7][3]
    list_FOB07 = max_min_Val(arg_FOB07)

    arg_FOB08 = datalist[8][3]
    list_FOB08 = max_min_Val(arg_FOB08)

    arg_FOB09 = datalist[9][3]
    list_FOB09 = max_min_Val(arg_FOB09)

    arg_FOB10 = datalist[10][3]
    list_FOB10 = max_min_Val(arg_FOB10)

    arg_FOB11 = datalist[11][3]
    list_FOB11 = max_min_Val(arg_FOB11)

    arg_CIF01 = datalist[13][3]
    list_CIF01 = max_min_Val(arg_CIF01)

    arg_CIF02 = datalist[14][3]
    list_CIF02 = max_min_Val(arg_CIF02)

    arg_CIF03 = datalist[15][3]
    list_CIF03 = max_min_Val(arg_CIF03)

    arg_CIF04 = datalist[16][3]
    list_CIF04 = max_min_Val(arg_CIF04)

    arg_CIF05 = datalist[17][3]
    list_CIF05 = max_min_Val(arg_CIF05)

    arg_CIF06 = datalist[18][3]
    list_CIF06 = max_min_Val(arg_CIF06)

    arg_CIF07 = datalist[19][3]
    list_CIF07 = max_min_Val(arg_CIF07)

    arg_CIF08 = datalist[20][3]
    list_CIF08 = max_min_Val(arg_CIF08)

    arg_CIF09 = datalist[21][3]
    list_CIF09 = max_min_Val(arg_CIF09)

    arg_CIF10 = datalist[22][3]
    list_CIF10 = max_min_Val(arg_CIF10)

    arg_CIF11 = datalist[23][3]
    list_CIF11 = max_min_Val(arg_CIF11)

    price_list = [
        ['02032', today, list_FOB01[0], list_FOB01[1], list_FOB01[2]],
        ['02033', today, list_FOB02[0], list_FOB02[1], list_FOB02[2]],
        ['02034', today, list_FOB03[0], list_FOB03[1], list_FOB03[2]],
        ['02035', today, list_FOB04[0], list_FOB04[1], list_FOB04[2]],
        ['02036', today, list_FOB05[0], list_FOB05[1], list_FOB05[2]],
        ['02037', today, list_FOB06[0], list_FOB06[1], list_FOB06[2]],
        ['02038', today, list_FOB07[0], list_FOB07[1], list_FOB07[2]],
        ['02039', today, list_FOB08[0], list_FOB08[1], list_FOB08[2]],
        ['02040', today, list_FOB09[0], list_FOB09[1], list_FOB09[2]],
        ['02041', today, list_FOB10[0], list_FOB10[1], list_FOB10[2]],
        ['02042', today, list_FOB11[0], list_FOB11[1], list_FOB11[2]],
        ['02043', today, list_CIF01[0], list_CIF01[1], list_CIF01[2]],
        ['02044', today, list_CIF02[0], list_CIF02[1], list_CIF02[2]],
        ['02045', today, list_CIF03[0], list_CIF03[1], list_CIF03[2]],
        ['02046', today, list_CIF04[0], list_CIF04[1], list_CIF04[2]],
        ['02047', today, list_CIF05[0], list_CIF05[1], list_CIF05[2]],
        ['02048', today, list_CIF06[0], list_CIF06[1], list_CIF06[2]],
        ['02049', today, list_CIF07[0], list_CIF07[1], list_CIF07[2]],
        ['02050', today, list_CIF08[0], list_CIF08[1], list_CIF08[2]],
        ['02051', today, list_CIF09[0], list_CIF09[1], list_CIF09[2]],
        ['02052', today, list_CIF10[0], list_CIF10[1], list_CIF10[2]],
        ['02053', today, list_CIF11[0], list_CIF11[1], list_CIF11[2]]
    ]

    print(price_list)

    #寫入資料庫
    if len(price_list) > 0:
        result = db_process2(price_list)
        err_flag = result[0]
        err_log.write(result[1])
        print(result)