distribution.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. """
  5. import json
  6. import time
  7. import requests
  8. from django.views.generic import TemplateView
  9. from django.shortcuts import render_to_response
  10. from django.http import JsonResponse
  11. from object.ResObject import ResObject
  12. import subprocess
  13. # from gevent.pool import Pool
  14. from model.models import UserModel,UidRtspModel
  15. from object.tkObject import tkObject
  16. from service.CommonService import CommonService
  17. from object.RedisObject import RedisObject
  18. rtspServer = "rtsp.zositech.org,18.222.107.129"
  19. class selectConnectNum(TemplateView):
  20. def post(self, request, *args, **kwargs):
  21. request.encoding = 'utf-8'
  22. request_dict = json.loads(request.body.decode('utf-8'))
  23. return self.select(request_dict)
  24. def get(self, request, *args, **kwargs):
  25. request.encoding = 'utf-8'
  26. request_dict = request.GET
  27. return self.select(request_dict)
  28. # def select(self, request_dict):
  29. # uid = 'xixixixiixixixixix'
  30. # response = ResObject()
  31. # redisObj = RedisObject(db=1)
  32. # rtko = tkObject(rank=1)
  33. # rtsp_stream = rtko.encrypt(data=uid)
  34. # res = redisObj.z_revrange('url')
  35. # url = res[0]
  36. # rtspUrl = str(url) + rtsp_stream
  37. # return response.json(0, res=rtspUrl)
  38. def select(self, request_dict):
  39. response = ResObject()
  40. redisObj = RedisObject(db=1)
  41. urls = rtspServer.split(',')
  42. httpPrefix = 'http://'
  43. rtspPrefix = 'rtsp://'
  44. postfix = ':10008/api/v1/pushers'
  45. for url in urls:
  46. res = redisObj.get_data(url)
  47. print(res)
  48. class storageConnectNum(TemplateView):
  49. def post(self, request, *args, **kwargs):
  50. request.encoding = 'utf-8'
  51. request_dict = json.loads(request.body.decode('utf-8'))
  52. return self.storage(request_dict)
  53. def get(self, request, *args, **kwargs):
  54. request.encoding = 'utf-8'
  55. request_dict = request.GET
  56. return self.storage(request_dict)
  57. def storage(self, request_dict):
  58. response = ResObject()
  59. redisObj = RedisObject(db=1)
  60. urls = rtspServer.split(',')
  61. httpPrefix = 'http://'
  62. # rtspPrefix = 'rtsp://'
  63. postfix = ':10008/api/v1/pushers'
  64. for url in urls:
  65. apiUrl = httpPrefix + url + postfix
  66. try:
  67. selectRtsp = requests.get(url=apiUrl, timeout=5)
  68. connectNum = selectRtsp.json()['total']
  69. except Exception as e:
  70. connectNum = -1
  71. redisObj.set_data(url, connectNum)
  72. value1 = redisObj.get_data(key='rtsp.zositech.org')
  73. print(value1)
  74. return response.json(0, res='yes')