Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #
- import json
- import sqlite3
- import requests
- import sqlite3
- config = {}
- con = sqlite3.connect("/home/azureuser/clever/clever.db")
- cur = con.cursor()
- # Read config from DB
- r = cur.execute("SELECT * from Config")
- for x, y in r.fetchall():
- config[x] = y
- url = (
- "https://mobileapp-backend.clever.dk/api//v4/transactions/"
- + config["dayCode"]
- + "/"
- + config["chargeBoxId"]
- + "/connector/"
- + config["connectorId"]
- + "?chargepointId="
- + config["chargeBoxId"]
- + "&connector="
- + config["connectorId"]
- )
- headers = {
- "content-type": "application/json",
- "accept": "*/*",
- "authorization": "Basic bW9iaWxlYXBwOmFwaWtleQ==",
- "app-version": "2.8.0",
- "app-os": "15.7",
- "app-platform": "iOS",
- "app-device": "iPhone9,3",
- "accept-encoding": "gzip, deflate, br",
- "accept-language": "da-DK,da;q=0.9",
- }
- r = requests.get(url, headers=headers)
- # print(r.json())
- # print("status='" + r.json()["data"]["status"] + "'")
- # print("timestamp='" + r.json()["data"]["timestamp"] + "'")
- # print("transactionId='" + str(r.json()["data"]["transactionId"]) + "'")
- # print("consumedWh='" + str(r.json()["data"]["consumedWh"]) + "'")
- # print("started='" + r.json()["data"]["started"] + "'")
- # print("cardNumber='" + r.json()["data"]["cardNumber"] + "'")
- # print("latestConsumptionWh='" + str(r.json()["data"]["latestConsumptionWh"]) + "'")
- # Silent exit when no data
- try:
- if r.json()['status'] != True:
- exit()
- except:
- exit()
- # try:
- sql = (
- "insert into CleverCharging VALUES('"
- + r.json()["data"]["status"]
- + "','"
- + r.json()["data"]["timestamp"]
- +"',"
- + str(r.json()["data"]["transactionId"])
- + ","
- + str(r.json()["data"]["consumedWh"])
- + ",'"
- + r.json()["data"]["started"]
- + "','"
- + r.json()["data"]["cardNumber"]
- + "',"
- + str(r.json()["data"]["latestConsumptionWh"])
- + ");",
- )
- # print(sql[0])
- try:
- cur.execute(sql[0])
- except:
- pass
- con.commit()
- con.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement