女帝的日常,通过数值一键筛选id

#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))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值