Pep8 cleanup on freemobile module
This commit is contained in:
parent
1ae1f23c85
commit
dfb66a4fbd
5 changed files with 35 additions and 35 deletions
|
|
@ -36,8 +36,12 @@ class FreeMobileBackend(BaseBackend, ICapBill):
|
||||||
VERSION = '0.b'
|
VERSION = '0.b'
|
||||||
LICENSE = 'AGPLv3+'
|
LICENSE = 'AGPLv3+'
|
||||||
DESCRIPTION = 'Free Mobile website'
|
DESCRIPTION = 'Free Mobile website'
|
||||||
CONFIG = BackendConfig(ValueBackendPassword('login', label='Account ID', masked=False, regexp='^(\d{8}|)$'),
|
CONFIG = BackendConfig(ValueBackendPassword('login',
|
||||||
ValueBackendPassword('password', label='Password')
|
label='Account ID',
|
||||||
|
masked=False,
|
||||||
|
regexp='^(\d{8}|)$'),
|
||||||
|
ValueBackendPassword('password',
|
||||||
|
label='Password')
|
||||||
)
|
)
|
||||||
BROWSER = Freemobile
|
BROWSER = Freemobile
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,10 @@ __all__ = ['Freemobile']
|
||||||
class Freemobile(BaseBrowser):
|
class Freemobile(BaseBrowser):
|
||||||
DOMAIN = 'mobile.free.fr'
|
DOMAIN = 'mobile.free.fr'
|
||||||
PROTOCOL = 'https'
|
PROTOCOL = 'https'
|
||||||
ENCODING = None # refer to the HTML encoding
|
ENCODING = None # refer to the HTML encoding
|
||||||
PAGES = {'.*moncompte/index.php': LoginPage,
|
PAGES = {'.*moncompte/index.php': LoginPage,
|
||||||
'.*page=home': HomePage,
|
'.*page=home': HomePage,
|
||||||
'.*page=suiviconso': HistoryPage
|
'.*page=suiviconso': HistoryPage
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
@ -50,7 +50,7 @@ class Freemobile(BaseBrowser):
|
||||||
if not self.is_on_page(LoginPage):
|
if not self.is_on_page(LoginPage):
|
||||||
self.location('https://mobile.free.fr/moncompte/index.php')
|
self.location('https://mobile.free.fr/moncompte/index.php')
|
||||||
|
|
||||||
self.page.login(self.username, self.password)
|
self.page.login(self.username, self.password)
|
||||||
|
|
||||||
if self.is_on_page(LoginPage):
|
if self.is_on_page(LoginPage):
|
||||||
raise BrowserIncorrectPassword()
|
raise BrowserIncorrectPassword()
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ from weboob.capabilities.bill import Detail
|
||||||
|
|
||||||
__all__ = ['HistoryPage']
|
__all__ = ['HistoryPage']
|
||||||
|
|
||||||
|
|
||||||
def convert_price(div):
|
def convert_price(div):
|
||||||
try:
|
try:
|
||||||
price = div.find('div[@class="horsForfait"]/p/span').text
|
price = div.find('div[@class="horsForfait"]/p/span').text
|
||||||
|
|
@ -42,20 +43,19 @@ class HistoryPage(BasePage):
|
||||||
divs = divnat.xpath('div[@class="detail"]')
|
divs = divnat.xpath('div[@class="detail"]')
|
||||||
divvoice = divs.pop(0)
|
divvoice = divs.pop(0)
|
||||||
|
|
||||||
# Two informations in one div...
|
# Two informations in one div...
|
||||||
voice = Detail()
|
voice = Detail()
|
||||||
voice.label = divvoice.find('div[@class="titreDetail"]/p').text_content()
|
voice.label = divvoice.find('div[@class="titreDetail"]/p').text_content()
|
||||||
voice.price = convert_price(divvoice)
|
voice.price = convert_price(divvoice)
|
||||||
voicenat = divvoice.xpath('div[@class="consoDetail"]/p/span')[0].text
|
voicenat = divvoice.xpath('div[@class="consoDetail"]/p/span')[0].text
|
||||||
voiceint = divvoice.xpath('div[@class="consoDetail"]/p/span')[1].text
|
voiceint = divvoice.xpath('div[@class="consoDetail"]/p/span')[1].text
|
||||||
voice.infos = "Consommation : " + voicenat + " International : " + voiceint
|
voice.infos = "Consommation : " + voicenat + " International : " + voiceint
|
||||||
self.details.append(voice)
|
self.details.append(voice)
|
||||||
|
|
||||||
self.iter_divs(divs)
|
self.iter_divs(divs)
|
||||||
divint = self.document.xpath('//div[@class="international hide"]')[0]
|
divint = self.document.xpath('//div[@class="international hide"]')[0]
|
||||||
self.iter_divs(divint.xpath('div[@class="detail"]'), True)
|
self.iter_divs(divint.xpath('div[@class="detail"]'), True)
|
||||||
|
|
||||||
|
|
||||||
def iter_divs(self, divs, inter=False):
|
def iter_divs(self, divs, inter=False):
|
||||||
for div in divs:
|
for div in divs:
|
||||||
detail = Detail()
|
detail = Detail()
|
||||||
|
|
@ -68,8 +68,6 @@ class HistoryPage(BasePage):
|
||||||
|
|
||||||
self.details.append(detail)
|
self.details.append(detail)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_calls(self):
|
def get_calls(self):
|
||||||
return self.calls
|
return self.calls
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,4 +44,4 @@ class HomePage(BasePage):
|
||||||
|
|
||||||
l.append(subscription)
|
l.append(subscription)
|
||||||
|
|
||||||
return l
|
return l
|
||||||
|
|
|
||||||
|
|
@ -25,23 +25,24 @@ from weboob.tools.browser import BasePage
|
||||||
|
|
||||||
__all__ = ['LoginPage']
|
__all__ = ['LoginPage']
|
||||||
|
|
||||||
|
|
||||||
class FreeKeyboard(object):
|
class FreeKeyboard(object):
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
symbols={'0':'001111111111110011111111111111111111111111111110000000000011110000000000011111111111111111011111111111111001111111111110',
|
symbols = {'0': '001111111111110011111111111111111111111111111110000000000011110000000000011111111111111111011111111111111001111111111110',
|
||||||
'1':'001110000000000001110000000000001110000000000011111111111111111111111111111111111111111111000000000000000000000000000000',
|
'1': '001110000000000001110000000000001110000000000011111111111111111111111111111111111111111111000000000000000000000000000000',
|
||||||
'2':'011110000001111011110000111111111000001111111110000011110011110000111100011111111111000011011111110000011001111000000011',
|
'2': '011110000001111011110000111111111000001111111110000011110011110000111100011111111111000011011111110000011001111000000011',
|
||||||
'3':'011100000011110111100000011111111000110000111110000110000011110001110000011111111111111111011111111111110001110001111100',
|
'3': '011100000011110111100000011111111000110000111110000110000011110001110000011111111111111111011111111111110001110001111100',
|
||||||
'4':'000000011111000000001111111000000111110011000011110000011000111111111111111111111111111111111111111111111000000000011000',
|
'4': '000000011111000000001111111000000111110011000011110000011000111111111111111111111111111111111111111111111000000000011000',
|
||||||
'5':'111111110011110111111110011111111001110000111111001100000011111001100000011111001111111111111001111111111010000111111110',
|
'5': '111111110011110111111110011111111001110000111111001100000011111001100000011111001111111111111001111111111010000111111110',
|
||||||
'6':'001111111111110011111111111111111111111111111110001100000011110001100000011111001111111111111101111111111011100111111110',
|
'6': '001111111111110011111111111111111111111111111110001100000011110001100000011111001111111111111101111111111011100111111110',
|
||||||
'7':'111000000000000111000000000000111000000011111111000011111111111011111111111111111111000000111111000000000111100000000000',
|
'7': '111000000000000111000000000000111000000011111111000011111111111011111111111111111111000000111111000000000111100000000000',
|
||||||
'8':'001110001111110011111111111111111111111111111110000110000011110000110000011111111111111111011111111111111001111001111110',
|
'8': '001110001111110011111111111111111111111111111110000110000011110000110000011111111111111111011111111111111001111001111110',
|
||||||
'9':'001111111000110011111111100111111111111100111110000001100011110000001100011111111111111111011111111111111001111111111110'
|
'9': '001111111000110011111111100111111111111100111110000001100011110000001100011111111111111111011111111111111001111111111110'
|
||||||
}
|
}
|
||||||
fingerprints = []
|
fingerprints = []
|
||||||
basepage = None
|
basepage = None
|
||||||
|
|
||||||
def __init__(self,basepage):
|
def __init__(self, basepage):
|
||||||
for htmlimg in basepage.document.xpath('//img[@class="ident_chiffre_img pointer"]'):
|
for htmlimg in basepage.document.xpath('//img[@class="ident_chiffre_img pointer"]'):
|
||||||
url = htmlimg.attrib.get("src")
|
url = htmlimg.attrib.get("src")
|
||||||
fichier = basepage.browser.openurl(url)
|
fichier = basepage.browser.openurl(url)
|
||||||
|
|
@ -51,9 +52,9 @@ class FreeKeyboard(object):
|
||||||
# The digit is only displayed in the center of image
|
# The digit is only displayed in the center of image
|
||||||
for x in range(15, 23):
|
for x in range(15, 23):
|
||||||
for y in range(12, 27):
|
for y in range(12, 27):
|
||||||
(r, g, b) = matrix[x,y]
|
(r, g, b) = matrix[x, y]
|
||||||
# If the pixel is "red" enough
|
# If the pixel is "red" enough
|
||||||
if g + b < 450:
|
if g + b < 450:
|
||||||
s += "1"
|
s += "1"
|
||||||
else:
|
else:
|
||||||
s += "0"
|
s += "0"
|
||||||
|
|
@ -63,12 +64,11 @@ class FreeKeyboard(object):
|
||||||
if self.DEBUG:
|
if self.DEBUG:
|
||||||
image.save('/tmp/' + s + '.png')
|
image.save('/tmp/' + s + '.png')
|
||||||
|
|
||||||
|
def get_symbol_code(self, digit):
|
||||||
def get_symbol_code(self,digit):
|
|
||||||
fingerprint = self.symbols[digit]
|
fingerprint = self.symbols[digit]
|
||||||
i = 0
|
i = 0
|
||||||
for string in self.fingerprints:
|
for string in self.fingerprints:
|
||||||
if string.__eq__(fingerprint):
|
if string == fingerprint:
|
||||||
return i
|
return i
|
||||||
i += 1
|
i += 1
|
||||||
# Image contains some noise, and the match is not always perfect
|
# Image contains some noise, and the match is not always perfect
|
||||||
|
|
@ -93,11 +93,11 @@ class FreeKeyboard(object):
|
||||||
|
|
||||||
# TODO : exception
|
# TODO : exception
|
||||||
|
|
||||||
def get_string_code(self,string):
|
def get_string_code(self, string):
|
||||||
code=''
|
code = ''
|
||||||
for c in string:
|
for c in string:
|
||||||
codesymbol = self.get_symbol_code(c)
|
codesymbol = self.get_symbol_code(c)
|
||||||
code+=str(codesymbol)
|
code += str(codesymbol)
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def get_small(self, string):
|
def get_small(self, string):
|
||||||
|
|
@ -122,5 +122,3 @@ class LoginPage(BasePage):
|
||||||
vk.get_small(code)
|
vk.get_small(code)
|
||||||
self.browser['pwd_abo'] = password
|
self.browser['pwd_abo'] = password
|
||||||
self.browser.submit(nologin=True)
|
self.browser.submit(nologin=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue