1
+ import webbrowser
2
+ from collections import Counter
1
3
from urllib .request import urlopen , quote
2
4
import json
3
5
import requests
4
6
import itchat
5
7
from itchat .content import *
6
8
7
9
def getlnglat (address ):
10
+ '''
11
+ 返回字典形式的城市经纬度和其他信息数据
12
+ '''
8
13
address = quote (address )
9
14
url = 'http://api.map.baidu.com/geocoder/v2/'
10
15
output = 'json'
11
16
ak = 'Uba11lIVgQGGj2xPZPif4mfRtNXjVhSo'
12
17
uri = url + '?output=' + output + '&address=' + address + '&ak=' + ak
13
- # try:
14
18
temp = urlopen (uri )
15
19
temp = json .loads (temp .read ().decode ())
16
- # except:
17
- # temp = None
18
- # finally:
19
20
return temp
20
21
21
22
@itchat .msg_register (itchat .content .TEXT )
@@ -25,13 +26,28 @@ def address_reply(msg):
25
26
address = itchat .get_friends (update = False )
26
27
print (type (address ))
27
28
address_list = ''
29
+ address_json = dict ()
30
+ address_city_list = []
28
31
for i in address :
29
32
nickname = i ["NickName" ]
30
33
city = i ["City" ]
31
34
province = i ["Province" ]
32
35
address_i = nickname + ':' + province + ' ' + city
33
36
address_list += address_i + '\n '
34
- print (getlnglat (city ))
37
+ city_json = getlnglat (city ) #type: <class 'dict'>
38
+ if city_json ['status' ] == 0 :
39
+ address_city_list .append (city )
40
+ print (city_json )
41
+ address_json [city ] = city_json
42
+ elif city_json ['status' ] != 0 :
43
+ province_json = getlnglat (province ) #type: <class 'dict'>
44
+ if province_json ['status' ] == 0 :
45
+ address_city_list .append (province )
46
+ print (province_json )
47
+ address_json [province ] = province_json
48
+
49
+ webbrowser .open ('/home/tiger/Workspace/itChatAttendanceCheck/addressMap/index.html' )
50
+ print (address_json )
35
51
itchat .send (address_list , source )
36
52
37
53
itchat .auto_login (hotReload = True )
0 commit comments