check_error_cards.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. import os, sys
  4. import threading
  5. import uuid
  6. import xlrd
  7. from xlrd import xldate_as_tuple
  8. import simplejson as json
  9. import datetime
  10. from django.conf import settings
  11. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  12. sys.path.insert(0, PROJECT_ROOT)
  13. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'configs.production')
  14. from script.base import init_env
  15. init_env(interactive = False)
  16. from apps.web.device.models import SIMCard,Device
  17. from apps.web.constant import Const
  18. from apilib.utils_datetime import to_datetime
  19. from apps.web.user.models import RechargeRecord
  20. # 从SIM卡平台上导出来的excel,导入到数据库中,便于流量结算。
  21. # 1、月末:根据用户的充值情况,把SIM卡数据全部导出来,发给卡商,进行充值。
  22. # 2、月头:卡商充值后,我们利用import_sim_card脚本,把excel导出来,然后导入到数据库,并执行另外一个脚本update_device_sim_info_from_simdb更新设备的超时时间
  23. supplier = sys.argv[1]
  24. excelFile = sys.argv[2]
  25. if supplier not in ['qiben','hezhou','jieyang']:
  26. print u'卡供应商必须是qiben、hezhou'
  27. exit(0)
  28. book = xlrd.open_workbook(excelFile)
  29. try:
  30. sheet = book.sheet_by_name("sheet1")
  31. except Exception,e:
  32. print 'open excel file error =%s' % e
  33. exit(0)
  34. nrows = sheet.nrows
  35. rows = []
  36. iccids = []
  37. for i in range(1, nrows):
  38. row = sheet.row_values(i)
  39. try:
  40. iccids.append(row[1].replace('\t','').upper())
  41. iccids.append(row[1].replace('\t','').lower())
  42. except Exception,e:
  43. print 'some error when update iccid=%s,e=%s' % (row[1],e)
  44. devIccids = []
  45. devList= []
  46. count = 0
  47. devObjs = Device.objects.filter(iccid__in = iccids,ownerId__ne = None,simStatus = 'updated')
  48. for devObj in devObjs:
  49. if not devObj.ownerId:
  50. continue
  51. if devObj.simChargeAuto:
  52. print devObj.ownerId,devObj.iccid