# -*- coding: utf-8 -*- #!/usr/bin/env python import os, sys import threading import uuid import xlrd from xlrd import xldate_as_tuple from openpyxl import Workbook,load_workbook import simplejson as json import datetime from django.conf import settings PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..') sys.path.insert(0, PROJECT_ROOT) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'configs.production') from script.base import init_env init_env(interactive = False) # 从SIM卡平台上导出来的excel,导入到数据库中,便于流量结算。 # 1、月末:根据用户的充值情况,把SIM卡数据全部导出来,发给卡商,进行充值。 # 2、月头:卡商充值后,我们利用import_sim_card脚本,把excel导出来,然后导入到数据库,并执行另外一个脚本update_device_sim_info_from_simdb更新设备的超时时间 kuaidiFile = sys.argv[1] taobaoFile = sys.argv[2] book = xlrd.open_workbook(kuaidiFile) try: sheet = book.sheet_by_name("sheet1") except Exception,e: print 'open excel file error =%s' % e exit(0) tbBook = load_workbook(taobaoFile) try: tbSheet = tbBook['sheet1'] except Exception,e: print 'open excel file error =%s' % e exit(0) nrows = sheet.nrows tbRows = tbSheet.max_row rows = [] iccids = [] dxIccids = [] # 电信的iccid,不一样哟。设备报上来的比excel的多一位 for i in range(1, nrows): row = sheet.row_values(i) try: orderNos = str(row[8]).replace('\t','').upper().split(',') if not orderNos: continue for orderNo in orderNos: if not orderNo: continue for j in range(1,tbRows): cell = tbSheet.cell(j,22) try: tbOrder = cell.value.replace('\t','').upper() if orderNo in tbOrder: print 'aaa',orderNo cell2 = tbSheet.cell(j,31) cell2.value = 999 except Exception,e: continue except Exception,e: print 'some error when update iccid=%s,e=%s' % (row[1],e) tbBook.save(taobaoFile)