-
Notifications
You must be signed in to change notification settings - Fork 1
/
niu.py
36 lines (27 loc) · 1.29 KB
/
niu.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import urllib.request
import json
strSerialNumber = "" # Check it in the app
strAppToken = "" # Dump the app request with Mitm
objNiuReq = urllib.request.Request("https://app-api.niu.com/v3/motor_data/index_info?sn=" + strSerialNumber)
objNiuReq.add_header("token", strAppToken)
with urllib.request.urlopen(objNiuReq) as objNiuResponse:
objNiuAPIResult = objNiuResponse.read()
objNiuData = json.loads(objNiuAPIResult)
intNiuBatteryLevel = objNiuData["data"]["batteries"]["compartmentA"]["batteryCharging"]
intNiuEstMileage = objNiuData["data"]["estimatedMileage"]
strNiuLocLat = objNiuData["data"]["postion"]["lat"]
strNiuLocLng = objNiuData["data"]["postion"]["lng"]
blnNiuCharging = objNiuData["data"]["isCharging"]
strNiuChargingStatus = ""
if blnNiuCharging == 0 :
strNiuChargingStatus = "(Not Charging)"
elif blnNiuCharging == 1 :
strNiuChargingStatus = "(Charging)"
strNiuLocLat = int(strNiuLocLat*100000)/100000
strNiuLocLng = int(strNiuLocLng*100000)/100000
strNiuGoogleMapsLink = "https://www.google.com/maps/search/" + str(strNiuLocLat) + ",+" + str(strNiuLocLng)
print ("Battery Level:", intNiuBatteryLevel, "%", strNiuChargingStatus)
print ("Estimated Mileage:", intNiuEstMileage, "KM")
print ("Location:", strNiuGoogleMapsLink)