优化同步问题
This commit is contained in:
@@ -13,8 +13,6 @@ district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_
|
|||||||
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
||||||
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
||||||
|
|
||||||
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
|
||||||
|
|
||||||
# 银行code
|
# 银行code
|
||||||
bank_typecode = ["160100", "160101", "160102", "160103", "160104", "160105", "160106", "160107", "160108", "160109",
|
bank_typecode = ["160100", "160101", "160102", "160103", "160104", "160105", "160106", "160107", "160108", "160109",
|
||||||
"160110",
|
"160110",
|
||||||
@@ -26,7 +24,6 @@ bank_typecode = ["160100", "160101", "160102", "160103", "160104", "160105", "16
|
|||||||
"160144",
|
"160144",
|
||||||
"160145", "160146", "160147", "160148", "160149", "160150", "160151", "160152", "160200"]
|
"160145", "160146", "160147", "160148", "160149", "160150", "160151", "160152", "160200"]
|
||||||
|
|
||||||
log.info("开始执行周边银行配套入库")
|
|
||||||
|
|
||||||
def find_around_by_location(city, location):
|
def find_around_by_location(city, location):
|
||||||
"""
|
"""
|
||||||
@@ -77,37 +74,45 @@ def find_around_by_location(city, location):
|
|||||||
print(e)
|
print(e)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def deal(city, lng, lat):
|
def deal(city, lng, lat):
|
||||||
location = [lng, lat]
|
location = [lng, lat]
|
||||||
bank_df = find_around_by_location(city, location)
|
bank_df = find_around_by_location(city, location)
|
||||||
return bank_df
|
return bank_df
|
||||||
|
|
||||||
for city_item in city_dict:
|
|
||||||
city = city_item['display']
|
|
||||||
log.info('开始查找' + city + '周边银行')
|
|
||||||
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
|
||||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
|
||||||
if len(seaweed_df) <= 0:
|
|
||||||
continue
|
|
||||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
|
||||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
|
||||||
seaweed_df['bank'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
|
||||||
|
|
||||||
actions = list()
|
def do():
|
||||||
log.info(city + '周边银行开始入库')
|
log.info("开始执行周边银行配套入库")
|
||||||
for index, item in seaweed_df.iterrows():
|
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
||||||
try:
|
for city_item in city_dict:
|
||||||
# 周边配套库中历史原因,id可能不为小区id
|
city = city_item['display']
|
||||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
log.info('开始查找' + city + '周边银行')
|
||||||
'district_name': item['name']}, {'$set': {'bank': item['bank'], 'city': item['city'], 'region': item['region'],
|
seaweed_df = pd.DataFrame(
|
||||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||||
actions.append(action)
|
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
||||||
except Exception as e:
|
if len(seaweed_df) <= 0:
|
||||||
print(e)
|
continue
|
||||||
if len(actions) == 5000:
|
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||||
|
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||||
|
seaweed_df['bank'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
||||||
|
|
||||||
|
actions = list()
|
||||||
|
log.info(city + '周边银行开始入库')
|
||||||
|
for index, item in seaweed_df.iterrows():
|
||||||
|
try:
|
||||||
|
# 周边配套库中历史原因,id可能不为小区id
|
||||||
|
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||||
|
'district_name': item['name']},
|
||||||
|
{'$set': {'bank': item['bank'], 'city': item['city'], 'region': item['region'],
|
||||||
|
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}},
|
||||||
|
upsert=True)
|
||||||
|
actions.append(action)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if len(actions) == 5000:
|
||||||
|
district_facilitys_conn.bulk_write(actions)
|
||||||
|
actions.clear()
|
||||||
|
if len(actions) > 0:
|
||||||
district_facilitys_conn.bulk_write(actions)
|
district_facilitys_conn.bulk_write(actions)
|
||||||
actions.clear()
|
actions.clear()
|
||||||
if len(actions) > 0:
|
log.info(city + '周边银行入库完毕')
|
||||||
district_facilitys_conn.bulk_write(actions)
|
|
||||||
actions.clear()
|
|
||||||
log.info(city + '周边银行入库完毕')
|
|
||||||
|
|||||||
@@ -13,12 +13,9 @@ district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_
|
|||||||
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
||||||
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
||||||
|
|
||||||
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
|
||||||
|
|
||||||
# 交通code
|
# 交通code
|
||||||
bus_typecode = ["150700","150500"]
|
bus_typecode = ["150700","150500"]
|
||||||
|
|
||||||
log.info("开始执行周边交通配套入库")
|
|
||||||
|
|
||||||
def find_around_by_location(city, location):
|
def find_around_by_location(city, location):
|
||||||
"""
|
"""
|
||||||
@@ -75,33 +72,37 @@ def deal(city, lng, lat):
|
|||||||
bus_df = find_around_by_location(city, location)
|
bus_df = find_around_by_location(city, location)
|
||||||
return bus_df
|
return bus_df
|
||||||
|
|
||||||
for city_item in city_dict:
|
|
||||||
city = city_item['display']
|
|
||||||
log.info('开始查找' + city + '周边交通')
|
|
||||||
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
|
||||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(
|
|
||||||
10000)))
|
|
||||||
if len(seaweed_df) <= 0:
|
|
||||||
continue
|
|
||||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
|
||||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
|
||||||
seaweed_df['bus'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
|
||||||
|
|
||||||
actions = list()
|
def do():
|
||||||
log.info(city + '周边交通开始入库')
|
log.info("开始执行周边交通配套入库")
|
||||||
for index, item in seaweed_df.iterrows():
|
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
||||||
try:
|
for city_item in city_dict:
|
||||||
# 周边配套库中历史原因,id可能不为小区id
|
city = city_item['display']
|
||||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
log.info('开始查找' + city + '周边交通')
|
||||||
'district_name': item['name']}, {'$set': {'bus': item['bus'], 'city': item['city'], 'region': item['region'],
|
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(
|
||||||
actions.append(action)
|
10000)))
|
||||||
except Exception as e:
|
if len(seaweed_df) <= 0:
|
||||||
print(e)
|
continue
|
||||||
if len(actions) == 5000:
|
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||||
district_facilitys_conn.bulk_write(actions)
|
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||||
actions.clear()
|
seaweed_df['bus'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
||||||
if len(actions) > 0:
|
|
||||||
district_facilitys_conn.bulk_write(actions)
|
actions = list()
|
||||||
actions.clear()
|
log.info(city + '周边交通开始入库')
|
||||||
log.info(city + '周边交通入库完毕')
|
for index, item in seaweed_df.iterrows():
|
||||||
|
try:
|
||||||
|
# 周边配套库中历史原因,id可能不为小区id
|
||||||
|
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||||
|
'district_name': item['name']}, {'$set': {'bus': item['bus'], 'city': item['city'], 'region': item['region'],
|
||||||
|
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
||||||
|
actions.append(action)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if len(actions) == 5000:
|
||||||
|
district_facilitys_conn.bulk_write(actions)
|
||||||
|
actions.clear()
|
||||||
|
if len(actions) > 0:
|
||||||
|
district_facilitys_conn.bulk_write(actions)
|
||||||
|
actions.clear()
|
||||||
|
log.info(city + '周边交通入库完毕')
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import district_bank as bank
|
||||||
|
import district_bus as bus
|
||||||
|
import district_hospital as hospital
|
||||||
|
import district_school as school
|
||||||
|
import district_subway as subway
|
||||||
|
import district_supermarket as supermarket
|
||||||
|
|
||||||
type = 'all'
|
type = 'all'
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
@@ -8,34 +14,22 @@ print("输出类型" + type)
|
|||||||
|
|
||||||
if type is not None:
|
if type is not None:
|
||||||
if type == 'bank':
|
if type == 'bank':
|
||||||
import district_bank as bank
|
bank.do()
|
||||||
bank
|
|
||||||
elif type == 'bus':
|
elif type == 'bus':
|
||||||
import district_bus as bus
|
import district_bus as bus
|
||||||
bus
|
bus.do()
|
||||||
elif type == 'hospital':
|
elif type == 'hospital':
|
||||||
import district_hospital as hospital
|
hospital.do()
|
||||||
hospital
|
|
||||||
elif type == 'school':
|
elif type == 'school':
|
||||||
import district_school as school
|
school.do()
|
||||||
school
|
|
||||||
elif type == 'subway':
|
elif type == 'subway':
|
||||||
import district_subway as subway
|
subway.do()
|
||||||
subway
|
|
||||||
elif type == 'supermarket':
|
elif type == 'supermarket':
|
||||||
import district_supermarket as supermarket
|
supermarket.do()
|
||||||
supermarket
|
|
||||||
else:
|
else:
|
||||||
import district_bank as bank
|
bank.do()
|
||||||
import district_bus as bus
|
bus.do()
|
||||||
import district_hospital as hospital
|
hospital.do()
|
||||||
import district_school as school
|
school.do()
|
||||||
import district_subway as subway
|
subway.do()
|
||||||
import district_supermarket as supermarket
|
supermarket.do()
|
||||||
|
|
||||||
bank
|
|
||||||
bus
|
|
||||||
hospital
|
|
||||||
school
|
|
||||||
subway
|
|
||||||
supermarket
|
|
||||||
|
|||||||
@@ -13,12 +13,9 @@ district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_
|
|||||||
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
||||||
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
||||||
|
|
||||||
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
|
||||||
|
|
||||||
# 医院code
|
# 医院code
|
||||||
hospital_typecode = ["090100", "090101", "090200"]
|
hospital_typecode = ["090100", "090101", "090200"]
|
||||||
|
|
||||||
log.info("开始执行周边医院配套入库")
|
|
||||||
|
|
||||||
def find_around_by_location(city, location):
|
def find_around_by_location(city, location):
|
||||||
"""
|
"""
|
||||||
@@ -69,37 +66,46 @@ def find_around_by_location(city, location):
|
|||||||
print(e)
|
print(e)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def deal(city, lng, lat):
|
def deal(city, lng, lat):
|
||||||
location = [lng, lat]
|
location = [lng, lat]
|
||||||
hospital_df = find_around_by_location(city, location)
|
hospital_df = find_around_by_location(city, location)
|
||||||
return hospital_df
|
return hospital_df
|
||||||
|
|
||||||
for city_item in city_dict:
|
|
||||||
city = city_item['display']
|
|
||||||
log.info('开始查找' + city + '周边医院')
|
|
||||||
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
|
||||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
|
||||||
if len(seaweed_df) <= 0:
|
|
||||||
continue
|
|
||||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
|
||||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
|
||||||
seaweed_df['hospital'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
|
||||||
|
|
||||||
actions = list()
|
def do():
|
||||||
log.info(city + '周边医院开始入库')
|
log.info("开始执行周边医院配套入库")
|
||||||
for index, item in seaweed_df.iterrows():
|
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
||||||
try:
|
for city_item in city_dict:
|
||||||
# 周边配套库中历史原因,id可能不为小区id
|
city = city_item['display']
|
||||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
log.info('开始查找' + city + '周边医院')
|
||||||
'district_name': item['name']}, {'$set': {'hospital': item['hospital'], 'city': item['city'], 'region': item['region'],
|
seaweed_df = pd.DataFrame(
|
||||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||||
actions.append(action)
|
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
||||||
except Exception as e:
|
if len(seaweed_df) <= 0:
|
||||||
print(e)
|
continue
|
||||||
if len(actions) == 5000:
|
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||||
|
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||||
|
seaweed_df['hospital'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
||||||
|
|
||||||
|
actions = list()
|
||||||
|
log.info(city + '周边医院开始入库')
|
||||||
|
for index, item in seaweed_df.iterrows():
|
||||||
|
try:
|
||||||
|
# 周边配套库中历史原因,id可能不为小区id
|
||||||
|
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||||
|
'district_name': item['name']}, {
|
||||||
|
'$set': {'hospital': item['hospital'], 'city': item['city'],
|
||||||
|
'region': item['region'],
|
||||||
|
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}},
|
||||||
|
upsert=True)
|
||||||
|
actions.append(action)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if len(actions) == 5000:
|
||||||
|
district_facilitys_conn.bulk_write(actions)
|
||||||
|
actions.clear()
|
||||||
|
if len(actions) > 0:
|
||||||
district_facilitys_conn.bulk_write(actions)
|
district_facilitys_conn.bulk_write(actions)
|
||||||
actions.clear()
|
actions.clear()
|
||||||
if len(actions) > 0:
|
log.info(city + '周边医院入库完毕')
|
||||||
district_facilitys_conn.bulk_write(actions)
|
|
||||||
actions.clear()
|
|
||||||
log.info(city + '周边医院入库完毕')
|
|
||||||
|
|||||||
@@ -13,12 +13,9 @@ district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_
|
|||||||
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
||||||
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
||||||
|
|
||||||
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
|
||||||
|
|
||||||
# 教育code
|
# 教育code
|
||||||
school_typecode = ["141200", "141201", "141202", "141203", "141204"]
|
school_typecode = ["141200", "141201", "141202", "141203", "141204"]
|
||||||
|
|
||||||
log.info("开始执行周边教育配套入库")
|
|
||||||
|
|
||||||
def find_around_by_location(city, location):
|
def find_around_by_location(city, location):
|
||||||
"""
|
"""
|
||||||
@@ -74,32 +71,36 @@ def deal(city, lng, lat):
|
|||||||
school_df = find_around_by_location(city, location)
|
school_df = find_around_by_location(city, location)
|
||||||
return school_df
|
return school_df
|
||||||
|
|
||||||
for city_item in city_dict:
|
|
||||||
city = city_item['display']
|
|
||||||
log.info('开始查找' + city + '周边教育')
|
|
||||||
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
|
||||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
|
||||||
if len(seaweed_df) <= 0:
|
|
||||||
continue
|
|
||||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
|
||||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
|
||||||
seaweed_df['school'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
|
||||||
|
|
||||||
actions = list()
|
def do():
|
||||||
log.info(city + '周边教育开始入库')
|
log.info("开始执行周边教育配套入库")
|
||||||
for index, item in seaweed_df.iterrows():
|
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
||||||
try:
|
for city_item in city_dict:
|
||||||
# 周边配套库中历史原因,id可能不为小区id
|
city = city_item['display']
|
||||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
log.info('开始查找' + city + '周边教育')
|
||||||
'district_name': item['name']}, {'$set': {'school': item['school'], 'city': item['city'], 'region': item['region'],
|
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
||||||
actions.append(action)
|
if len(seaweed_df) <= 0:
|
||||||
except Exception as e:
|
continue
|
||||||
print(e)
|
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||||
if len(actions) == 5000:
|
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||||
district_facilitys_conn.bulk_write(actions)
|
seaweed_df['school'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
||||||
actions.clear()
|
|
||||||
if len(actions) > 0:
|
actions = list()
|
||||||
district_facilitys_conn.bulk_write(actions)
|
log.info(city + '周边教育开始入库')
|
||||||
actions.clear()
|
for index, item in seaweed_df.iterrows():
|
||||||
log.info(city + '周边教育入库完毕')
|
try:
|
||||||
|
# 周边配套库中历史原因,id可能不为小区id
|
||||||
|
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||||
|
'district_name': item['name']}, {'$set': {'school': item['school'], 'city': item['city'], 'region': item['region'],
|
||||||
|
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
||||||
|
actions.append(action)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if len(actions) == 5000:
|
||||||
|
district_facilitys_conn.bulk_write(actions)
|
||||||
|
actions.clear()
|
||||||
|
if len(actions) > 0:
|
||||||
|
district_facilitys_conn.bulk_write(actions)
|
||||||
|
actions.clear()
|
||||||
|
log.info(city + '周边教育入库完毕')
|
||||||
|
|||||||
@@ -13,13 +13,10 @@ district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_
|
|||||||
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
||||||
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
||||||
|
|
||||||
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
|
||||||
|
|
||||||
# 地铁code
|
# 地铁code
|
||||||
subway_typecode = ["150500"]
|
subway_typecode = ["150500"]
|
||||||
|
|
||||||
log.info("开始执行周边地铁配套入库")
|
|
||||||
|
|
||||||
def find_around_by_location(city, location):
|
def find_around_by_location(city, location):
|
||||||
"""
|
"""
|
||||||
查找周边poi
|
查找周边poi
|
||||||
@@ -75,33 +72,37 @@ def deal(city, lng, lat):
|
|||||||
subway_df = find_around_by_location(city, location)
|
subway_df = find_around_by_location(city, location)
|
||||||
return subway_df
|
return subway_df
|
||||||
|
|
||||||
for city_item in city_dict:
|
|
||||||
city = city_item['display']
|
|
||||||
log.info('开始查找' + city + '周边地铁')
|
|
||||||
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
|
||||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(
|
|
||||||
10000)))
|
|
||||||
if len(seaweed_df) <= 0:
|
|
||||||
continue
|
|
||||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
|
||||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
|
||||||
seaweed_df['subway'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
|
||||||
|
|
||||||
actions = list()
|
def do():
|
||||||
log.info(city + '周边地铁开始入库')
|
log.info("开始执行周边地铁配套入库")
|
||||||
for index, item in seaweed_df.iterrows():
|
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
||||||
try:
|
for city_item in city_dict:
|
||||||
# 周边配套库中历史原因,id可能不为小区id
|
city = city_item['display']
|
||||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
log.info('开始查找' + city + '周边地铁')
|
||||||
'district_name': item['name']}, {'$set': {'subway': item['subway'], 'city': item['city'], 'region': item['region'],
|
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(
|
||||||
actions.append(action)
|
10000)))
|
||||||
except Exception as e:
|
if len(seaweed_df) <= 0:
|
||||||
print(e)
|
continue
|
||||||
if len(actions) == 5000:
|
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||||
district_facilitys_conn.bulk_write(actions)
|
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||||
actions.clear()
|
seaweed_df['subway'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
||||||
if len(actions) > 0:
|
|
||||||
district_facilitys_conn.bulk_write(actions)
|
actions = list()
|
||||||
actions.clear()
|
log.info(city + '周边地铁开始入库')
|
||||||
log.info(city + '周边地铁入库完毕')
|
for index, item in seaweed_df.iterrows():
|
||||||
|
try:
|
||||||
|
# 周边配套库中历史原因,id可能不为小区id
|
||||||
|
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||||
|
'district_name': item['name']}, {'$set': {'subway': item['subway'], 'city': item['city'], 'region': item['region'],
|
||||||
|
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
||||||
|
actions.append(action)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if len(actions) == 5000:
|
||||||
|
district_facilitys_conn.bulk_write(actions)
|
||||||
|
actions.clear()
|
||||||
|
if len(actions) > 0:
|
||||||
|
district_facilitys_conn.bulk_write(actions)
|
||||||
|
actions.clear()
|
||||||
|
log.info(city + '周边地铁入库完毕')
|
||||||
|
|||||||
@@ -13,12 +13,10 @@ district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_
|
|||||||
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
||||||
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
server_area_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'server_area')
|
||||||
|
|
||||||
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
|
||||||
|
|
||||||
# 商场code
|
# 商场code
|
||||||
supermarket_typecode = ["060100","060101","060102"]
|
supermarket_typecode = ["060100","060101","060102"]
|
||||||
|
|
||||||
log.info("开始执行周边商场配套入库")
|
|
||||||
|
|
||||||
def find_around_by_location(city, location):
|
def find_around_by_location(city, location):
|
||||||
"""
|
"""
|
||||||
@@ -76,33 +74,36 @@ def deal(city, lng, lat):
|
|||||||
return supermarket_df
|
return supermarket_df
|
||||||
|
|
||||||
|
|
||||||
for city_item in city_dict:
|
def do():
|
||||||
city = city_item['display']
|
log.info("开始执行周边商场配套入库")
|
||||||
log.info('开始查找' + city + '周边商场')
|
city_dict = list(server_area_conn.find({'city_grade': {'$ne': 0}}, {'display': 1}))
|
||||||
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
for city_item in city_dict:
|
||||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(
|
city = city_item['display']
|
||||||
10000)))
|
log.info('开始查找' + city + '周边商场')
|
||||||
if len(seaweed_df) <= 0:
|
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||||
continue
|
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(
|
||||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
10000)))
|
||||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
if len(seaweed_df) <= 0:
|
||||||
seaweed_df['supermarket'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
continue
|
||||||
|
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||||
|
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||||
|
seaweed_df['supermarket'] = seaweed_df.apply(lambda x: deal(x['city'], x['lng'], x['lat']), axis=1)
|
||||||
|
|
||||||
actions = list()
|
actions = list()
|
||||||
log.info(city + '周边商场开始入库')
|
log.info(city + '周边商场开始入库')
|
||||||
for index, item in seaweed_df.iterrows():
|
for index, item in seaweed_df.iterrows():
|
||||||
try:
|
try:
|
||||||
# 周边配套库中历史原因,id可能不为小区id
|
# 周边配套库中历史原因,id可能不为小区id
|
||||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||||
'district_name': item['name']}, {'$set': {'supermarket': item['supermarket'], 'city': item['city'], 'region': item['region'],
|
'district_name': item['name']}, {'$set': {'supermarket': item['supermarket'], 'city': item['city'], 'region': item['region'],
|
||||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
||||||
actions.append(action)
|
actions.append(action)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
if len(actions) == 5000:
|
if len(actions) == 5000:
|
||||||
district_facilitys_conn.bulk_write(actions)
|
district_facilitys_conn.bulk_write(actions)
|
||||||
actions.clear()
|
actions.clear()
|
||||||
if len(actions) > 0:
|
if len(actions) > 0:
|
||||||
district_facilitys_conn.bulk_write(actions)
|
district_facilitys_conn.bulk_write(actions)
|
||||||
actions.clear()
|
actions.clear()
|
||||||
log.info(city + '周边商场入库完毕')
|
log.info(city + '周边商场入库完毕')
|
||||||
|
|||||||
Reference in New Issue
Block a user