import pymongo import pandas import json from pymongo import MongoClient client = MongoClient() client2 = MongoClient() db = client["baojia"] collection = db["qdxm"] db2 = client2["dinge"] collection2 = db2["de-collection"] def clean(debh): if "附注" in debh: position = debh.find("附注") debh = debh[:position] if "*" in debh: position = debh.find("*") debh = debh[:position] if debh.endswith("换"): debh = debh[:-1] if "[" in debh: position = debh.find("[") debh = debh[:position-1] return debh for post in collection.find({"biao_id": '688990c88230558391ff533c', 'Dwgcbh': '004'}): for entry in (post['__children']): ##print(entry['清单编码']) cleaned = clean(entry['清单编码']) if cleaned.startswith("D"): continue dercj = (entry['dercj']) post2 = collection2.find_one({'zhuanye': '土建', 'DEBH' : cleaned }) if post2 == None: if '-F' in cleaned : pass else: print("DE not found") print(cleaned) print(post) else: mongo_cl = post2['mongo_cl'] mongo_jx = post2['mongo_jx'] mongo_rg = post2['mongo_rg'] for item in dercj: bm = item[1] if bm == '人材机编码': continue if "商品砼" in item[2]: continue hit = False for rg in mongo_rg: if rg['CLBH'] == bm: hit = True for cl in mongo_cl: if cl['CLBH'] == bm: hit = True for jx in mongo_jx: if jx['jxbh'] == bm: hit = True if (not hit) and item[1] != 'S00001' and item[1] != '410000F' and item[1] != 'JD0001' and (not '二类工' in item[2]) and (not '水泥' in item[2]) and item[1] != '01270100' and cleaned !='5-28' and cleaned != '4-3' and (not '砂浆' in item[2]): print(cleaned) print("special case found for" + str(item)) print("来自清单") print(post['bt']) print(post) break