Exemplo n.º 1
0
 def on_loaded(self):
     try:
         raise BrowserUnavailable(
             self.parser.select(self.document.getroot(),
                                'div#message_error_hs', 1).text.strip())
     except BrokenPageError:
         raise BrowserUnavailable()
Exemplo n.º 2
0
    def on_loaded(self):
        try:
            h1 = self.parser.select(self.document.getroot(), 'h1', 1)
        except BrokenPageError:
            pass

        if h1.text is not None and h1.text.startswith('Le service est moment'):
            try:
                raise BrowserUnavailable(self.document.xpath('//h4')[0].text)
            except KeyError:
                raise BrowserUnavailable(h1.text)
Exemplo n.º 3
0
    def get_location(self, ipaddr):
        with self.browser:

            content = self.browser.readurl('http://www.geolocip.com/?s[ip]=%s&commit=locate+IP!' % str(ipaddr))

            if content is None:
                raise BrowserUnavailable()

            tab = {}
            last_line = ''
            line = ''
            for line in content.split('\n'):
                if len(line.split('<dd>')) > 1:
                    key = last_line.split('<dt>')[1].split('</dt>')[0][0:-2]
                    value = line.split('<dd>')[1].split('</dd>')[0]
                    tab[key] = value
                last_line = line
            iploc = IpLocation(ipaddr)
            iploc.city = tab['City']
            iploc.region = tab['Region']
            iploc.zipcode = tab['Postal code']
            iploc.country = tab['Country name']
            if tab['Latitude'] != '':
                iploc.lt = float(tab['Latitude'])
            else:
                iploc.lt = 0.0
            if tab['Longitude'] != '':
                iploc.lg = float(tab['Longitude'])
            else:
                iploc.lg = 0.0
            #iploc.host = 'NA'
            #iploc.tld = 'NA'
            #iploc.isp = 'NA'

            return iploc
Exemplo n.º 4
0
    def on_loaded(self):
        errors = []
        for div in self.parser.select(self.document.getroot(), 'div.poetry'):
            errors.append(self.parser.tocleanstring(div))

        if len(errors) > 0:
            raise BrowserUnavailable(', '.join(errors))
Exemplo n.º 5
0
 def on_loaded(self):
     try:
         a = self.document.xpath('//a[@class="btn"]')[0]
     except IndexError:
         raise BrowserUnavailable()
     else:
         self.browser.location(a.attrib['href'])
Exemplo n.º 6
0
 def on_loaded(self):
     for td in self.document.getroot().cssselect('td.LibelleErreur'):
         if td.text is None:
             continue
         msg = td.text.strip()
         if 'indisponible' in msg:
             raise BrowserUnavailable(msg)
Exemplo n.º 7
0
 def on_loaded(self):
     # Check for an error
     for div in self.document.getiterator('div'):
         if div.attrib.get('class',
                           '') == 'dv' and div.getchildren()[0].tag in (
                               'img') and div.getchildren()[0].attrib.get(
                                   'alt', '') == 'Attention':
             # Try to find a detailed error message
             if div.getchildren()[1].tag == 'span':
                 raise BrowserUnavailable(div.find('span').find('b').text)
             elif div.getchildren()[1].tag == 'b':
                 # I haven't encountered this variation in the wild,
                 # but I wouldn't be surprised if it existed
                 # given the similar differences between regions.
                 raise BrowserUnavailable(div.find('b').find('span').text)
             raise BrowserUnavailable()
Exemplo n.º 8
0
 def post_paste(self, paste, expiration=None):
     self.home()
     self.page.post(paste, expiration=expiration)
     if self.is_on_page(CaptchaPage):
         raise BrowserUnavailable(
             "Detected as spam and unable to handle the captcha")
     paste.id = self.page.get_id()
Exemplo n.º 9
0
    def get_video(self, url, video=None):
        requires_account = False
        redir_url = None

        # FIXME: this is quite ugly
        # but is required to handle cases like 1013422@gdcvault
        self.set_handle_redirect(False)
        try:
            self.open_novisit(url)
            #headers = req.info()
        except HTTPError as e:
            # print e.getcode()
            if e.getcode() == 302 and hasattr(e, 'hdrs'):
                #print e.hdrs['Location']
                if e.hdrs['Location'] in ['/', '/login']:
                    requires_account = True
                else:
                    # 1015865 redirects to a file with an eacute in the name
                    redir_url = unicode(e.hdrs['Location'], encoding='utf-8')
        self.set_handle_redirect(True)

        if requires_account:
            raise BrowserUnavailable('Requires account')

        if redir_url:
            if video is None:
                m = re.match(
                    'http://[w\.]*gdcvault.com/play/(?P<id>[\d]+)/?.*', url)
                if m:
                    # print m.group(1)
                    video = GDCVaultVideo(int(m.group(1)))
                else:
                    raise BrowserUnavailable(
                        'Cannot find ID on page with redirection')
            video.url = redir_url
            video.set_empty_fields(NotAvailable)
            # best effort for now
            return video

        self.location(url)
        # redirects to /login means the video is not public
        if not self.is_on_page(VideoPage):
            raise BrowserUnavailable('Requires account')
        return self.page.get_video(video)
Exemplo n.º 10
0
    def login(self, login, passwd):
        msgb = self.document.xpath(".//*[@id='message_client']/text()")
        msga = ''.join(msgb)
        msg = msga.strip("\n")

        if "maintenance" in msg:
            raise BrowserUnavailable(msg)

        self.browser.select_form(nr=3)
        self.browser['login'] = login.encode('utf-8')
        self.browser['passwd'] = passwd.encode('utf-8')
        self.browser.submit(nologin=True)
Exemplo n.º 11
0
    def login(self):
        assert isinstance(self.username, basestring)
        assert isinstance(self.password, basestring)
        assert self.password.isdigit()

        if not self.is_on_page(LoginPage):
            self.location('https://' + self.DOMAIN_LOGIN + '/index.html', no_login=True)

        self.page.login(self.username, self.password)

        if self.is_on_page(LoginPage):
            raise BrowserIncorrectPassword()

        if self.is_on_page(BadLoginPage):
            error = self.page.get_error()
            if error is None:
                raise BrowserIncorrectPassword()
            elif error.startswith('Votre session a'):
                raise BrowserUnavailable('Session has expired')
            elif error.startswith('Le service est momentan'):
                raise BrowserUnavailable(error)
            else:
                raise BrowserIncorrectPassword(error)
Exemplo n.º 12
0
    def get_location(self, ipaddr):
        with self.browser:

            content = self.browser.readurl('http://ipinfodb.com/ip_locator.php?ip=%s' % str(ipaddr))

            if content is None:
                raise BrowserUnavailable()

            if 'Invalid IP or domain name' in content:
                raise Exception('Bad parameter')
            else:
                tab = {'City' : 'NA' ,\
                        'Country name' : 'NA' ,\
                        'Region' : 'NA' ,\
                        'Latitude' : 'NA' ,\
                        'Longitude' : 'NA' ,\
                        'hostname' : 'NA' ,\
                        'zipcode' : 'NA'}
                line = ''
                for line in content.split('\n'):
                    if '<li>' in line:
                        if 'Country :' in line:
                            tab['Country name'] = line.split('Country : ')[1].split('<')[0]
                        elif "State/Province :" in line:
                            tab['Region'] = line.split('State/Province : ')[1].split('<')[0]
                        elif "City :" in line:
                            tab['City'] = line.split('City : ')[1].split('<')[0]
                        elif "Latitude :" in line:
                            tab['Latitude'] = line.split('Latitude : ')[1].split('<')[0]
                        elif "Longitude :" in line:
                            tab['Longitude'] = line.split('Longitude : ')[1].split('<')[0]
                        elif "Hostname :" in line:
                            tab['hostname'] = line.split('Hostname : ')[1].split('<')[0]
                iploc = IpLocation(ipaddr)
                iploc.city = tab['City'].decode('utf-8')
                iploc.region = tab['Region']
                iploc.zipcode = tab['zipcode']
                iploc.country = tab['Country name']
                try :
                    iploc.lt = float(tab['Latitude'])
                    iploc.lg = float(tab['Longitude'])
                except ValueError:
                    pass
                iploc.host = tab['hostname']
                iploc.tld = tab['hostname'].split('.')[-1]
                #iploc.isp = 'NA'

                return iploc
Exemplo n.º 13
0
 def on_loaded(self):
     raise BrowserUnavailable('Website is currently unavailable')
Exemplo n.º 14
0
 def on_loaded(self):
     warn = self.document.xpath('//div[@id="attTxt"]')
     if len(warn) > 0:
         raise BrowserUnavailable(warn[0].text)
Exemplo n.º 15
0
 def on_loaded(self):
     raise BrowserUnavailable()