110 lines
4 KiB
Python
110 lines
4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright(C) 2008-2011 Romain Bignon
|
|
#
|
|
# This file is part of weboob.
|
|
#
|
|
# weboob is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# weboob is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
import re
|
|
from weboob.tools.browser import BasePage, BrowserUnavailable
|
|
from weboob.backends.aum.exceptions import AdopteBanned
|
|
|
|
class PageBase(BasePage):
|
|
def __init__(self, *args, **kwargs):
|
|
BasePage.__init__(self, *args, **kwargs)
|
|
|
|
# Check the 'oops' error message when adopteunmec guys are gay.
|
|
b = self.document.getElementsByTagName('body')[0]
|
|
for div in b.getElementsByTagName('div'):
|
|
if div.getAttribute('id') == 'oops':
|
|
raise BrowserUnavailable('Oops')
|
|
|
|
# Check when the account is temporarily blocked.
|
|
for img in self.document.getElementsByTagName('img'):
|
|
if img.getAttribute('src') == 'http://s.adopteunmec.com/img/exemple.jpg':
|
|
raise AdopteBanned('Your account is blocked. You have to unblock by yourself but we can\'t help you.')
|
|
|
|
def open_contact_list_page(self):
|
|
self.browser.follow_link(url_regex=r"/mail.php$")
|
|
|
|
def open_thread_page(self, id, all_messages=False):
|
|
if all_messages:
|
|
self.browser.location('/thread.php?id=%d&see=all' % int(id))
|
|
else:
|
|
self.browser.location('/thread.php?id=%d' % int(id))
|
|
|
|
def score(self):
|
|
"""
|
|
<table width="220">
|
|
<tr>
|
|
<td align=left class=header>popularité</td>
|
|
<td align=right class=header><big style="color:#ff0198;" id=popScore>7.230</big> pts</td>
|
|
</tr>
|
|
</table>
|
|
"""
|
|
|
|
l = self.document.getElementsByTagName('table')
|
|
for tag in l:
|
|
if tag.getAttribute('width') == '220':
|
|
# <table><tbody(implicit)><tr><td>
|
|
child = tag.childNodes[0].childNodes[0].childNodes[3]
|
|
return int(child.childNodes[0].childNodes[1].data.replace(' ', '').strip())
|
|
|
|
self.logger.error("Error: I can't find the score :(")
|
|
return '0'
|
|
|
|
def __get_indicator(self, elementName):
|
|
""" <span id=mailsCounter><blink>1</blink></span> """
|
|
|
|
l = self.document.getElementsByTagName('span')
|
|
for tag in l:
|
|
if tag.getAttribute('id') == elementName:
|
|
child = tag.childNodes[0]
|
|
|
|
if not hasattr(child, 'data'):
|
|
if child.tagName != u'blink':
|
|
self.logger.warning("Warning: %s counter isn't a blink and hasn't data" % elementName)
|
|
child = child.childNodes[0]
|
|
if not hasattr(child, 'data'):
|
|
break
|
|
|
|
return int(child.data)
|
|
|
|
self.logger.error("Error: I can't find the %s counter :(" % elementName)
|
|
return 0
|
|
|
|
MYNAME_REGEXP = re.compile("Bonjour (.*)")
|
|
def get_my_name(self):
|
|
""" <span class=header2>Bonjour Romain</span> """
|
|
|
|
tags = self.document.getElementsByTagName('span')
|
|
for tag in tags:
|
|
if hasattr(tag.firstChild, 'data'):
|
|
m = self.MYNAME_REGEXP.match(tag.firstChild.data)
|
|
if m:
|
|
return m.group(1)
|
|
|
|
self.logger.warning('Warning: Unable to fetch name')
|
|
return '?'
|
|
|
|
def nb_new_mails(self):
|
|
return self.__get_indicator(u'mailsCounter')
|
|
|
|
def nb_new_baskets(self):
|
|
return self.__get_indicator(u'flashsCounter')
|
|
|
|
def nb_new_visites(self):
|
|
return self.__get_indicator(u'visitesCounter')
|