Skip to content

Instantly share code, notes, and snippets.

@johnlpage
Created March 17, 2022 09:26
Show Gist options
  • Save johnlpage/406991286bf41f0e69d48955a75a3653 to your computer and use it in GitHub Desktop.
Save johnlpage/406991286bf41f0e69d48955a75a3653 to your computer and use it in GitHub Desktop.
import requests
from pprint import pprint
import json
import pymongo
with open("/home/pi/.mongo_uri.txt") as f:
uri = f.readline().strip()
mongoclient = pymongo.MongoClient(uri)
with open("/home/pi/.ginlongpass") as f:
password = f.readline().strip()
loginurl = "https://m.ginlong.com/cpro/login/validateLogin.json"
logindata = {
"userName": "johnlpage@gmail.com",
"userNameDisplay": "johnlpage@gmail.com",
"password": password,
"lan": 2,
"domain": "m.ginlong.com",
"userType": "C",
}
s = requests.session()
login_response = s.post(loginurl, data=logindata)
dataurl = "https://m.ginlong.com/cpro/device/inverter/goDetailAjax.json"
payload = {"deviceId": 101279970}
r = s.post(dataurl, data=payload)
data = json.loads(r.text)
# Add Solar watts at the time to latest electric reading
try:
solarwatts = int(float(data["result"]["deviceWapper"]["dataJSON"]["1ao"]))
print(solarwatts)
collection = mongoclient.energy.meter
query = {"type": "electric"}
sort = [("date", -1)]
update = {"$set": {"solarwatts": solarwatts}}
collection.find_one_and_update(query, update, sort=sort)
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment