Ejemplo n.º 1
0
    def create_category(self, category):
        title = self.api.Title(category)
        if title.iwprefix or title.namespace != "Category":
            raise ValueError("Invalid category name: [[{}]]".format(category))
        # normalize name
        category = title.fullpagename

        # skip existing categories
        if category in self.info:
            return

        pure, langname = lang.detect_language(category)
        if langname == lang.get_local_language():
            logger.warning(
                "Cannot automatically create {} category: [[{}]]".format(
                    lang.get_local_language(), category))
            return

        local = lang.format_title(pure, lang.get_local_language())
        if local not in self.info:
            logger.warning(
                "Cannot create category [[{}]]: {} category [[{}]] does not exist."
                .format(category, lang.get_local_language(), local))
            return

        def localized_category(cat, langname):
            pure, lgn = lang.detect_language(cat)
            if pure == "Category:Languages":
                # this terminates the recursive creation
                return pure
            elif pure.lower() == "category:" + lgn.lower():
                return "Category:{}".format(langname)
            return lang.format_title(pure, langname)

        if local in self.parents.keys():
            parents = [
                localized_category(p, langname) for p in self.parents[local]
            ]
            content = "\n".join("[[{}]]".format(p) for p in parents)
        else:
            parents = None
            content = ""

        self.api.create(title=category,
                        text=content,
                        summary="init wanted category")
        self.update()

        if parents is not None:
            for p in parents:
                self.create_category(p)
Ejemplo n.º 2
0
    def create_category(self, category):
        title = self.api.Title(category)
        if title.iwprefix or title.namespace != "Category":
            raise ValueError("Invalid category name: [[{}]]".format(category))
        # normalize name
        category = title.fullpagename

        # skip existing categories
        if category in self.info:
            return

        pure, langname = lang.detect_language(category)
        if langname == lang.get_local_language():
            logger.warning("Cannot automatically create {} category: [[{}]]".format(lang.get_local_language(), category))
            return

        local = lang.format_title(pure, lang.get_local_language())
        if local not in self.info:
            logger.warning("Cannot create category [[{}]]: {} category [[{}]] does not exist.".format(category, lang.get_local_language(), local))
            return

        def localized_category(cat, langname):
            pure, lgn = lang.detect_language(cat)
            if pure == "Category:Languages":
                # this terminates the recursive creation
                return pure
            elif pure.lower() == "category:" + lgn.lower():
                return "Category:{}".format(langname)
            return lang.format_title(pure, langname)

        parents = [localized_category(p, langname) for p in self.parents[local]]
        content = "\n".join("[[{}]]".format(p) for p in parents)

        self.api.create(title=category, text=content, summary="init wanted category")
        self.update()

        for p in parents:
            self.create_category(p)
Ejemplo n.º 3
0
 def find_orphans(self):
     """
     Returns list of pages that are alone in their families.
     """
     orphans = []
     for page in self.allpages:
         title = page["title"]
         # unsupported languages need to be skipped now
         if not self._is_valid_interlanguage(title):
             continue
         langlinks = self.get_langlinks(title)
         if lang.detect_language(title)[1] != lang.get_local_language() and len(langlinks) == 0:
             orphans.append(title)
     return orphans
Ejemplo n.º 4
0
 def find_orphans(self):
     """
     Returns list of pages that are alone in their families.
     """
     orphans = []
     for page in self.allpages:
         title = page["title"]
         # unsupported languages need to be skipped now
         if not self._is_valid_interlanguage(title):
             continue
         langlinks = self.get_langlinks(title)
         if lang.detect_language(title)[1] != lang.get_local_language(
         ) and len(langlinks) == 0:
             orphans.append(title)
     return orphans
Ejemplo n.º 5
0
    def __init__(self, api, cliargs):
        self.api = api
        self.cliargs = cliargs

        if self.cliargs.save is False and self.cliargs.print is False:
            self.cliargs.print = True

        if len(self.cliargs.toc_languages) == 1 and self.cliargs.toc_languages[0] == "all":
            self.cliargs.toc_languages = lang.get_internal_tags()
        # strip "(Language)" suffix
        self.cliargs.toc_page = lang.detect_language(canonicalize(self.cliargs.toc_page))[0]

        # detect page titles
        self.titles = []
        for ln in sorted(self.cliargs.toc_languages):
            if ln == lang.tag_for_langname(lang.get_local_language()):
                self.titles.append(self.cliargs.toc_page)
            else:
                self.titles.append("{} ({})".format(self.cliargs.toc_page, lang.langname_for_tag(ln)))
Ejemplo n.º 6
0
    def __init__(self, api, cliargs):
        self.api = api
        self.cliargs = cliargs

        if self.cliargs.save is False and self.cliargs.print is False:
            self.cliargs.print = True

        if len(self.cliargs.toc_languages) == 1 and self.cliargs.toc_languages[0] == "all":
            self.cliargs.toc_languages = lang.get_internal_tags()
        # strip "(Language)" suffix
        self.cliargs.toc_page = lang.detect_language(canonicalize(self.cliargs.toc_page))[0]

        # detect page titles
        self.titles = []
        for ln in sorted(self.cliargs.toc_languages):
            if ln == lang.tag_for_langname(lang.get_local_language()):
                self.titles.append(self.cliargs.toc_page)
            else:
                self.titles.append("{} ({})".format(self.cliargs.toc_page, lang.langname_for_tag(ln)))