|
@@ -17,6 +17,46 @@ sleep_time = 60 # 每多少秒扫描一次
|
|
url1_private = "http://10.14.86.127:9081/device/auth"
|
|
url1_private = "http://10.14.86.127:9081/device/auth"
|
|
url2_private = "http://10.14.86.127:9081/device/data/callback"
|
|
url2_private = "http://10.14.86.127:9081/device/data/callback"
|
|
|
|
|
|
|
|
+error_bag_json = "/mnt/disk001/dcl_data_process/src/python2/pjisuv/callback-errorBag.json"
|
|
|
|
+
|
|
|
|
+def parse_json_to_string_array(file_path):
|
|
|
|
+ try:
|
|
|
|
+ # 打开并读取JSON文件(Python 2中不支持encoding参数,需要使用codecs模块或处理文件读取后的编码)
|
|
|
|
+ with open(file_path, 'r') as file:
|
|
|
|
+ # 读取文件内容
|
|
|
|
+ file_content = file.read()
|
|
|
|
+ # 解析JSON内容(Python 2中json.loads用于解析字符串)
|
|
|
|
+ data = json.loads(file_content.decode('utf-8')) # 假设文件是UTF-8编码,这里需要手动解码
|
|
|
|
+
|
|
|
|
+ # 检查数据是否是一个列表,并且列表中的元素是否是字符串
|
|
|
|
+ if isinstance(data, list):
|
|
|
|
+ for item in data:
|
|
|
|
+ if not isinstance(item, basestring): # Python 2中字符串类型包括str和unicode,用basestring检查
|
|
|
|
+ raise ValueError("JSON数组中的元素不是字符串")
|
|
|
|
+ return data
|
|
|
|
+ else:
|
|
|
|
+ return []
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return []
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def list_to_json_file(data, file_path):
|
|
|
|
+ """
|
|
|
|
+ 将列表转换为JSON格式并写入指定的文件路径。
|
|
|
|
+ 如果文件已存在,则覆盖它。
|
|
|
|
+
|
|
|
|
+ 参数:
|
|
|
|
+ data (list): 要转换为JSON的列表。
|
|
|
|
+ file_path (str): 要写入JSON数据的文件路径。
|
|
|
|
+ """
|
|
|
|
+ # 将列表转换为JSON格式的字符串,并确保输出为UTF-8编码的字符串
|
|
|
|
+ json_data = json.dumps(data, ensure_ascii=False, indent=4)
|
|
|
|
+ json_data_utf8 = json_data.encode('utf-8') # 编码为UTF-8
|
|
|
|
+
|
|
|
|
+ # 以写入模式打开文件,如果文件已存在则覆盖
|
|
|
|
+ with open(file_path, 'w') as file:
|
|
|
|
+ # 将UTF-8编码的JSON字符串写入文件
|
|
|
|
+ file.write(json_data_utf8)
|
|
|
|
|
|
def add_hour(date_string, hour_number):
|
|
def add_hour(date_string, hour_number):
|
|
original_date = datetime.strptime(date_string, "%Y-%m-%d-%H-%M-%S")
|
|
original_date = datetime.strptime(date_string, "%Y-%m-%d-%H-%M-%S")
|
|
@@ -92,13 +132,11 @@ if __name__ == '__main__':
|
|
"secretKey": json_object['secretKey']
|
|
"secretKey": json_object['secretKey']
|
|
}
|
|
}
|
|
json_data1 = json.dumps(data1)
|
|
json_data1 = json.dumps(data1)
|
|
- # logging.info("授权接口请求中: %s" % url1_private)
|
|
|
|
request1 = urllib2.Request(url1_private, json_data1,
|
|
request1 = urllib2.Request(url1_private, json_data1,
|
|
headers={'Content-Type': 'application/json'})
|
|
headers={'Content-Type': 'application/json'})
|
|
response1 = urllib2.urlopen(request1)
|
|
response1 = urllib2.urlopen(request1)
|
|
result_json1 = response1.read()
|
|
result_json1 = response1.read()
|
|
result_object1 = json.loads(result_json1)
|
|
result_object1 = json.loads(result_json1)
|
|
- # logging.info("授权接口请求结果为: %s", result_object1)
|
|
|
|
try:
|
|
try:
|
|
access_token = result_object1.get('data').get('accessToken')
|
|
access_token = result_object1.get('data').get('accessToken')
|
|
logging.info("bag文件为:%s" % str(json_object['rosBagPath']))
|
|
logging.info("bag文件为:%s" % str(json_object['rosBagPath']))
|
|
@@ -151,11 +189,12 @@ if __name__ == '__main__':
|
|
bucket.delete_object(old_ros_bag_path)
|
|
bucket.delete_object(old_ros_bag_path)
|
|
bucket.batch_delete_objects(old_delete_list)
|
|
bucket.batch_delete_objects(old_delete_list)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- logging.exception("报错: %s" % str(e))
|
|
|
|
|
|
+ error_bag_list = parse_json_to_string_array(error_bag_json)
|
|
|
|
+ error_bag_list.append(parse_prefix)
|
|
|
|
+ list_to_json_file(error_bag_list, error_bag_json)
|
|
continue
|
|
continue
|
|
|
|
|
|
if upload:
|
|
if upload:
|
|
- logging.info("json_object 包含 'userId' 字段,是手动上传的包,userId为:", json_object['userId'])
|
|
|
|
data2 = {
|
|
data2 = {
|
|
'userId': json_object['userId'],
|
|
'userId': json_object['userId'],
|
|
"dataName": new_date,
|
|
"dataName": new_date,
|
|
@@ -167,7 +206,6 @@ if __name__ == '__main__':
|
|
"triggerId": trigger_id
|
|
"triggerId": trigger_id
|
|
}
|
|
}
|
|
else:
|
|
else:
|
|
- logging.info("json_object 不包含 'userId' 字段,是自动采集的包")
|
|
|
|
data2 = {
|
|
data2 = {
|
|
"dataName": new_date,
|
|
"dataName": new_date,
|
|
"dataSize": bucket.get_object_meta(json_object['rosBagPath']).content_length,
|
|
"dataSize": bucket.get_object_meta(json_object['rosBagPath']).content_length,
|