<commit_before>#!/usr/bin/python3
'''
Home by SFR wrapping class
Plain use of your Home by SFR device from a Python library

Warning:
This is a wrap aroud website, this could stop working without prior notice

Note about version naming:
The version are formed like <major>.<minor>-<date>
Since the major 1, the method's names, paramters and their default value will never change inside the same major.
So, if a program using a major does not work anymore with another version from the same major, it's a bug from the library.

The major 0 is a testing one
'''

authors = (
	'Gilles "Almtesh" <NAME>',
	)
name = 'pyhomesfr'
version = '0.8-20160511'

# Settable modes
MODE_OFF = 0
MODE_CUSTOM = 1
MODE_ON = 2

from urllib import request
from http.cookiejar import CookieJar
from urllib.parse import urlencode
from xml.etree import ElementTree as ET
from urllib.error import HTTPError

def bytes2file (b):
	'''
	Gives a file-like class from a Bytes
	'''
	from io import BytesIO
	r = BytesIO ()
	r.write (b)
	r.seek (0)
	return (r)

class HomeSFR ():
	def __init__ (self, username, password, debug = False, autologin = True):
		'''
		Sets the class with username and password
		The debug parameter defines if the class will write debug messages to stdout, if False, the stdout will never be writen by the class
		The autologin parameter defines if the class will manage the login by itself, if False, the user must call login () to login and test_login () to check the login
		'''
		self.DEBUG = debug
		if self.DEBUG:
			print (name + ' ' + version)
			print ('Authors:')
			for i in authors:
				print (' - ' + i)
			print ('init with username ' + username)
			print ('debug = ' + str (debug))
			print ('autologin = ' + str (autologin))
		
		self.username = username
		self.password = password
		self.autologin = autologin
		self.cookies = CookieJar ()
		self.opener = request.build_opener (request.HTTPCookieProcessor (self.cookies))
		
		# Specific configuration
		self.base_url = 'https://home.sfr.fr'
		
		# path to login test
		self.auth_path = '/mysensors'
		self.auth_ok = '/accueil'	# if logged<commit_msg>Adding TODOS<commit_after>#!/usr/bin/python3
'''
Home by SFR wrapping class
Plain use of your Home by SFR device from a Python library

Warning:
This is a wrap aroud website, this could stop working without prior notice

Note about version naming:
The version are formed like <major>.<minor>-<date>
Since the major 1, the method's names, paramters and their default value will never change inside the same major.
So, if a program using a major does not work anymore with another version from the same major, it's a bug from the library.

The major 0 is a testing one
'''

# TODO:
## Return sensors in a class
## Manage cameras
### Get image
### Get video
## Manage logs
## Import/Export cookies

authors = (
	'Gilles "Almtesh" <NAME>',
	)
name = 'pyhomesfr'
version = '0.8-20160521'

# Settable modes
MODE_OFF = 0
MODE_CUSTOM = 1
MODE_ON = 2

from urllib import request
from http.cookiejar import CookieJar
from urllib.parse import urlencode
from xml.etree import ElementTree as ET
from urllib.error import HTTPError

def bytes2file (b):
	'''
	Gives a file-like class from a Bytes
	'''
	from io import BytesIO
	r = BytesIO ()
	r.write (b)
	r.seek (0)
	return (r)

def bytes2image (b):
	'''
	Gives a Image object from bytes
	Uses the bytes2file function
	'''
	from PIL import Image
	f = bytes2file (b)
	r = Image ()
	r.open (f)
	return (r)

class HomeSFR ():
	def __init__ (self, username, password, debug = False, autologin = True):
		'''
		Sets the class with username and password
		The debug parameter defines if the class will write debug messages to stdout, if False, the stdout will never be writen by the class
		The autologin parameter defines if the class will manage the login by itself, if False, the user must call login () to login and test_login () to check the login
		'''
		self.DEBUG = debug
		if self.DEBUG:
			print (name + ' ' + version)
			print ('Authors:')
			for i in authors:
				print (' - ' + i)
			print ('init with username ' + username)
			print ('debug = ' + str (debug))
			print ('autologin = ' + str (autologin))
		
		self.username = username
		self.password = password
		self.autologin = autologin
		self.cookies = CookieJar ()
		self.opener = request.build_opener (request.HTTPCookieProcessor (self.cookies))
		
		# Specific configuration
		self.base_url = 'https://home.sfr.fr'
		
		# path to login test
		self.auth_path = '/mysensors'
		self.auth_ok = '/accueil'	# if logged
{'fraction_non_alphanumeric': 0.09215469613259669, 'fraction_numerical': 0.00861878453038674, 'mean_word_length': 3.7096774193548385, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7004813', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1420, 'n_words': 594}