Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

python - Script Is Inserting Duplicate Rows To my Table

I'm having issues trying to stop my script to not insert a new row if the icl_dollar_amount is already in my table. Every time I run my script it inserts a new row.

ppc_data.icl_awk table

client id      file total
12345           2000.45

actual result

client id      file total
12345           2000.45
12345           2000.45

expected result

client id      file total
12345           2000.45

code:

    body_l =[]

    for link in url:
        browser = webdriver.Chrome(options=options, 
        executable_path=r'\TESTuser$TESTDocumentschromedriver.exe')
        # if 'P2 Cust ID 908554 File' in fcg_subject:
        browser.get(link)
        body = browser.find_element_by_xpath("//*[contains(text(), 'Total:')]").text
        body_l.append(body)
        icl_dollar_amount = re.findall('(?:[£$€]{1}[,d]+.?d*)', body)[0].split('$', 1)[1]
        icl_dollar_amount_l.append(icl_dollar_amount)
    if not missing_amount:
        logging.info("List is empty")
        print("List is empty")
    count = 0
    for i in range(len(missing_amount)):
        if missing_amount[i] in icl_dollar_amount_l:
            body = body_l[i]
            get_company_id = body.split("Customer Id:", 1)[1][4:10].strip()
            client_id_l.append(get_company_id)
            get_file_total = re.findall('(?:[£$€]{1}[,d]+.?d*)', body)[0].split('$',1)[1]
            file_total_l.append(get_file_total)


return client_id_l, file_total_l

def insertToDb(client_id_l, file_total_l):

    for client_id, file_total in 
            zip(client_id_l,file_total_l):
        if client_id == '000908554':
            ins_file_dtl = """INSERT INTO ppc_data.icl_awk VALUES ('%s', %s)""" % (client_id, file_total)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...