operate_error_cards.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. # devices = Device.get_sim_expire_notify_devices()
  24. #
  25. #
  26. # from cytoolz import groupby
  27. # devMap = groupby('ownerId', devices)
  28. #
  29. # dealerMap = {} # type: Dict[ObjectId, dict]
  30. # for id_,devs in devMap.items():
  31. # try:
  32. # print len(devs)
  33. # if len(devs) <= 1000:
  34. # for dev in devs:
  35. # try:
  36. # devObj = Device.objects.get(logicalCode = dev['logicalCode'])
  37. # devObj.simChargeAuto = True
  38. # devObj.save()
  39. # Device.invalid_device_cache(devObj.devNo)
  40. # print devObj.devNo
  41. # except Exception,e:
  42. # print e
  43. # continue
  44. # except:
  45. # continue
  46. # 打印数据
  47. from apps.web.dealer.tasks import dealer_auto_charge_sim_card
  48. print 'start charege auto card'
  49. dealer_auto_charge_sim_card()
  50. print 'end charge card'