text: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  
  # @Time        : 2021/4/7 7:20 下午
  # @Author      : linksdl
  # @ProjectName : acs-project-cloud_computing
  # @File        : mock_request.py
  
  import requests
  import random
  import ast
  import time
  
  seeds = 'zyxwvutsrqponmlkjihgfedcba0123456789'
  cities = ['London', 'Birmingham', 'Manchester', 'Leeds',
            'Newcastle', 'Birstall', 'Glasgow', 'Liverpool', 'York', 'Bristol']
  iot_ids = []
  url = 'https://azureiotproject.azurewebsites.net/api/httptriggeriot'
  
  # url ='http://localhost:7071/api/HttpTriggerIOT'
  
  
  def mock_sub(nums):
      for i in range(nums):
          iot_id = ''.join(random.sample(seeds, k=15))
          city = cities[random.randint(0, len(cities) - 1)]
          if iot_id not in iot_ids:
              iot_ids.append(iot_id)
              params = {'iot_id': iot_id, 'city_name': city, 'req_type': 'add_sub'}
              res = requests.get(url, params=params)
              response = res.text
              dict = ast.literal_eval(response)
              print('Device subscribe successfully.-------', dict['success'])
  
  
  def mock_cancel(nums):
      for i in range(nums):
          iot_id = iot_ids[i]
          city = cities[random.randint(0, len(cities) - 1)]
          params = {'iot_id': iot_id, 'city_name': city, 'req_type': 'del_sub'}
          res = requests.get(url, params=params)
          response = res.text
          # dict = ast.literal_eval(response)
          print('Device cancel subcription successfully.-------', response)
  
  
  def mock_req(num):
      for i in range(num):
          iot_id = iot_ids[i]
          city = cities[random.randint(0, len(cities) - 1)]
          params = {'iot_id': iot_id, 'city_name': city, 'req_type': 'req_data'}
          res = requests.get(url, params=params)
          response = res.text
          dict = ast.literal_eval(response)
          print('Device request the data.-------', dict['success'])
  
  iot_nums = 100
  sub_nums = 100
  req_nums = 100
  del_nums = 50
  while True:
      # sub_nums = random.randint(min, iot_nums)
      mock_sub(sub_nums)
      # time.sleep(1)
      # req_nums = random.randint(1, len(iot_ids))
      mock_req(req_nums)
      # time.sleep(2)
      # del_nums = random.randint(1, min)
      mock_cancel(del_nums)
      # time.sleep(1)
  
  
  
  