-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebapi_sample.py
More file actions
40 lines (33 loc) · 1.01 KB
/
webapi_sample.py
File metadata and controls
40 lines (33 loc) · 1.01 KB
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
import requests
import xml.etree.ElementTree as ET
import goplt
def get_address(zipcode):
url = "http://zip.cgis.biz/xml/zip.php"
payload = {"zn": str(zipcode)}
r = requests.get(url, params=payload)
root=ET.fromstring(r.text)
state=''
city=''
address=''
for value in root.iter('value'):
for item in value.attrib:
if(item=='state'):
state= value.attrib[item]
elif(item=='city'):
city= value.attrib[item]
elif(item=='address'):
address= value.attrib[item]
if(state==''):
state='存在しません'
return state,city,address
def main():
gop=goplt.Goplt('/dev/ttyACM0')
while True:
s=gop.Enq()
if(s=='ZIP'):
zipcode=gop.ReadMem('zipcode',1)
state,city,address=get_address(zipcode)
gop.WriteTMem('state',state)
gop.WriteTMem('city',city)
gop.WriteTMem('address',address)
main()