diff --git a/modules/biplan/__init__.py b/modules/biplan/__init__.py deleted file mode 100644 index 81701c18e96bc6db556efc2f27cf9a8074ce57de..0000000000000000000000000000000000000000 --- a/modules/biplan/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2013 Bezleputh -# -# This file is part of a weboob module. -# -# This weboob module 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. -# -# This weboob module 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 this weboob module. If not, see . - - -from .module import BiplanModule - - -__all__ = ['BiplanModule'] diff --git a/modules/biplan/browser.py b/modules/biplan/browser.py deleted file mode 100644 index 5596593e6aabccc673bf4e402181cb13c5bd2c2f..0000000000000000000000000000000000000000 --- a/modules/biplan/browser.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2013 Bezleputh -# -# This file is part of a weboob module. -# -# This weboob module 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. -# -# This weboob module 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 this weboob module. If not, see . - - -from weboob.browser import PagesBrowser, URL - -from .pages import ProgramPage, EventPage - -__all__ = ['BiplanBrowser'] - - -class BiplanBrowser(PagesBrowser): - BASEURL = 'https://www.lebiplan.org' - - program_page = URL('/fr/biplan-prog-(?P<_category>.*).php', ProgramPage) - event_page = URL('/(?P<_id>.*).html', EventPage) - - def list_events_concert(self, date_from, date_to=None, city=None, categories=None): - return self.program_page.go(_category='concert').list_events(date_from=date_from, - date_to=date_to, - city=city, - categories=categories, - is_concert=True) - - def list_events_theatre(self, date_from, date_to=None, city=None, categories=None): - return self.program_page.go(_category='theatre').list_events(date_from=date_from, - date_to=date_to, - city=city, - categories=categories, - is_concert=False) - - def get_event(self, _id, event=None): - return self.event_page.go(_id=_id).get_event(obj=event) diff --git a/modules/biplan/calendar.py b/modules/biplan/calendar.py deleted file mode 100644 index 01a258fa5f09cb5aaf6ff8eff7050ab742f3f3d7..0000000000000000000000000000000000000000 --- a/modules/biplan/calendar.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2013 Bezleputh -# -# This file is part of a weboob module. -# -# This weboob module 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. -# -# This weboob module 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 this weboob module. If not, see . - -from weboob.capabilities.calendar import BaseCalendarEvent, TRANSP, STATUS, CATEGORIES - - -class BiplanCalendarEvent(BaseCalendarEvent): - - def __init__(self): - BaseCalendarEvent.__init__(self) - self.city = u'LILLE' - self.location = u'19, rue Colbert' - self.sequence = 1 - self.transp = TRANSP.TRANSPARENT - self.status = STATUS.CONFIRMED - self.timezone = u'Europe/Paris' - - -class BiplanCalendarEventConcert(BiplanCalendarEvent): - def __init__(self): - BiplanCalendarEvent.__init__(self) - self.category = CATEGORIES.CONCERT - - -class BiplanCalendarEventTheatre(BiplanCalendarEvent): - def __init__(self): - BiplanCalendarEvent.__init__(self) - self.category = CATEGORIES.THEATRE diff --git a/modules/biplan/favicon.png b/modules/biplan/favicon.png deleted file mode 100644 index e2f65474828f1c926e91af8c3b221178dbad497a..0000000000000000000000000000000000000000 Binary files a/modules/biplan/favicon.png and /dev/null differ diff --git a/modules/biplan/module.py b/modules/biplan/module.py deleted file mode 100644 index 7d647b9b326af75ee985e49fa48b9aed4b3fa30c..0000000000000000000000000000000000000000 --- a/modules/biplan/module.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2013 Bezleputh -# -# This file is part of a weboob module. -# -# This weboob module 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. -# -# This weboob module 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 this weboob module. If not, see . - - -from weboob.tools.backend import Module -from weboob.capabilities.calendar import CapCalendarEvent, CATEGORIES -import itertools - -from .browser import BiplanBrowser -from.calendar import BiplanCalendarEvent - -__all__ = ['BiplanModule'] - - -class BiplanModule(Module, CapCalendarEvent): - NAME = 'biplan' - DESCRIPTION = u'lebiplan.org website' - MAINTAINER = u'Bezleputh' - EMAIL = 'carton_ben@yahoo.fr' - LICENSE = 'AGPLv3+' - VERSION = '1.6' - ASSOCIATED_CATEGORIES = [CATEGORIES.CONCERT, CATEGORIES.THEATRE] - BROWSER = BiplanBrowser - - def search_events(self, query): - if self.has_matching_categories(query): - theatre_events = [] - concert_events = [] - if CATEGORIES.CONCERT in query.categories: - concert_events = self.browser.list_events_concert(query.start_date, - query.end_date, - query.city, - query.categories) - if CATEGORIES.THEATRE in query.categories: - theatre_events = self.browser.list_events_theatre(query.start_date, - query.end_date, - query.city, - query.categories) - - items = list(itertools.chain(concert_events, theatre_events)) - items.sort(key=lambda o: o.start_date) - return items - - def list_events(self, date_from, date_to=None): - items = list(itertools.chain(self.browser.list_events_concert(date_from, date_to), - self.browser.list_events_theatre(date_from, date_to))) - items.sort(key=lambda o: o.start_date) - return items - - def get_event(self, _id): - return self.browser.get_event(_id) - - def fill_obj(self, event, fields): - return self.browser.get_event(event.id, event) - - OBJECTS = {BiplanCalendarEvent: fill_obj} diff --git a/modules/biplan/pages.py b/modules/biplan/pages.py deleted file mode 100644 index ce86595c8cb0a5989cd38958851b16ebd9f11469..0000000000000000000000000000000000000000 --- a/modules/biplan/pages.py +++ /dev/null @@ -1,154 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2013 Bezleputh -# -# This file is part of a weboob module. -# -# This weboob module 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. -# -# This weboob module 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 this weboob module. If not, see . - -from __future__ import unicode_literals - -import re -from datetime import datetime, time - -import weboob.tools.date as date_util -from .calendar import BiplanCalendarEventConcert, BiplanCalendarEventTheatre - -from weboob.browser.elements import ItemElement, SkipItem, ListElement, method -from weboob.browser.pages import HTMLPage -from weboob.browser.filters.standard import Filter, CleanText, Env, Regexp, CombineDate -from weboob.browser.filters.html import Link, CleanHTML - - -class BiplanPrice(Filter): - def filter(self, el): - index = 1 if len(el) > 1 else 0 - content = CleanText.clean(CleanText('.', ['HORAIRES'])(el[index])) - a_price = content.split(' - ')[-1] - parsed_price = re.findall(r"\d*\,\d+|\d+", " ".join(a_price)) - - if parsed_price and len(parsed_price) > 0: - return float(parsed_price[0].replace(',', '.')) - - return float(0) - - -class BiplanDate(Filter): - def filter(self, el): - content = CleanText.clean(CleanText(CleanHTML('.'), ['*'])(el[0])) - a_date = content[0:content.index(' - ')] - - for fr, en in date_util.DATE_TRANSLATE_FR: - a_date = fr.sub(en, a_date) - - try: - _month = datetime.strptime(a_date, "%A %d %B").month - if (datetime.now().month > _month): - a_date += u' %i' % (datetime.now().year + 1) - else: - a_date += u' %i' % (datetime.now().year) - except ValueError: - pass - - return datetime.strptime(a_date, "%A %d %B %Y") - - -class StartTime(Filter): - def filter(self, el): - index = 1 if len(el) > 1 else 0 - content = CleanText.clean(CleanText('.', ['HORAIRES'])(el[index])) - _content = content.split(' - ') - a_time = _content[2] if len(_content) > 2 else _content[0] - regexp = re.compile(r'(?P\d+)h?(?P\d+)') - m = regexp.search(a_time) - if m: - return time(int(m.groupdict()['hh'] or 0), int(m.groupdict()['mm'] or 0)) - return time(0, 0) - - -class EndTime(Filter): - def filter(self, el): - return time.max - - -class ProgramPage(HTMLPage): - - @method - class list_events(ListElement): - item_xpath = '//div[@class="ligne"]' - - class item(ItemElement): - def klass(self): - return BiplanCalendarEventConcert() if self.env['is_concert'] else BiplanCalendarEventTheatre() - - def condition(self): - return (self.el.xpath('./div') and CleanText('./div/a/img/@src')(self)[-1] != '/') - - def validate(self, obj): - return (self.is_valid_event(obj, self.env['city'], self.env['categories']) and - self.is_event_in_valid_period(obj.start_date, self.env['date_from'], self.env['date_to'])) - - def is_valid_event(self, event, city, categories): - if city and city != '' and city.upper() != event.city.upper(): - return False - - if categories and len(categories) > 0 and event.category not in categories: - return False - - return True - - def is_event_in_valid_period(self, event_date, date_from, date_to): - if event_date >= date_from: - if not date_to: - return True - else: - if event_date <= date_to: - return True - return False - - obj_id = Regexp(Link('./div/a'), '/(.*?).html') - obj_start_date = CombineDate(BiplanDate('div/div/b'), StartTime('div/div/b')) - obj_end_date = CombineDate(BiplanDate('div/div/b'), EndTime('.')) - obj_price = BiplanPrice('div/div/b') - obj_summary = CleanText("div/div/div/a/strong") - - -class EventPage(HTMLPage): - - encoding = u'utf-8' - - @method - class get_event(ItemElement): - klass = BiplanCalendarEventConcert if Env('is_concert') else BiplanCalendarEventTheatre - - def parse(self, el): - _div = "//div/div/div[@id='popup']" - div = el.xpath("%s" % _div)[0] - if self.obj.id: - event = self.obj - event.url = self.page.url - event.description = CleanHTML("%s/div/div[@class='presentation-popup']" % _div)(self) - raise SkipItem() - - self.env['is_concert'] = (div.attrib['class'] != 'theatre-popup') - self.env['url'] = self.page.url - - obj_id = Env('_id') - base = "//div[@id='popup']" - obj_price = BiplanPrice("%s/div/b" % base) - obj_start_date = CombineDate(BiplanDate("%s/div/b" % base), StartTime("%s/div/b" % base)) - obj_end_date = CombineDate(BiplanDate("%s/div/b" % base), EndTime(".")) - obj_url = Env('url') - obj_summary = CleanText('%s/div/div/span' % base) - obj_description = CleanHTML('%s/div/div[@class="presentation-popup"]' % base) diff --git a/modules/biplan/test.py b/modules/biplan/test.py deleted file mode 100644 index cf7fedb49ed388849281073664a331bc0c5bd99c..0000000000000000000000000000000000000000 --- a/modules/biplan/test.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2013 Bezleputh -# -# This file is part of a weboob module. -# -# This weboob module 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. -# -# This weboob module 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 this weboob module. If not, see . - -from datetime import datetime - -from weboob.tools.test import BackendTest, SkipTest - - -class BiplanTest(BackendTest): - MODULE = 'biplan' - - def test_biplan_list(self): - if datetime.now() > datetime(datetime.now().year, 7, 14) and datetime.now() < datetime(datetime.now().year, 9, 15): - raise SkipTest("Fermeture estivale") - l = list(self.backend.list_events(datetime.now())) - assert len(l) - event = self.backend.get_event(l[0].id) - self.assertTrue(event.url, 'URL for event "%s" not found: %s' % (event.id, event.url))