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
- from datetime import datetime, timezone
- 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
- print(config)
- url = (
- "https://mobileapp-backend.clever.dk/api/mobile/customer/loginWithSecretCode?secret="
- + config["userSecret"]
- + "&email="
- + config["email"]
- )
- 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())
- dayCode = str(r.json()["data"])
- print("dayCode='" + dayCode + "'")
- config["dayCode"] = dayCode
- url = "https://mobileapp-backend.clever.dk/api//v3/" + dayCode + "/installations?"
- r = requests.get(url, headers=headers)
- print(r.json())
- connectorId = r.json()["data"][0]["connectorId"]
- chargeBoxId = r.json()["data"][0]["chargeBoxId"]
- print("---")
- print("connectorId=" + str(connectorId))
- print("chargeBoxId='" + chargeBoxId + "'")
- config["connectorId"] = str(connectorId)
- config["chargeBoxId"] = chargeBoxId
- print("---")
- # Write config to DB
- print("Writing config...")
- for x in config:
- sql = "UPDATE Config SET value = '" + config[x] + "' WHERE var = '" + x + "';"
- print(" " + sql)
- cur.execute(sql)
- url = (
- "https://mobileapp-backend.clever.dk/api//v2/consumption/"
- + config["dayCode"]
- + "/history?lastUpdatedAt="
- + datetime.now().isoformat()
- + "%2B02:00"
- )
- r = requests.get(url, headers=headers)
- # print(r.json())
- for x in r.json()["data"]["consumptionRecords"]:
- # print(x)
- if x["idTokenSubscriptionLineId"] == None:
- x["idTokenSubscriptionLineId"] = "None"
- sql = (
- "insert into CleverHistory VALUES('"
- + x["chargePointId"]
- + "',"
- + str(x["connectorId"])
- + ","
- + str(x["transactionId"])
- + ",'"
- + x["idTag"]
- + "',"
- + str(x["startTimeLocal"])
- + ","
- + str(x["stopTimeLocal"])
- + ","
- + str(x["startTimeUtc"])
- + ","
- + str(x["stopTimeUtc"])
- + ","
- + str(x["kWh"])
- + ",'"
- + x["idTokenSubscriptionLineId"]
- + "');"
- )
- try:
- cur.execute(sql)
- print("success....: " + sql)
- except:
- print("failed.....: " + sql)
- sql = (
- "UPDATE CleverHistory SET kwh = "
- + str(x["kWh"])
- + " WHERE startTimeUtc = "
- + str(x["startTimeUtc"])
- + ";"
- )
- try:
- cur.execute(sql)
- print("success....: " + sql)
- except:
- print("failed.....: " + sql)
- pass
- con.commit()
- con.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement