forked from guiguiabloc/api-domogeek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassEJP.py
117 lines (111 loc) · 2.45 KB
/
ClassEJP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Gruik coded by GuiguiAbloc
# http://blog.guiguiabloc.fr
# http://api.domogeek.fr
#
import urllib2
import sys
import json
url="https://particulier.edf.fr/bin/edf_rc/servlets/ejptempo?searchType=ejp"
class EDFejp:
def EJPToday(self,request):
print "RECU REQUETE: " +request
try:
html = urllib2.urlopen(url)
except:
return None
try:
rep = json.load(html)
except:
return None
data = rep["data"]
try:
d = json.loads(data)
except:
return None
info_ejp=d['dtos']
result = None
lst = []
for i in info_ejp:
d=i['dates'][0]
v=i['values'][0]
r=i['region']
liste = {}
liste[r]=v
lst.append(liste)
resultat = json.dumps(lst)
NORD = lst[0]['EJP_NORD']
OUEST = lst[1]['EJP_OUEST']
PACA = lst[2]['EJP_PACA']
SUD = lst[3]['EJP_SUD']
print NORD, OUEST, PACA, SUD
if request == "nord":
result= NORD
if request == "sud":
result = SUD
if request == "ouest":
result = OUEST
if request == "paca":
result = PACA
print result
if "OUI" in str(result):
return "True"
elif "NON" in str(result):
return "False"
elif "ND" in str(result):
return "ND"
else:
return "no data"
def EJPTomorrow(self,request):
print "RECU REQUETE: " +request
try:
html = urllib2.urlopen(url)
except:
return None
try:
rep = json.load(html)
except:
return None
data = rep["data"]
try:
d = json.loads(data)
except:
return None
info_ejp=d['dtos']
result = None
lst = []
for i in info_ejp:
try:
d_tomorrow=i['dates'][1]
v_tomorrow=i['values'][1]
r=i['region']
liste = {}
liste[r]=v
lst.append(liste)
resultat = json.dumps(lst)
except:
return "no value"
NORD = lst[0]['EJP_NORD']
OUEST = lst[1]['EJP_OUEST']
PACA = lst[2]['EJP_PACA']
SUD = lst[3]['EJP_SUD']
print NORD, OUEST, PACA, SUD
if request == "nord":
result= NORD
if request == "sud":
result = SUD
if request == "ouest":
result = OUEST
if request == "paca":
result = PACA
print result
if "OUI" in str(result):
return "True"
elif "NON" in str(result):
return "False"
elif "ND" in str(result):
return "ND"
else:
return "no data"