优化异常捕获

This commit is contained in:
Jian Shen
2022-06-18 21:00:50 +08:00
parent e7e1f2c80c
commit 118e23a078
3 changed files with 129 additions and 98 deletions
+43 -33
View File
@@ -35,53 +35,63 @@ def find_around_by_location(city, location):
:param location: :param location:
:return: :return:
""" """
bank_df = elastic_client.scan_to_data_frame('amap_poi', { try:
"_source": ["name"], bank_df = elastic_client.scan_to_data_frame('amap_poi', {
"query": { "_source": ["name"],
"bool": { "query": {
"must_not": [ "bool": {
{ "must_not": [
"term": { {
"status": { "term": {
"value": 1 "status": {
"value": 1
}
} }
} }
} ],
], "filter": [
"filter": [ {"terms": {
{"terms": { "typecode": bank_typecode
"typecode": bank_typecode }},
}}, {
{ "term": {
"term": { "cityname": {
"cityname": { "value": city
"value": city }
}
},
{
"geo_distance": {
"distance": 1000,
"location": location
} }
} }
}, ]
{ }
"geo_distance": {
"distance": 1000,
"location": location
}
}
]
} }
} });
}); if len(bank_df) > 0:
if len(bank_df) > 0: return bank_df['name'].tolist()
return bank_df['name'].tolist() return []
return [] except Exception as e:
print(e)
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
### 临时后续注释
after_dongguan = False
for city_item in city_dict: for city_item in city_dict:
city = city_item['display'] city = city_item['display']
log.info('开始查找' + city + '周边银行') log.info('开始查找' + city + '周边银行')
if city == '东莞':
after_dongguan = True
if not after_dongguan:
continue
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}}, 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))) {'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10 seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
+42 -32
View File
@@ -27,43 +27,47 @@ def find_around_by_location(city, location):
:param location: :param location:
:return: :return:
""" """
bus_df = elastic_client.scan_to_data_frame('amap_poi', { try:
"_source": ["name"], bus_df = elastic_client.scan_to_data_frame('amap_poi', {
"query": { "_source": ["name"],
"bool": { "query": {
"must_not": [ "bool": {
{ "must_not": [
"term": { {
"status": { "term": {
"value": 1 "status": {
"value": 1
}
} }
} }
} ],
], "filter": [
"filter": [ {"terms": {
{"terms": { "typecode": bus_typecode
"typecode": bus_typecode }},
}}, {
{ "term": {
"term": { "cityname": {
"cityname": { "value": city
"value": city }
}
},
{
"geo_distance": {
"distance": 1000,
"location": location
} }
} }
}, ]
{ }
"geo_distance": {
"distance": 1000,
"location": location
}
}
]
} }
} });
}); if len(bus_df) > 0:
if len(bus_df) > 0: return bus_df['name'].tolist()
return bus_df['name'].tolist() return []
return [] except Exception as e:
print(e)
return []
def deal(city, lng, lat): def deal(city, lng, lat):
@@ -71,10 +75,16 @@ 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
### 临时后续注释
after_dongguan = False
for city_item in city_dict: for city_item in city_dict:
city = city_item['display'] city = city_item['display']
log.info('开始查找' + city + '周边交通') log.info('开始查找' + city + '周边交通')
if city == '东莞':
after_dongguan = True
if not after_dongguan:
continue
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}}, 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( {'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(
10000))) 10000)))
+44 -33
View File
@@ -27,44 +27,48 @@ def find_around_by_location(city, location):
:param location: :param location:
:return: :return:
""" """
supermarket_df = elastic_client.scan_to_data_frame('amap_poi', { try:
"_source": ["name"], supermarket_df = elastic_client.scan_to_data_frame('amap_poi', {
"query": { "_source": ["name"],
"bool": { "query": {
"must_not": [ "bool": {
{ "must_not": [
"term": { {
"status": { "term": {
"value": 1 "status": {
"value": 1
}
} }
} }
} ],
], "filter": [
"filter": [ {"terms": {
{"terms": { "typecode": supermarket_typecode
"typecode": supermarket_typecode }},
}}, {
{ "term": {
"term": { "cityname": {
"cityname": { "value": city
"value": city }
}
},
{
"geo_distance": {
"distance": 1000,
"location": location
} }
} }
}, ]
{ }
"geo_distance": {
"distance": 1000,
"location": location
}
}
]
} }
} });
}); if len(supermarket_df) > 0:
if len(supermarket_df) > 0: return supermarket_df['name'].tolist()
return supermarket_df['name'].tolist() return []
return [] except Exception as e:
print(e)
print(location)
return []
def deal(city, lng, lat): def deal(city, lng, lat):
location = [lng, lat] location = [lng, lat]
@@ -72,9 +76,16 @@ def deal(city, lng, lat):
return supermarket_df return supermarket_df
### 临时后续注释
after_dongguan = False
for city_item in city_dict: for city_item in city_dict:
city = city_item['display'] city = city_item['display']
log.info('开始查找' + city + '周边商场') log.info('开始查找' + city + '周边商场')
if city == '东莞':
after_dongguan = True
if not after_dongguan:
continue
seaweed_df = pd.DataFrame(list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}}, 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( {'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(
10000))) 10000)))