1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- # -*- coding: utf-8 -*-
- #!/usr/bin/env python
- import threading
- import uuid
- import simplejson as json
- import sys
- import datetime
- from apilib.utils_datetime import to_datetime
- from django.conf import settings
- from apps.web.device.models import SIMCard,Device
- from apps.web.constant import Const
- import xlrd
- from xlrd import xldate_as_tuple
- from apps.web.user.models import RechargeRecord
- # 从SIM卡平台上导出来的excel,导入到数据库中,便于流量结算。
- # 1、月末:根据用户的充值情况,把SIM卡数据全部导出来,发给卡商,进行充值。
- # 2、月头:卡商充值后,我们利用import_sim_card脚本,把excel导出来,然后导入到数据库,并执行另外一个脚本update_device_sim_info_from_simdb更新设备的超时时间
- supplier = sys.argv[1]
- excelFile = sys.argv[2]
- if supplier not in ['qiben','hezhou','jieyang']:
- print u'卡供应商必须是qiben、hezhou'
- exit(0)
-
- book = xlrd.open_workbook(excelFile)
- try:
- sheet = book.sheet_by_name("Sheet")
- except Exception,e:
- print 'open excel file error =%s' % e
- exit(0)
- nrows = sheet.nrows
- rows = []
- iccids = []
- for i in range(1, nrows):
- row = sheet.row_values(i)
- try:
- iccids.append(row[1].replace('\t',''))
- except Exception,e:
- print 'some error when update iccid=%s,e=%s' % (row[1],e)
- devIccids = []
- devList= []
- simObjs = SIMCard.objects.filter(iccid__in = iccids)
- print 'ic card from excel,the num is ',len(iccids), 'ic card in db,the num is ',simObjs.count()
- for sim in simObjs:
- if sim.expireTime.day != 30:
- print 'error card'
- print sim.iccid,sim.expireTime.strftime(Const.DATETIME_FMT)
- print 'finished'
|