[hybride] improve browser2 adaptation
This commit is contained in:
parent
eefe784352
commit
9cd521bfde
3 changed files with 35 additions and 66 deletions
|
|
@ -46,19 +46,25 @@ class CombineDate(Filter):
|
|||
return datetime.combine(format_date(text), time.max)
|
||||
|
||||
|
||||
class Description(Filter):
|
||||
def filter(self, el):
|
||||
description = ''
|
||||
|
||||
description_intro = el[0].xpath("div[@class='itemIntroText']/table/tbody/tr/td")
|
||||
|
||||
if description_intro and len(description_intro) > 0:
|
||||
description += u'%s' % description_intro[0].text_content()
|
||||
|
||||
description_content = el[0].xpath("div[@class='itemFullText']/table/tbody/tr/td")
|
||||
|
||||
if description_content and len(description_content) > 0:
|
||||
description += u'%s' % description_content[0].text_content()
|
||||
|
||||
return u'%s' % description
|
||||
|
||||
|
||||
class ProgramPage(HTMLPage):
|
||||
|
||||
date_from = None
|
||||
date_to = None
|
||||
city = None
|
||||
categories = None
|
||||
|
||||
def set_filters(self, date_from, date_to, city, categories):
|
||||
self.date_from = date_from
|
||||
self.date_to = date_to
|
||||
self.city = city
|
||||
self.categories = categories
|
||||
|
||||
@method
|
||||
class list_events(ListElement):
|
||||
item_xpath = '//div[@class="catItemView groupLeading"]'
|
||||
|
|
@ -66,27 +72,23 @@ class ProgramPage(HTMLPage):
|
|||
class item(ItemElement):
|
||||
klass = HybrideCalendarEvent
|
||||
|
||||
def condition(self):
|
||||
return self.check_date() and self.check_city() and self.check_category()
|
||||
def validate(self, obj):
|
||||
return self.check_date(obj) and self.check_city(obj) and self.check_category(obj)
|
||||
|
||||
def check_date(self):
|
||||
date = self.el.xpath("div[@class='catItemHeader']/span[@class='catItemDateCreated']")[0]
|
||||
event_date = format_date(date.text)
|
||||
if self.page.date_from and event_date >= self.page.date_from:
|
||||
if not self.page.date_to:
|
||||
def check_date(self, obj):
|
||||
if self.env['date_from'] and obj.start_date > self.env['date_from']:
|
||||
if not self.env['date_to']:
|
||||
return True
|
||||
else:
|
||||
if event_date <= self.page.date_to:
|
||||
if obj.end_date < self.env['date_to']:
|
||||
return True
|
||||
return False
|
||||
|
||||
def check_city(self):
|
||||
return (not self.page.city or (self.page.city and
|
||||
self.page.city.upper() == HybrideCalendarEvent.get_city().upper())
|
||||
)
|
||||
def check_city(self, obj):
|
||||
return (not self.env['city'] or self.env['city'].upper() == obj.city.upper())
|
||||
|
||||
def check_category(self):
|
||||
return (not self.page.categories or HybrideCalendarEvent.get_category() in self.page.categories)
|
||||
def check_category(self, obj):
|
||||
return (not self.env['categories'] or obj.category in self.env['categories'])
|
||||
|
||||
class CheckId(Filter):
|
||||
def filter(self, a_id):
|
||||
|
|
@ -100,8 +102,6 @@ class ProgramPage(HTMLPage):
|
|||
obj_start_date = Date(CleanText('div[@class="catItemHeader"]/span[@class="catItemDateCreated"]'))
|
||||
obj_end_date = CombineDate(CleanText('div[@class="catItemHeader"]/span[@class="catItemDateCreated"]'))
|
||||
obj_summary = CleanText('div[@class="catItemHeader"]/h3[@class="catItemTitle"]/a')
|
||||
obj_city = HybrideCalendarEvent.get_city()
|
||||
obj_category = HybrideCalendarEvent.get_category()
|
||||
|
||||
|
||||
class EventPage(HTMLPage):
|
||||
|
|
@ -111,40 +111,18 @@ class EventPage(HTMLPage):
|
|||
klass = HybrideCalendarEvent
|
||||
|
||||
def parse(self, el):
|
||||
div = el.xpath("//div[@class='itemView']")[0]
|
||||
|
||||
if self.obj.id:
|
||||
event = self.obj
|
||||
event.url = self.page.url
|
||||
event.description = self.get_description(div)
|
||||
event.description = Description('//div[@class="itemView"]/div[@class="itemBody"]')(self)
|
||||
raise SkipItem()
|
||||
|
||||
re_id = re.compile('http://www.lhybride.org/programme/item/(.*?)', re.DOTALL)
|
||||
self.env['id'] = re_id.search(self.page.url).group(1)
|
||||
self.env['url'] = self.page.url
|
||||
self.env['description'] = self.get_description(div)
|
||||
|
||||
def get_description(self, div):
|
||||
description = ''
|
||||
|
||||
description_intro = div.xpath("div[@class='itemBody']/div[@class='itemIntroText']/table/tbody/tr/td")
|
||||
|
||||
if description_intro and len(description_intro) > 0:
|
||||
description += u'%s' % description_intro[0].text_content()
|
||||
|
||||
description_content = div.xpath("div[@class='itemBody']/div[@class='itemFullText']/table/tbody/tr/td")
|
||||
|
||||
if description_content and len(description_content) > 0:
|
||||
description += u'%s' % description_content[0].text_content()
|
||||
|
||||
return u'%s' % description
|
||||
|
||||
obj_id = Env('id')
|
||||
obj_id = Env('_id')
|
||||
base = '//div[@class="itemView"]/div[@class="itemHeader"]'
|
||||
obj_start_date = Date(CleanText('%s/span[@class="itemDateCreated"]' % base))
|
||||
obj_end_date = CombineDate(CleanText('%s/span[@class="itemDateCreated"]' % base))
|
||||
obj_summary = CleanText('%s/h2[@class="itemTitle"]' % base)
|
||||
obj_city = HybrideCalendarEvent.get_city()
|
||||
obj_category = HybrideCalendarEvent.get_category()
|
||||
obj_url = Env('url')
|
||||
obj_description = Env('description')
|
||||
obj_description = Description('//div[@class="itemView"]/div[@class="itemBody"]')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue