#persons_face.sa 外貌文件
import json
import re
# 读取txt文件
with open('文件路径,要把\变成/', 'r', encoding='utf-8') as file:
lines = file.readlines()
data = []
json_pattern = re.compile(r'\{.*?\}')
for line in lines:
# 去除转义字符
line = line.replace('\\"', '"')
json_objects = json_pattern.findall(line)
for obj in json_objects:
try:
entry = json.loads(obj)
if entry['re'][12] < 70:#条件写这里
data.append(entry['re'][0])
except json.JSONDecodeError as e:
print(f"JSON解析错误: {e} - 行内容: {obj}")
# 输出符合条件的第一个元素构成的列表
print(data)
##persons_value.sa 文件
import json
# 文件在电脑上的地址
with open('路径,要把\变成/', 'r', encoding='utf-8') as file:
file_content = file.read()
try:
data = json.loads(file_content)
except json.JSONDecodeError as e:
print(f"Error decoding JSON: {e}")
exit()
if 're' not in data:
print("'re' key not found in data")
exit()
# 提取并解析每个字符串为字典
result = []
for item in data['re']:
try:
dictionary = json.loads(item)
if isinstance(dictionary, dict) and 'ni' in dictionary:
array = dictionary['ni']
if array[17] in [4,5,6,7,8,9] and array[18] == 0 :#条件写这里
result.append(array)
except json.JSONDecodeError as e:
print(f"Error decoding JSON in item: {e}")
fourth_elements = []
for array in result:
if len(array) > 3:
fourth_elements.append(array[3])
print(fourth_elements)
print(len(fourth_elements))
#根据face文件条件筛选id但去除死人版
import json
import re
# 读取 value 文件内容
with open('地址persons_value.txt', 'r', encoding='utf-8') as file:
file_content = file.read()
try:
value_data = json.loads(file_content)
except json.JSONDecodeError as e:
print(f"Error decoding JSON in value file: {e}")
exit()
# 检查 're' 键是否存在
if 're' not in value_data:
print("'re' key not found in value data")
exit()
# 创建一个包含所有 ni[0] 的集合
ni_ids = set()
for item in value_data['re']:
try:
dictionary = json.loads(item)
if isinstance(dictionary, dict) and 'ni' in dictionary:
ni_ids.add(dictionary['ni'][3])
except json.JSONDecodeError as e:
print(f"Error decoding JSON in value item: {e}")
print(len(ni_ids))
# 读取 face 文件内容
with open('地址/persons_face.txt', 'r', encoding='utf-8') as file:
lines = file.readlines()
data = []
json_pattern = re.compile(r'\{.*?\}')
for line in lines:
# 去除转义字符
line = line.replace('\\"', '"')
json_objects = json_pattern.findall(line)
for obj in json_objects:
try:
entry = json.loads(obj)
# 检查 entry['re'] 是否满足条件,并且 ni_ids 中包含这个 id
if entry['re'][11] <40 and entry['re'][12] <100 :#条件写这里
if entry['re'][0] in ni_ids:
data.append(entry['re'][0])
except json.JSONDecodeError as e:
print(f"JSON解析错误: {e} - 行内容: {obj}")
# 输出符合条件的第一个元素构成的列表
print(data)
print(len(data))