Skip to content

Commit

Permalink
Change API v3 -> v4
Browse files Browse the repository at this point in the history
Add daily consumption request
  • Loading branch information
Richard DUMAIS committed Sep 18, 2021
1 parent e710262 commit e74a16b
Showing 1 changed file with 51 additions and 18 deletions.
69 changes: 51 additions & 18 deletions examples/dataconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
import json
import re
import sys
if ((3, 0) <= sys.version_info <= (3, 9)):
import urllib.parse as urlparse
elif ((2, 0) <= sys.version_info <= (2, 9)):
import urlparse
import os
from urllib import parse as urlparse




client_id = 'changeme'
client_secret = 'changeme'
redirect_uri = 'changeme'
# Before launch this script you must export your credentials
print(f"{os.environ['client_id']}\n{os.environ['redirect_uri']}")
client_id = os.environ['client_id']
client_secret = os.environ['client_secret']
redirect_uri = os.environ['redirect_uri']


authorize_url = "https://gw.hml.api.enedis.fr/group/espace-particuliers/consentement-linky/oauth2/authorize"
Expand Down Expand Up @@ -118,10 +116,9 @@ def pretty_print_request(req):
print("################################################################################")
print("# Request data : consumption max power #########################################")
print("################################################################################")
start_date = '2019-04-23'
end_date = '2019-04-24'
metering_data_api_path = '/v3/metering_data/consumption_max_power'
#metering_data_api_path = '/v3/metering_data/consumption_max_power'
start_date = '2021-09-14'
end_date = '2021-09-15'
metering_data_api_path = f'/v4/metering_data/daily_consumption_max_power'
request_url = metering_data_base_url + metering_data_api_path
token_type = endpoint_token_returned_json['token_type']
token = endpoint_token_returned_json['access_token']
Expand Down Expand Up @@ -156,10 +153,46 @@ def pretty_print_request(req):
print("################################################################################")
print("# Request data : consumption load curve ########################################")
print("################################################################################")
start_date = '2019-04-23'
end_date = '2019-04-24'
metering_data_api_path = '/v3/metering_data/consumption_load_curve'
#metering_data_api_path = '/v3/metering_data/consumption_max_power'
start_date = '2021-09-14'
end_date = '2021-09-15'
metering_data_api_path = '/v4/metering_data/consumption_load_curve'
request_url = metering_data_base_url + metering_data_api_path
token_type = endpoint_token_returned_json['token_type']
token = endpoint_token_returned_json['access_token']

req_head = {
'Accept': 'application/json',
'Authorization': token_type + ' ' + token
}

req_params = {
'start': start_date,
'end': end_date,
'usage_point_id':callback_usage_point_id
}

# Forge and print request
http_request = requests.Request("GET", request_url, headers=req_head, params=req_params)
http_request_prepared = http_request.prepare()
pretty_print_request(http_request_prepared)

# Send request
http_session = requests.Session()
http_return = http_session.send(http_request_prepared)

# Print request result
print(http_return.status_code)
print(http_return.text)
#print(http_return.json)



print("################################################################################")
print("# Request data : daily consumption ########################################")
print("################################################################################")
start_date = '2021-09-14'
end_date = '2021-09-15'
metering_data_api_path = f'/v4/metering_data/daily_consumption'
request_url = metering_data_base_url + metering_data_api_path
token_type = endpoint_token_returned_json['token_type']
token = endpoint_token_returned_json['access_token']
Expand Down Expand Up @@ -187,4 +220,4 @@ def pretty_print_request(req):
# Print request result
print(http_return.status_code)
print(http_return.text)
#print(http_return.json)
#print(http_return.json)

0 comments on commit e74a16b

Please sign in to comment.