find_error_expire_card.py 1.7 KB

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