123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- # -*- coding: utf-8 -*-
- #!/usr/bin/env python
- import os, sys
- import threading
- import uuid
- import xlrd
- from xlrd import xldate_as_tuple
- 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)
- from apps.web.device.models import SIMCard,Device
- from apps.web.constant import Const
- from apilib.utils_datetime import to_datetime
- 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("sheet1")
- 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','').upper())
- iccids.append(row[1].replace('\t','').lower())
- except Exception,e:
- print 'some error when update iccid=%s,e=%s' % (row[1],e)
- devIccids = []
- devList= []
- count = 0
- devObjs = Device.objects.filter(iccid__in = iccids,ownerId__ne = None,simStatus = 'updated')
- for devObj in devObjs:
- if not devObj.ownerId:
- continue
-
- if devObj.simChargeAuto:
- print devObj.ownerId,devObj.iccid
|