def add_monitor_area_for_cam_location():
df = pd.read_excel('xxxx.xlsx')
url = '/monitorarea/registerMonitorArea'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
prefix = '{"type":"Point","coordinates":'
postfix = '}'
for _, row in df.iterrows():
try:
camera_id = int(row['gb_channel_id'])
lng = float(row['经度'])
lat = float(row['纬度'])
data={'monitor_obj_type': "location",
'monitor_obj_id': camera_id,
'monitor_geojson': "{}{}{}".format(prefix, [lng, lat], postfix),
'geo_level': 26,
'grid_count': "",
'agg_flag': False,
'presets': camera_id,
}
if lng > 0 and lat > 0:
r = requests.post(url, data=data, headers=headers)
res = json.loads(r.text)
if res['server_status'] == 200:
print('{}: success!'.format(camera_id))
else:
print(camera_id, res)
except ValueError as e:
print("*"*10, e, row)
|