Skip to content

Instantly share code, notes, and snippets.

@dangsonbk
Last active November 4, 2020 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dangsonbk/70d572bebc0db73c3ee76db65dcc1fde to your computer and use it in GitHub Desktop.
Save dangsonbk/70d572bebc0db73c3ee76db65dcc1fde to your computer and use it in GitHub Desktop.
Get household daily power consumption from EVN
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
from datetime import datetime
from datetime import timedelta
import json
account = {
'UserName': (None, "USER"),
'Password': (None, "PASSWORD"),
}
time_day = datetime.now()
start_time = time_day - timedelta(days=70)
start_time = datetime.combine(start_time, datetime.min.time())
daily = {
"diemDo": (None, "USER001"),
"tuNgay": (None, start_time.strftime("%d/%m/%Y")),
"denNgay": (None, time_day.strftime("%d/%m/%Y")),
}
sess = requests.Session()
response = sess.post('http://cskh.evnhanoi.com.vn/Account/Login?ma_loai_ycau=-1', files=account)
print('Calling API: ' + 'http://cskh.evnhanoi.com.vn/BaoCaoChiSo/GetDataChiSoNgay')
print("Time from {} to {}".format(start_time.strftime("%d/%m/%Y"), time_day.strftime("%d/%m/%Y")))
response = sess.post('http://cskh.evnhanoi.com.vn/BaoCaoChiSo/GetDataChiSoNgay', files=daily)
daily_response = response.json()
last_chi_so = 0
previous_chi_so = 0
ngay = []
chi_so = []
for daily in json.loads(daily_response)[1:]:
if "NGAY" in daily:
last_chi_so = int(daily["CHI_SO"])
last_ngay = daily["NGAY"].replace("12:00:00", "".join([daily["GIO"].zfill(2), ":", daily["PHUT"].zfill(2), ":00"]))
delta_chi_so = last_chi_so - previous_chi_so
previous_chi_so = last_chi_so
print(",".join([last_ngay, str(last_chi_so), str(delta_chi_so)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment