Пример #1
0
    def _common_clean(self, att, filter=None):
        """
        Spolecna funkce pro clean_XXX metody. Zadany KML soubor rozparsuje a
        vytahne z nej nosne informace pod atribut `att`_data (napr. polygon_data).
        """
        data = self.cleaned_data.get(att)

        if data:
            # kontrola URL
            data = data.strip()
            if 'output=nl' not in data:
                data = data + '&output=nl'

            # stahneme KML soubor
            content = download_content(data)
            if content is None:
                # chyba behem downloadu
                logger.info('Problem with downloading URL %s' % data)
                return None, self.err_down
            setattr(self, '%s_kml' % att, content)

            # rozparsujeme zadany KML
            try:
                parsed_data = parse_xml(KMLHandler(), content, filter)
            except:
                logger.info('Parsing error during processing content of %s' % data)
                return None, self.err_wrong
            if not parsed_data:
                logger.info('Content of %s does not contain geo data' % data)
                # ha! mozna jsme dostali link na "spatny" KML, overime si to
                parsed_data2 = parse_xml(LinkHandler(), content)
                if len(parsed_data2) != 1:
                    logger.info('Content of %s does not contain link data' % data)
                    # uzivatel zadal asi nejake spatne URL
                    return None, self.err_wrong

                # mame nove URL, zkusime to s nim znovu
                new_url = parsed_data2[0]
                logger.info('Content of %s contain link to %s' % (data, new_url))
                # stahneme KML soubor
                content = download_content(new_url)
                if content is None:
                    # chyba behem downloadu
                    logger.info('Problem with downloading URL %s' % new_url)
                    return None, self.err_down
                setattr(self, '%s_kml' % att, content)

                # rozparsujeme novy KML
                parsed_data = parse_xml(KMLHandler(), content, filter)
                if not parsed_data:
                    # tak ani odkaz ze "spatneho" KML nas nikam nedovedl
                    logger.info('Content of %s does not contain geo data' % new_url)
                    return None, self.err_wrong

                data = new_url

            setattr(self, '%s_data' % att, parsed_data)

        return data, None
Пример #2
0
    def find_entry_information(self):
        """
        Zjisti dodatecne informace ze zadanych KML souboru. Co presne?

        * vypocita geograficky stred vsech heren
        * podle lat/lon pozice pres google zjisti nazev mesta
        * z wikipedie vyzobne informaci o poctu obyvatel a rozloze

        Tyto informace slouzi pro naplneni zaznamu Entry.
        """
        out = {'wikipedia_url': None, 'public': False}
        out['pos'] = self.find_center()
        out['town'] = self.find_town(out['pos'])
        if out['town']:
            out['wikipedia_url'] = self.guess_wikipedia_url(out['town'])
            wikipedia_content = download_content(out['wikipedia_url'])
            if wikipedia_content:
                out.update(parse_xml(MediaWikiHandler(), wikipedia_content))
                if out['population'] and out['area']:
                    out['public'] = True
        return out