init_property.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # coding=utf-8
  2. '''
  3. Created on 2016年4月5日
  4. 使用mongodb对数组的条件查询快速得到property
  5. @author: ChenHao
  6. '''
  7. from pymongo.mongo_client import MongoClient
  8. from util_common import Constant
  9. '''
  10. 用一开始总结出来的60个初始化
  11. 今后不需要用这段初始化的代码了
  12. @date 2016年4月5日14:22:28
  13. '''
  14. # file_path = "../spider_download/Other/labelAndName.csv"
  15. # fin = open(file_path, "r")
  16. # lines = fin.readlines()
  17. # fin.close()
  18. #
  19. # properties_list = list()
  20. # for index, line in enumerate(lines):
  21. # temp_list = line.split(",")
  22. # d = dict()
  23. # d["id"] = temp_list[0]
  24. # d["labelCn"] = temp_list[1]
  25. # d["labelEn"] = temp_list[2]
  26. # properties_list.append(d)
  27. #
  28. # cli = MongoClient(Constant.MONGODB_URL)
  29. # db = cli.spider
  30. # db.property.insert_many(properties_list)
  31. # cli.close()
  32. '''
  33. 1、得到所有的
  34. '''
  35. cli = MongoClient(Constant.MONGODB_URL)
  36. db = cli.spider
  37. # rs = db.component_original.find().distinct("properties.lable")
  38. # for r in rs:
  39. # print (r)
  40. # print (len(rs))
  41. rs = db.property.find()
  42. print (rs.count())
  43. for r in rs:
  44. print (type(r["id"]))
  45. r["id"] = int(r["id"])
  46. print (type(r["id"]))
  47. db.property.save(r)
  48. cli.close()