Exemple #1
0
    def get_video(self, _id):
        video = QuviVideo(_id)

        parser = LibQuvi()
        if not parser.load():
            raise UserError('Make sure libquvi 0.4 is installed')

        try:
            info = parser.get_info(video.page_url)
        except QuviError as qerror:
            raise UserError(qerror.message)

        video.url = to_unicode(info.get('url'))
        if not video.url:
            raise NotImplementedError()

        video.ext = to_unicode(info.get('suffix'))
        video.title = to_unicode(info.get('title'))
        video.page = to_unicode(info.get('page'))
        duration = int(info.get('duration', 0))
        if duration:
            video.duration = datetime.timedelta(milliseconds=duration)
        if info.get('thumbnail'):
            video.thumbnail = BaseImage(info.get('thumbnail'))
            video.thumbnail.url = video.thumbnail.id
        return video
Exemple #2
0
    def on_load(self):
        if not self.doc['success']:
            for err in self.doc.get('errors', []):
                raise Exception(err['msg'])

        # at this point, success is true, but that doesn't really mean anything
        if isinstance(self.doc['d'], list) and self.doc['d']:
            # does this still happen?
            msg = self.doc['d'][0].get('ErrorMessage')
            if msg:
                raise UserError(msg)
        elif isinstance(self.doc['d'], dict) and self.doc['d'].get('Errors'):
            msg = self.doc['d']['Errors'][0].get('Value')
            if msg:
                raise UserError(msg)
Exemple #3
0
    def search_videos(self, pattern, sortby):
        if pattern == 'a' or pattern == 'i':
            raise UserError('this pattern is not supported');

        self.search.go(query=pattern)
        assert self.search.is_here()
        return self.page.iter_videos()
Exemple #4
0
    def search_videos(self, pattern):
        if len(pattern) < 3:
            raise UserError('Pattern to short (min length : 3 characters)')

        self.search.go(pattern=pattern, pagenum=1)
        assert self.search.is_here(pattern=pattern, pagenum=1)

        return self.page.iter_videos()
Exemple #5
0
    def search_events(self, query):
        if CATEGORIES.CINE in query.categories:
            if query.city and re.match('\d{5}', query.city):
                events = list(self.browser.search_events(query))
                events.sort(key=lambda x: x.start_date, reverse=False)
                return events

            raise UserError('You must enter a zip code in city field')
Exemple #6
0
    def on_load(self):
        if not self.doc['success']:
            for err in self.doc.get('errors', []):
                raise Exception(err['msg'])

        if isinstance(self.doc['d'], list) and self.doc['d']:
            msg = self.doc['d'][0].get('ErrorMessage')
            if msg:
                raise UserError(msg)
Exemple #7
0
 def transfer(self, account, recipient, amount, reason):
     if not reason:
         raise UserError(
             'Reason is mandatory to do a transfer on ING website')
     if not isinstance(account, Account):
         account = self.get_account(account)
     if not isinstance(recipient, Recipient):
         # Remove weboob identifier prefix (LA-, CC-...)
         if "-" in recipient:
             recipient = recipient.split('-')[1]
     return self.browser.transfer(account, recipient, amount, reason)
Exemple #8
0
    def get_event(self, _id, event=None):
        if not event:
            try:
                event = self.films_page.go().iter_films(_id=_id).next()
            except StopIteration:
                raise UserError('This event (%s) does not exists' % _id)

        film_id = _id.split('#')[0]
        event = self.event_page.go(_id=film_id).get_event(obj=event)
        resume = self.get_resume(film_id)
        event.description += resume
        return event
Exemple #9
0
    def id2url(cls, _id):
        if _id.startswith('http'):
            return _id

        if not '.' in _id:
            raise UserError('Please give an ID in form WEBSITE.ID (for example youtube.BaW_jenozKc). Supported websites are: %s' % ', '.join(cls.BACKENDS.keys()))

        sub_backend, sub_id = _id.split('.', 1)
        try:
            return cls.BACKENDS[sub_backend] % sub_id
        except KeyError:
            raise NotImplementedError()
Exemple #10
0
    def _get_sensor_by_id(self, id):
        try:
            sensor_name, gauge_name, contract = id.split('.')
        except ValueError:
            raise UserError('Expected format NAME.ID.CITY for sensor: %r' % id)

        gauge = self._get_gauge_by_id('%s.%s' % (gauge_name, contract))
        if not gauge:
            raise SensorNotFound()
        for sensor in gauge.sensors:
            if sensor.id.lower() == id.lower():
                return sensor
Exemple #11
0
    def __init__(self, lang, quality, order, format, version, *args, **kwargs):
        super(ArteBrowser, self).__init__(*args, **kwargs)
        self.order = order
        self.lang = next(value for key, value in LANG.items if key == lang)
        self.version = next(
            value for key, value in VERSION_VIDEO.items
            if self.lang.get('label') in value.keys() and version == key)
        self.quality = next(value for key, value in QUALITY.items
                            if key == quality)
        self.format = format

        if self.lang.get('label') not in self.version.keys():
            raise UserError('%s is not available for %s' %
                            (self.lang.get('label'), version))
Exemple #12
0
    def do_login(self):
        if self.login_browser:
            if self.login_browser.code is None or self.user_id is None:
                self.login_browser.do_login()
                params = {'code': self.login_browser.code,
                          'client_id': 'feedly',
                          'client_secret': '0XP4XQ07VVMDWBKUHTJM4WUQ',
                          'redirect_uri': 'http://dev.feedly.com/feedly.html',
                          'grant_type': 'authorization_code'}

                token, self.user_id = self.token.go(data=params).get_token()
                self.session.headers['X-Feedly-Access-Token'] = token
        else:
            raise UserError(r'You need to fill your username and password to access this page')
Exemple #13
0
    def iter_prices(self, zipcode, product):
        if self.TOKEN is None:
            self.get_token()

        data = {
            '_recherche_recherchertype[localisation]': '%s' % zipcode,
            '_recherche_recherchertype[choix_carbu]': '%s' % product.id,
            '_recherche_recherchertype[_token]': '%s' % self.TOKEN, }

        self.index_page.go(data=data)

        if not self.result_page.is_here():
            raise UserError('Bad zip or product')

        if not product.name:
            product.name = self.page.get_product_name()

        return self.page.iter_results(product=product)
Exemple #14
0
    def search(self, departure, arrival, date, age, card, comfort_class):
        self.browser.select_form(name='saisie')
        self.browser['ORIGIN_CITY'] = departure.encode(self.browser.ENCODING)
        self.browser['DESTINATION_CITY'] = arrival.encode(
            self.browser.ENCODING)

        if date is None:
            date = datetime.now() + timedelta(hours=1)
        elif date < datetime.now():
            raise UserError("You cannot look for older departures")

        self.browser['OUTWARD_DATE'] = date.strftime('%d/%m/%y')
        self.browser['OUTWARD_TIME'] = [str(date.hour)]
        self.browser['PASSENGER_1'] = [age]
        self.browser['PASSENGER_1_CARD'] = [card]
        self.browser['COMFORT_CLASS'] = [str(comfort_class)]
        self.browser.controls.append(
            TextControl('text', 'nbAnimalsForTravel', {'value': ''}))
        self.browser['nbAnimalsForTravel'] = '0'
        self.browser.submit()
Exemple #15
0
    def fetch_info(self):
        if not self.doc['success']:
            raise UserError(self.doc['msg']['msg'])

        return self.doc['msg']
Exemple #16
0
 def __init__(self, msg='You cannot select more than three cities'):
     UserError.__init__(self, msg)
Exemple #17
0
 def __init__(self, msg='You cannot select more than three cities'):
     UserError.__init__(self, msg)
Exemple #18
0
 def on_loaded(self):
     p = self.document.getroot().cssselect('div.messagesError p')
     if len(p) > 0:
         message = p[0].text.strip()
         raise UserError(message)
Exemple #19
0
 def on_loaded(self):
     raise UserError(
         'Your IP address is localized in a country not supported by this module (%s). Currently only the French website is supported.'
         % self.group_dict['country'])