Compare commits
3 Commits
09bd724058
...
1.6
| Author | SHA1 | Date | |
|---|---|---|---|
| 771fe374fa | |||
| 4fe61ebfbc | |||
| 8a4db22a4c |
34
homesfr.py
34
homesfr.py
@@ -9,12 +9,13 @@ from http.cookiejar import CookieJar
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
from time import time
|
from time import time
|
||||||
|
from json import loads as json_read
|
||||||
|
|
||||||
authors = (
|
authors = (
|
||||||
'Gilles "Almtesh" Émilien MOREL',
|
'Sasha "Almtesh" Évan MOREL',
|
||||||
)
|
)
|
||||||
name = 'homesfr pour Python 3'
|
name = 'homesfr pour Python 3'
|
||||||
version = '1.4'
|
version = '1.6'
|
||||||
|
|
||||||
# Modes utilisables
|
# Modes utilisables
|
||||||
MODE_OFF = 0
|
MODE_OFF = 0
|
||||||
@@ -37,11 +38,15 @@ base_url = 'https://home.sfr.fr'
|
|||||||
# Authentification
|
# Authentification
|
||||||
auth_path = '/mysensors'
|
auth_path = '/mysensors'
|
||||||
auth_ok_url = 'https://home.sfr.fr/logged'
|
auth_ok_url = 'https://home.sfr.fr/logged'
|
||||||
auth_post_url = 'https://boutique.home.sfr.fr/authentification'
|
auth_post_url = 'https://home.sfr.fr/login'
|
||||||
auth_referer = 'https://boutique.home.sfr.fr/authentification?back=service'
|
auth_referer = 'https://home.sfr.fr/login'
|
||||||
auth_user_field = 'email'
|
auth_user_field = 'email'
|
||||||
auth_pass_field = 'passwd'
|
auth_pass_field = 'passwd'
|
||||||
auth_extra_fields = {'back': 'service', 'token_sso': '', 'error_sso': '', 'SubmitLogin': 'OK'}
|
auth_extra_fields = {'back': 'service', 'error_sso': '', 'SubmitLogin': 'OK'}
|
||||||
|
auth_sso_post_url = 'https://home.sfr.fr/sso-connector.php'
|
||||||
|
auth_sso_user_field = 'connectionSFR'
|
||||||
|
auth_sso_pass_field = 'passSFR'
|
||||||
|
auth_sso_get_field = 'token_sso'
|
||||||
auth_logout_path = '/deconnexion'
|
auth_logout_path = '/deconnexion'
|
||||||
|
|
||||||
# Chemin pour la liste des capteurs
|
# Chemin pour la liste des capteurs
|
||||||
@@ -272,6 +277,7 @@ class HomeSFR ():
|
|||||||
print ('initalisé avec l\'identifiant ' + username)
|
print ('initalisé avec l\'identifiant ' + username)
|
||||||
if cookies is not None:
|
if cookies is not None:
|
||||||
print ('initialisé avec des cookies')
|
print ('initialisé avec des cookies')
|
||||||
|
print ('Cookies ' + str (len (cookies)))
|
||||||
print ('debug = ' + str (debug))
|
print ('debug = ' + str (debug))
|
||||||
print ('autologin = ' + str (autologin))
|
print ('autologin = ' + str (autologin))
|
||||||
|
|
||||||
@@ -285,10 +291,8 @@ class HomeSFR ():
|
|||||||
self.autologin = False
|
self.autologin = False
|
||||||
if cookies is None:
|
if cookies is None:
|
||||||
self.cookies = CookieJar ()
|
self.cookies = CookieJar ()
|
||||||
elif type (cookies) == CookieJar:
|
|
||||||
self.cookies = cookies
|
|
||||||
else:
|
else:
|
||||||
raise TypeError ('Les cookies doivent être de type CookieJar !')
|
self.cookies = cookies
|
||||||
self.opener = request.build_opener (request.HTTPCookieProcessor (self.cookies))
|
self.opener = request.build_opener (request.HTTPCookieProcessor (self.cookies))
|
||||||
self.mysensors = self.MySensors (self)
|
self.mysensors = self.MySensors (self)
|
||||||
|
|
||||||
@@ -325,7 +329,19 @@ class HomeSFR ():
|
|||||||
'''
|
'''
|
||||||
if self.username is not None and self.password is not None:
|
if self.username is not None and self.password is not None:
|
||||||
self.opener.open (auth_referer)
|
self.opener.open (auth_referer)
|
||||||
data = auth_extra_fields
|
# SSO
|
||||||
|
data = {}
|
||||||
|
data [auth_sso_user_field] = self.username
|
||||||
|
data [auth_sso_pass_field] = self.password
|
||||||
|
data = bytes (urlencode (data), 'UTF8')
|
||||||
|
if self.DEBUG:
|
||||||
|
print ('Cookies ' + str (len (self.cookies)))
|
||||||
|
print ('Envoi de ' + str (data))
|
||||||
|
a = self.opener.open (auth_sso_post_url, data = data)
|
||||||
|
sso = json_read (a.read ().decode ('UTF8')) ['result']
|
||||||
|
# Authenfication
|
||||||
|
data = dict (auth_extra_fields)
|
||||||
|
data [auth_sso_get_field] = sso [auth_sso_get_field]
|
||||||
data [auth_user_field] = self.username
|
data [auth_user_field] = self.username
|
||||||
data [auth_pass_field] = self.password
|
data [auth_pass_field] = self.password
|
||||||
data = bytes (urlencode (data), 'UTF8')
|
data = bytes (urlencode (data), 'UTF8')
|
||||||
|
|||||||
Reference in New Issue
Block a user