From c1204057dcdb55640944ff0a7c9912f1fb0ca431 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Tue, 22 Jun 2010 10:47:12 +0200 Subject: [PATCH] handle 'oops' error message --- weboob/backends/aum/browser.py | 16 +++++++----- weboob/backends/aum/pages/base.py | 42 ++++++++++++++++++------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/weboob/backends/aum/browser.py b/weboob/backends/aum/browser.py index 6b87aa8c..55ea45fc 100644 --- a/weboob/backends/aum/browser.py +++ b/weboob/backends/aum/browser.py @@ -1,16 +1,16 @@ # -*- coding: utf-8 -*- # Copyright(C) 2008-2010 Romain Bignon, Christophe Benz -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 3 of the License. -# +# # This program 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 General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -26,7 +26,7 @@ except ImportError: import simplejson import urllib -from weboob.tools.browser import BaseBrowser +from weboob.tools.browser import BaseBrowser, BrowserUnavailable from weboob.tools.parsers.html5libparser import Html5libParser from weboob.backends.aum.exceptions import AdopteWait @@ -275,7 +275,11 @@ class AdopteUnMec(BaseBrowser): return r def _get_chat_infos(self): - json = simplejson.load(self.openurl('http://www.adopteunmec.com/1.1_cht_get.php?anticache=%f' % random.random())) + try: + json = simplejson.load(self.openurl('http://www.adopteunmec.com/1.1_cht_get.php?anticache=%f' % random.random())) + except simplejson.JSONDecodeError: + raise BrowserUnavailable() + if json['error']: raise ChatException(u'Error while getting chat infos. json:\n%s' % json) return json @@ -317,7 +321,7 @@ class AdopteUnMec(BaseBrowser): request = self.request_class(url, urllib.urlencode(data), headers) response = self.openurl(request).read() try: - datetime.datetime.strptime(response, '%Y-%m-%d %H:%M:%S') + datetime.datetime.strptime(response, '%Y-%m-%d %H:%M:%S') return True except ValueError: return False diff --git a/weboob/backends/aum/pages/base.py b/weboob/backends/aum/pages/base.py index 885abe54..7ad55fa8 100644 --- a/weboob/backends/aum/pages/base.py +++ b/weboob/backends/aum/pages/base.py @@ -1,28 +1,34 @@ # -*- coding: utf-8 -*- -""" -Copyright(C) 2008-2010 Romain Bignon - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -""" +# Copyright(C) 2008-2010 Romain Bignon +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import re from logging import error, warning -from weboob.tools.browser import BasePage +from weboob.tools.browser import BasePage, BrowserUnavailable 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() + def open_contact_list_page(self): self.browser.follow_link(url_regex=r"/mails.php$")