import json def del_lot(lots): del_lots = [] with open("delete_lot.txt","r") as f: for line in f.readlines(): lot = line.strip() del_lots.append(lot) return list(set(lots).difference(set(del_lots))) def get_region_lots(s_region): json_file = open("../rg/hygc_rg_region_20210303.json","r") json_data =json.load(json_file) regions = json_data["region"] for region in regions: #print(region) if s_region == region["name"]: return region["lots"] if __name__=="__main__": json_file = open("hygc_screen_region_20210303.json","r") json_data =json.load(json_file) screens = json_data["led_regions"] w = open("lotss.txt","w",encoding="utf-8") for screen in screens: #print(screen) surplus_led_id = screen["surplus_led_id"] floor = screen["floor"] regions = screen["regions"] lots =[] for s_region in regions: s_lots = get_region_lots(s_region) lots = lots +s_lots print(len(lots),lots) res_lots = del_lot(lots) print(len(res_lots),res_lots) w_str="%s,%s,%s,%s\n"%(floor,surplus_led_id,len(res_lots),"|".join(res_lots)) w.write(w_str)