Commit 6c528f44 authored by liyang's avatar liyang

feat:facebook debug

parent 9126b716
This diff is collapsed.
import mysql.connector
import json
# 连接到数据库
db_config = {
"host": "8.142.151.250",
"user": "script",
"password": "changfA123$",
"database": "network_assets"
}
# 读取JSON文件内容
with open('./staticLogicEdgeInfo.json', 'r') as file:
json_data = file.read()
connection = mysql.connector.connect(**db_config)
cursor = connection.cursor()
# 解析JSON内容
parsed_data = json.loads(json_data)
# 设置 group_concat_max_len,设置返回字符串长度限制为 1,000,000 字符
cursor.execute("SET SESSION group_concat_max_len = 1000000")
# 将JSON内容转换为一行
compressed_json = json.dumps(parsed_data, separators=(',', ':'))
# 执行SQL查询语句
sql_query = """
SELECT
country_code AS countryCode,
CONCAT(
'{"countryCode": "', REPLACE(country_code, '"', '\\"'), '", ',
'"ASInfoList": [',
GROUP_CONCAT(
CONCAT(
'{"topology": false, "ASType": "', REPLACE(type, '"', '\\"'),
'", "linkedNumber": ', connect_degree,
', "ASNumber": ', as_number,
', "ASDegrees": ', transmit_degree,
', "countryCode": "', REPLACE(country_code, '"', '\\"'), '"}'
)
SEPARATOR ', '
),
'], ',
'"countryName": "', REPLACE(country, '"', '\\"'), '"}'
) AS result
FROM as_info
GROUP BY country_code, country
"""
cursor.execute(sql_query)
query_result = cursor.fetchall()
# 关闭数据库连接
cursor.close()
connection.close()
# 将查询结果转换为正确格式的数据
formatted_result = []
for row in query_result:
country_code = row[0]
result_data = row[1]
# 转换非字符串类型为字符串
if isinstance(result_data, (list, tuple)):
result_data = [str(item) for item in result_data]
# # 构建 JSON 数据
# json_data = {
# "countryCode": country_code,
# "ASInfoList": result_data
# }
data = json.loads(result_data)
formatted_result.append(data)
# 将结果导出到 JSON 文件
output_file_path = "./output.json"
with open(output_file_path, "w", encoding="utf-8") as json_file:
json.dump(formatted_result, json_file, indent=4, ensure_ascii=False)
print(f"查询结果已导出到 {output_file_path}")
# 将压缩后的内容写入文件
with open('staticLogicEdgeInfo.json', 'w') as file:
file.write(compressed_json)
\ No newline at end of file
......@@ -102,13 +102,16 @@ def parse_time_string(time_str):
new_time_str = time_str.replace("年", "/").replace("月", "/").replace("日", "")
dt_object = datetime.datetime.strptime(new_time_str, '%Y/%m/%d')
else:
# new_time_str = time_str.replace("月", "/").replace("日", "")
# dt_object = datetime.datetime.strptime(new_time_str, '%m/%d')
current_year = datetime.datetime.now().year
new_time_str = time_str.replace("月", "/").replace("日", f"/{current_year} ")
dt_object = datetime.datetime.strptime(new_time_str, '%m/%d/%Y %H:%M')
return dt_object.timestamp()
if ":" in time_str:
new_time_str = f"{current_year}/" + time_str.replace("月", "/").replace("日", " ")
dt_object = datetime.datetime.strptime(new_time_str, '%Y/%m/%d %H:%M')
else:
new_time_str = f"{current_year}/" + time_str.replace("月", "/").replace("日", "")
dt_object = datetime.datetime.strptime(new_time_str, '%Y/%m/%d')
timestamp = dt_object.timestamp()
return timestamp
def parse_ltn_time_string(time_str):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment