批量从excel文件中传输数据

批量从excel文件中传输数据:

import openpyxl
import hashlib
import requests
import json
import time
wb = openpyxl.load_workbook('pass_che.xlsx')

# 获取workbook中所有的表格
sheets = wb.sheetnames

def main(city, phone,time=time.time()):
    time = str(time).split('.')[0]
    token = 'yyyyyy'    # 标识接口认证 
    data = {
        'name': '先生',
        'mobile': phone,
        'city': city,
        'brand': '未知',
        'series': '未知',
        'model': '未知',
        'kilometer': '10',
        'licensed_date_year': '2010 3',
        'is_operation': '',
        'is_accidented': ''
    }
    data = json.dumps(data)
    # print(data)

    sign = hashlib.md5((data + token + time).encode("utf-8")).hexdigest()
    post_data = {
        'token': token,
        'sign': sign,
        'time': time,
        'data': data,
    }
    url = 'xxxx'  # 公司机密
    r = requests.post(url, data=post_data)
    print(r.text)
    print('查入成功')

# 循环遍历所有sheet
for i in range(len(sheets)):
    sheet = wb[sheets[i]]

    for r in range(1, sheet.max_row + 1):
        if r == 1:
            city = str(sheet.cell(row=r, column=1).value)
            phone = str(sheet.cell(row=r, column=2).value)
            print(city,phone)
            main(city,phone)
        else:
            city = str(sheet.cell(row=r, column=1).value)
            phone = str(sheet.cell(row=r, column=2).value)
            print(city,phone)
            main(city,phone)
posted @ 2020-04-29 16:15  black__star  阅读(244)  评论(0编辑  收藏  举报