-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_poi.py
47 lines (37 loc) · 1.11 KB
/
get_poi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import re
from time import sleep
import requests
from config import AK
# from box import SBox
PATTERN = re.compile(r'(\{.*\})', re.DOTALL)
ALL = dict()
with open('data.json', encoding='utf-8') as jsondata:
ALL = json.load(jsondata)
for university, data in ALL.items():
if data['BResult'] and data['BResult']['status'] == 0:
continue
param = {
'query': university,
'tag': '高等院校',
'region': '全国',
'output': 'json',
'page_size': 1,
'ak': AK
}
r = requests.get(f'http://api.map.baidu.com/place/v2/search', params=param)
print(university)
print(r.text)
BResult = json.loads(PATTERN.findall(r.text)[0])
if BResult['status'] == 0:
results = BResult['results']
if not results:
BResult['status'] = 1
else:
BResult['results'] = BResult['results'][0]
data['BResult'] = BResult
sleep(0.5)
with open('data.json', 'w', encoding='utf-8') as jsonout:
json.dump(ALL, jsonout, ensure_ascii=False, indent=2, sort_keys=True)