new version of genericArticle

This commit is contained in:
juke 2011-02-21 17:30:49 +01:00
commit 800796a2be
2 changed files with 28 additions and 10 deletions

View file

@ -20,20 +20,24 @@ from weboob.tools.parsers.lxmlparser import select, SelectElementException
class NoAuthorElement(SelectElementException): class NoAuthorElement(SelectElementException):
pass pass
class NoneMainDiv(AttributeError):
pass
class Article(object): class Article(object):
author = u''
def __init__(self, browser, _id): def __init__(self, browser, _id):
self.browser = browser self.browser = browser
self.id = _id self.id = _id
self.title = u'' self.title = u''
self.body = u'' self.body = u''
self.url = u'' self.url = u''
self.author = u''
self.date = None self.date = None
class GenericNewsPage(BasePage): class GenericNewsPage(BasePage):
__element_body = NotImplementedError __element_body = NotImplementedError
__article = Article __article = Article
element_title_selector = "h1" element_title_selector = NotImplementedError
main_div = NotImplementedError main_div = NotImplementedError
element_body_selector = NotImplementedError element_body_selector = NotImplementedError
element_author_selector = NotImplementedError element_author_selector = NotImplementedError
@ -45,7 +49,7 @@ class GenericNewsPage(BasePage):
try: try:
return self.get_element_author().text_content().strip() return self.get_element_author().text_content().strip()
except NoAuthorElement: except NoAuthorElement:
return None return self.__article.author
def get_title(self): def get_title(self):
return select( return select(
@ -61,9 +65,14 @@ class GenericNewsPage(BasePage):
return select(self.main_div, self.element_author_selector, 1) return select(self.main_div, self.element_author_selector, 1)
except SelectElementException: except SelectElementException:
raise NoAuthorElement() raise NoAuthorElement()
except AttributeError:
if self.main_div == None:
raise NoneMainDiv("main_div is none on %s" % (self.browser))
else:
raise
def get_article(self, id): def get_article(self, _id):
__article = Article(self.browser, id) __article = Article(self.browser, _id)
__article.author = self.get_author() __article.author = self.get_author()
__article.title = self.get_title() __article.title = self.get_title()
__article.url = self.url __article.url = self.url

View file

@ -20,20 +20,24 @@ from weboob.tools.parsers.lxmlparser import select, SelectElementException
class NoAuthorElement(SelectElementException): class NoAuthorElement(SelectElementException):
pass pass
class NoneMainDiv(AttributeError):
pass
class Article(object): class Article(object):
author = u''
def __init__(self, browser, _id): def __init__(self, browser, _id):
self.browser = browser self.browser = browser
self.id = _id self.id = _id
self.title = u'' self.title = u''
self.body = u'' self.body = u''
self.url = u'' self.url = u''
self.author = u''
self.date = None self.date = None
class GenericNewsPage(BasePage): class GenericNewsPage(BasePage):
__element_body = NotImplementedError __element_body = NotImplementedError
__article = Article __article = Article
element_title_selector = "h1" element_title_selector = NotImplementedError
main_div = NotImplementedError main_div = NotImplementedError
element_body_selector = NotImplementedError element_body_selector = NotImplementedError
element_author_selector = NotImplementedError element_author_selector = NotImplementedError
@ -45,7 +49,7 @@ class GenericNewsPage(BasePage):
try: try:
return self.get_element_author().text_content().strip() return self.get_element_author().text_content().strip()
except NoAuthorElement: except NoAuthorElement:
return None return self.__article.author
def get_title(self): def get_title(self):
return select( return select(
@ -61,9 +65,14 @@ class GenericNewsPage(BasePage):
return select(self.main_div, self.element_author_selector, 1) return select(self.main_div, self.element_author_selector, 1)
except SelectElementException: except SelectElementException:
raise NoAuthorElement() raise NoAuthorElement()
except AttributeError:
if self.main_div == None:
raise NoneMainDiv("main_div is none on %s" % (self.browser))
else:
raise
def get_article(self, id): def get_article(self, _id):
__article = Article(self.browser, id) __article = Article(self.browser, _id)
__article.author = self.get_author() __article.author = self.get_author()
__article.title = self.get_title() __article.title = self.get_title()
__article.url = self.url __article.url = self.url