Files
Sklearn/sync/DistrictStatRent.py
T
2019-05-07 11:33:15 +08:00

32 lines
996 B
Python

import common
from common import configs as cfg
prod_district_stat = common.get_mongodb_collection(cfg.MONGO_URI, "fangjia", "district_stat_rent")
test_district_stat = common.get_mongodb_collection(cfg.TEST_URI, "fangjia", "district_stat_rent")
for index in prod_district_stat.list_indexes():
keys = list()
for key in index["key"]:
keys.append((key, index["key"][key]))
print(index)
if "unique" in index:
test_district_stat.create_index(keys, background=True, unique=index["unique"])
else:
test_district_stat.create_index(keys, background=True)
sync_condition = {
"city": "上海",
"region": "长宁",
"end_month_date": {"$gt": common.parse_date("2018-03-01")}
}
total = prod_district_stat.count(sync_condition)
count = 0
for dbo in prod_district_stat.find(sync_condition, no_cursor_timeout=True).batch_size(1000):
count += 1
test_district_stat.save(dbo)
if count % 1000 == 0:
print(str(count) + "/" + str(total))