updateCmpKindId.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #coding=utf-8
  2. '''
  3. Created on 2016年6月13日
  4. @author: uas
  5. '''
  6. from pymongo.mongo_client import MongoClient
  7. from util_common import Constant
  8. import csv
  9. cli=MongoClient(Constant.MONGODB_URL)
  10. db=cli.spider
  11. rows_cmp=db.component_temp_0607.find({'cmp_kiid':None})
  12. rows_original=db.component_original.find({},{'_id':False,'code':True,'lastkind':True})
  13. with open('newtranslate.csv',newline='') as csvfile:
  14. reader=csv.reader(csvfile,delimiter=',')
  15. relation_dict=dict()
  16. for index,row in enumerate(reader):
  17. if index==0:
  18. continue
  19. relation_dict[row[1]]=row[2]
  20. rows_original_list=list()
  21. for r in rows_original:
  22. rows_original_list.append(r)
  23. print(len(rows_original_list))
  24. for index,r in enumerate(rows_cmp):
  25. if rows_original_list[r['cmp_id']-1]['code']==r['cmp_code']:
  26. print(index)
  27. uuid=relation_dict.get(rows_original_list[r['cmp_id']-1]['lastkind'])
  28. print(rows_original_list[r['cmp_id']-1]['lastkind']+''+str(uuid))
  29. if uuid is not None:
  30. db.component_temp_0607.update({'_id':r['_id']},{'$set':{'cmp_kiid':uuid}})