【NET API + Python3】 add postion

Upload to NET terminal positons

Run.
> python3 this_script.py

 

# -*- coding: utf-8 -*-
import urllib.request

apk_key = 'your api key'
tid = 'terminal name'
datas = [
{"lat": 35.5xxxxxx , "lng": 139.3xxxxx, "date:": "xxxx-xx-xx xx:xx:xx" },
{"lat": 35.5xxxxxx , "lng": 139.3xxxxx, "date:": "xxxx-xx-xx xx:xx:xx" },
{"lat": 35.5xxxxxx , "lng": 139.3xxxxx, "date:": "xxxx-xx-xx xx:xx:xx" },
{"lat": 35.5xxxxxx , "lng": 139.3xxxxx, "date:": "xxxx-xx-xx xx:xx:xx" },
]

for dt in datas:

add_position = "http://api.sensor-network.jp:8181/api/position/add/"
post_data = {
'api_key': apk_key,
'tid': tid,
'lat': dt["lat"],
'lng': dt["lng"]
'date': dt["date"]
}
post_data = urllib.parse.urlencode(post_data).encode(encoding='utf-8')

request = urllib.request.Request(add_position)
request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
response = urllib.request.urlopen(request, post_data)
result = response.read()
print(result)

 

Leave a Reply