import json
import os
import sys

with open('json.txt', 'r', encoding='utf-8') as f:
    json_list = f.readlines()
json_list = list(set(json_list))
if '[]\n' in json_list:
    json_list.remove('[]\n')
data_list = [json.loads(x[:-1]) for x in json_list]
data_list = [x[0] for x in data_list]

with open('C:/Users/Administrator/Downloads/pb_json_list_240730.json', 'r', encoding='utf-8') as f:
    json_str = f.read()
json_list = json.loads(json_str)[1:]
data_list2 = [json.loads(x[0]) for x in json_list]

docid_data_list = []
for data in data_list:
    docid_list = [x.get('docid') for x in data]
    docid_list = list(set(docid_list))
    if None in docid_list:
        docid_list.remove(None)
    if 0 in docid_list:
        docid_list.remove(0)
    docid_list.sort(key=lambda x: x)
    if data[0].get('docchannel') is not None:
        data[0]['docchannel'] = int(data[0]['docchannel'])
    docid_data_list.append([docid_list, data])

docid_data_list2 = []
for data in data_list2:
    docid_list = [x.get('docid') for x in data]
    docid_list = list(set(docid_list))
    if None in docid_list:
        docid_list.remove(None)
    if 0 in docid_list:
        docid_list.remove(0)
    docid_list.sort(key=lambda x: x)
    data[0]['pb_project_name'] = data[0]['project_name_refind']
    if data[0].get('docchannel') is not None:
        data[0]['docchannel'] = int(data[0]['docchannel'])
    docid_data_list2.append([docid_list, data])

equal_list = []
not_equal_list = []
for docid_list, data in docid_data_list:
    for docid_list2, data2 in docid_data_list2:
        if len(set(docid_list).intersection(set(docid_list2))) > 0:
            if docid_list == docid_list2:
                equal_list.append([data, data2])
            else:
                not_equal_list.append([data, data2])

print('len(data_list)', len(data_list))
print('len(equal_list)', len(equal_list))
print('len(not_equal_list)', len(not_equal_list))
print('='*30)
print('='*30)

for data, data2 in not_equal_list:
    print('data', [[x.get('docid'), x.get('page_time'), x.get('stage')] for x in data[1:]])
    print('data2', [[x.get('docid'), x.get('page_time'), x.get('stage')] for x in data2[1:]])

    for key in set(list(data[0].keys()) + list(data2[0].keys())):
        if key in ['partitionkey', 'has_stage', 'service_days', 'service_time',
                   'nlp_enterprise_attachment', 'nlp_enterprise', 'show_name_refind',
                   'project_name_refind', 'tenderee_contact', 'project2_uuid',
                   'tenderee_phone']:
            continue
        if data[0].get(key) in [0., None, ""] and data2[0].get(key) in [0., None, ""]:
            continue

        if data[0].get(key) != data2[0].get(key):
            print('data.get(key)', key, data[0].get(key))
            print('data2.get(key)', key, data2[0].get(key))
            # if key in ['page_time', 'stage']:
            #     print('data', [[x.get('page_time'), x.get('stage')] for x in data[1:]])
            #     print('data2', [[x.get('page_time'), x.get('stage')] for x in data2[1:]])

    print('='*30)
    input('next')