Beispiel #1
0
    def setUp(self):
        self._defined = dir(pdb_stats)
        self._missing = list(set(PdbTestCase.REQUIRED) - set(self._defined))
        TEST_LINES = PdbTestCase.TEST_LINES
        self._atom_lines = TEST_LINES[2:9]
        self._title_line = TEST_LINES[1]
        self._ignore_lines = TEST_LINES[0:1] + TEST_LINES[9:]
        self._test_pdb = "\n".join(TEST_LINES)

        try:
            self._parsed_atoms = []
            for line in self._atom_lines:
                self._parsed_atoms.append(pdb_stats.parse_atom_line(line))
        except:
            self._parsed_atoms = None

        try:
            self._parsed_pdb = pdb_stats.parse_pdb(TEST_LINES)
        except:
            self._parsed_pdb = None

        try:
            self._downloaded_pdb = download(PdbTestCase.TEST_PDBID)
        except:
            self._downloaded_pdb = None
Beispiel #2
0
    def load_manifest(self, current_version):
        try:
            copy_file("data.pls", "save/data.pls")
            move_file("PlayListStore4.exe", "save/PlayListStore4.exe")

            versions = download(VersionsPath).text.split('=')
            if versions[-1] != current_version:
                if current_version == versions[-2]:
                    manifest = download(ManifestPath +
                                        "%s.txt" % versions[-1]).text
                    self.update(manifest)
                else:
                    for version in versions[versions.index(current_version) +
                                            1:]:
                        manifest = download(ManifestPath + "%s.txt" % version)
                        self.update(manifest)
        except Exception as e:
            print(e)
            open("UPDATE_ERRORS.txt", 'w').write(str(e))
            self.close()
Beispiel #3
0
    def test_19_build_url(self):
        self.skip_if_missing('build_url')

        self.assertIsNone(pdb_stats.build_url("This should be None"))

        url = pdb_stats.build_url(PdbTestCase.TEST_PDB_ID)
        try:
            # This is a hack for 2-3 compatibility
            result = unicode(download(url).content)
            self.assertTrue(result.startswith(PdbTestCase.TEST_PDB_HEADER))
        except:
            self.skipTest("Download was unable to complete")
def download_table(table_url):
    """Returns a BeautifulSoup ResultSet with all tables from the WikiCommons
    Hanzi decomposition project. Each table is contained in a <pre> tag."""
    # get a list of all <pre>-elements
    print('Downloading from {}...'.format(table_url), end='')
    decomp_html = download(table_url).text
    print('Done.')
    decomp_soup = BeautifulSoup(decomp_html, 'html.parser').find_all('pre')
    # remove first part that describes the table
    if re.search(r'1\.[^2]+2\.', decomp_soup[0].string, re.DOTALL):
        decomp_soup.pop(0)

    return decomp_soup
Beispiel #5
0
def gismeteo_ru():

    url  = 'https://www.gismeteo.ru/city/daily/5039/'
    ua   = {'user-agent': 'cw-app/0.0.1'}
    html = download(url, headers=ua).text

    soup   = bs(html, 'html.parser')

    found = soup.find_all('span', 'value m_wind ms')
    for index in [0, 1,  2,  3]:
        root = found[index].parent.parent.parent.parent.find_all('td')  # OLOLO

        print(bold(light[index]), end=" ")
        for elem in root:
            if elem.has_attr('class'):
                at = elem.attrs['class'][0]
                if   'clicon' == at:
                    pass
                elif 'cltext' == at:
                    print(f(46,7,30, elem.text))  # Облачно
                elif 'temp'   == at:
                    for ch in elem.children:
                        print("Tемпература воздуха {}".format(f(48,7,91,ch.text)))
                        break

            else:
                size = len(list(elem.children))
                if   1 == size: # два случая
                    for ch in elem.children:
                        try:
                            tag = ch.tag  # exception!
                            title = ""
                            for c in ch.children:
                                if c.has_attr('title'):
                                    title = c.attrs['title']
                                else:
                                    for x in c.children:
                                        print("Ветер     {}, {} м/с".format(f(41,1,37,title), f(48,0,1,x.text)))
                                        break
                        except: # Влажность
                            print("Влажность {}".format(f(46,0,33,elem.text)))
                            break
                elif 2 == size:
                    for ch in elem.children:
                        print("Ощущается {}".format(f(48,7,31,ch.text)))
                        break
                elif 3 == size: # "value m_press torr"
                    for ch in elem.children:
                        print("Атмосферн. давление {} мм рт. ст.".format(f(0,1,100,ch.text)))
                        break
        print("")
    def parse(self, response):
        for pics in response.css('div img::attr(src)').re(r'.*.jpg'):
            pic = download(pics)
            f = open("{0}".format(pics.split('/')[-1]), 'wb')
            for chunk in pic.iter_content(10000):
                f.write(chunk)
            f.close()

        #http://www.vgcats.com/comics/?strip_id=0    first comic, increments will need to check and stop download if see duplicate

        #recursion to keep download all comics
        #<div align="center">
        #<a href="?strip_id=385"><img src="next.gif" border="0"></a>
        next_page = response.css('div a::attr(href)').re(r'.*page.*')[0]
        #checks if it is the first comic
        if next_page is None:
            yield scrapy.Request(next_page, callback=self.parse)
Beispiel #7
0
    def update(self, manifest):
        try:
            manifest = manifest.split('\n')
            modules = manifest[1:1 + int(manifest[1])]
            params = manifest[1 + int(manifest[1]):]

            self.bar.setValue(0)
            self.bar.setMaximum(len(manifest) - 1)
            for module_name in modules:
                file = download(BasePath + module_name)
                open(module_name, "wb").write(file.content)
                self.bar.setValue(self.bar.value() + 1)
                self.status.setText("Downloading: %s" % module_name)

            self.apply_params(params)
            self.close()
            run_app('PlayListStore4.exe update')
        except Exception as e:
            print(e)
            open("UPDATE_ERRORS.txt", 'w').write(str(e))
            self.close()