12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #!/usr/bin/env python
- # encoding: utf-8
- """
- @CreateTime: 2021/8/5 9:54
- @Author: lxc
- @LastEditTime:
- @Desctiption: 上行数据:上传(更新)摄像设备配置文件到云平台
- """
- import configparser
- import time
- import os
- import requests
- from requests_toolbelt.multipart import MultipartEncoder
- import LogOut
- def post_upload_file():
- """
- 上传二进制字节流文件
- :return: "SUCCESS" or "ERROR"
- """
- now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
- headers = {
- "Authorization": token,
- "userAccount": '1'
- }
- multipart_encoder = MultipartEncoder(
- fields={
- "file": (FILENAME, open(config_path, 'rb'), "multipart/form-data")
- }
- )
- headers['Content-Type'] = multipart_encoder.content_type
- requests.urllib3.disable_warnings()
- url = "https://management.super-sight.com.cn:8000/system/api/cameraManagement/cameraInfoFileUpload"
- ret = requests.post(url=url, headers=headers, data=multipart_encoder, verify=False)
- if ret.status_code == 200 and "success" in ret.text:
- _logger.info("%s: ret.text=%s" % (now_time, ret.text))
- _logger.info("%s: ret.status_code=%s" % (now_time, ret.status_code))
- else:
- _logger.error("%s: ret.text=%s" % (now_time, ret.text))
- _logger.error("%s: ret.status_code=%s" % (now_time, ret.status_code))
- def main():
- """
- 判断文件是否需要更新
- :return: 无
- """
- run_time = 0
- file_time = 0
- while True:
- now_time = time.time()
- if now_time - run_time > 60*60:
- run_time = now_time
- status = os.path.exists(config_path)
- if status:
- file_new_time = os.path.getmtime(config_path)
- if file_time != file_new_time:
- file_time = file_new_time
- post_upload_file()
- else:
- _logger.error("未找到目标文件:" + config_path)
- if __name__ == '__main__':
- _logger = LogOut.Log('uploadCameraProfile')
- # 创建读取配置文件对象
- config = configparser.ConfigParser()
- config.read("config.ini", encoding="utf-8")
- # 获取通用配置项
- SECTION = "General" # 读取的SECTION标签
- token = config.get(SECTION, 'token')
- appId = config.get(SECTION, 'appId')
- FILEPATH = r"/home/sencott/imageCapture/configration_files"
- FILENAME = "云平台导入海上平台摄像配置文件模板.xlsx"
- config_path = os.path.join(FILEPATH, FILENAME)
- main()
|