當前位置: 首頁>>代碼示例>>Python>>正文


Python pywikibot.Category方法代碼示例

本文整理匯總了Python中pywikibot.Category方法的典型用法代碼示例。如果您正苦於以下問題:Python pywikibot.Category方法的具體用法?Python pywikibot.Category怎麽用?Python pywikibot.Category使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pywikibot的用法示例。


在下文中一共展示了pywikibot.Category方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def __init__(self, cattitle, collectionqid):
        """
        Arguments:
            * cattitle    - Title of the category to look for images.
            * collectionqid       - The Q number id of the collection

        """
        #firstrecord  = dictGenerator.next()
        #self.generator = itertools.chain([firstrecord], dictGenerator)
        self.repo = pywikibot.Site().data_repository()
        self.site = pywikibot.Site(u'commons', u'commons')
        self.category = pywikibot.Category(self.site, title=cattitle)
        self.generator = pagegenerators.FileGenerator(pagegenerators.PreloadingGenerator(self.category.articles(namespaces=6)))
        #self.create = create
        
        #self.idProperty = firstrecord.get(u'idpid')
        self.collectionqid = collectionqid
        #self.collectionitem = pywikibot.ItemPage(self.repo, self.collectionqid)
        self.artworkIds = self.fillCache(self.collectionqid, u'217') 
開發者ID:multichill,項目名稱:toollabs,代碼行數:21,代碼來源:add_google_images.py

示例2: getBoundedCat

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def getBoundedCat(self, cat, currMinSize):
        print
        print "getBoundedCat"
        site = Site("en")
        try:
            catObj = Category(site, title=cat)
        except:
            catObj = Category(site, title=cat.decode("utf-8"))
        
        subCats = self.recursiveCats(catObj) 
        
        articleSet = set()
        
        for subCat in subCats:
            print "inside subCat", subCat
            newArts = set(self.getArticles(subCat, recurse=False))
            articleSet.update(newArts)
            print len(articleSet)
            if len(articleSet) > currMinSize:
                print "break"
                return currMinSize
                #continue

        return len(articleSet) 
開發者ID:DMTsurel,項目名稱:FunFacts,代碼行數:26,代碼來源:WikiManager.py

示例3: main

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def main():
    """Main script function."""
    processors = []
    date = get_dump_date()
    dump = xmlreader.XmlDump(FILENAME.format(date=date))
    site = pywikibot.Site()
    category = pywikibot.Category(site, CATEGORY)
    for page in category.members():
        processor = Processor(page, date)
        if processor.correct:
            processors.append(processor)
            if len(processors) > 100:
                break
    if len(processors) == 0:
        return
    for entry in dump.parse():
        for processor in processors:
            processor.process(entry)
    for processor in processors:
        processor.save_result() 
開發者ID:Facenapalm,項目名稱:NapalmBot,代碼行數:22,代碼來源:autodumpscan.py

示例4: main

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def main():
    """Main script function."""
    site = pywikibot.Site()
    category = pywikibot.Category(site, CATEGORY)
    refs = [page.title() for page in category.articles(namespaces=[0])]
    template = pywikibot.Page(site, TEMPLATE)
    references = set([page.title() for page in template.embeddedin(namespaces=[0])])
    pages = [pywikibot.Page(site, page) for page in refs if not page in references]
    # converting to titles and back is needed for saving memory
    for page in pages:
        (text, ignored) = checkwiki.ignore(page.text)
        (text, flag) = checkwiki.insert_references(text)
        text = checkwiki.deignore(text, ignored)
        if flag:
            (text, fixes) = checkwiki.process_text(text)
            page.text = text
            page.save(COMMENT)
            checkwiki.mark_error_list_done(fixes, page.title()) 
開發者ID:Facenapalm,項目名稱:NapalmBot,代碼行數:20,代碼來源:wikidatarefs.py

示例5: main

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def main():
    """Main script function."""
    site = pywikibot.Site()

    category = pywikibot.Category(site, CATEGORY_NAME)
    pages = list(category.articles())
    pages = ["[[" + page.title() + "]]" for page in pages]

    random.shuffle(pages)

    text = ", ".join(pages[:LIST_LEN])
    text = TEXT_BEFORE + text + TEXT_AFTER

    template = pywikibot.Page(site, TEMPLATE_NAME)
    noinclude = re.search(r"<noinclude>(?:[^<]|<(?!noinclude)?)+</noinclude>$", template.text)
    if noinclude:
        template.text = text + noinclude.group(0)
    else:
        template.text = text
    template.save(COMMENT, minor=False) 
開發者ID:Facenapalm,項目名稱:NapalmBot,代碼行數:22,代碼來源:afi.py

示例6: get_all_church_cats

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def get_all_church_cats():
    """Extract all church categories, per municipality."""
    site = pwb.Site('commons', 'commons')
    top_cat = pwb.Category(site, 'Category:Churches in Sweden by municipality')
    church_cats_per_muni = {}
    for sub_cat in top_cat.subcategories():
        # municipal level
        sub_cat_name = sub_cat.title(withNamespace=False)
        if not sub_cat_name.startswith('Churches in '):
            raise pwb.Error(
                'Basic assumption failed: "{}" does not start with '
                '"Churches in"'.format(sub_cat_name))
        sub_cat_name_end = sub_cat_name[len('Churches in '):]
        muni_name = sub_cat_name_end.partition(',')[0]
        church_dict = {}
        loop_over_candidates(sub_cat, church_dict, sub_cat_name_end, depth=0)
        church_cats_per_muni[muni_name] = church_dict
        pwb.output('{} done found {}'.format(muni_name, len(church_dict)))
    return church_cats_per_muni 
開發者ID:lokal-profil,項目名稱:KMB-import,代碼行數:21,代碼來源:load_church_cats.py

示例7: apply

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def apply(self, page, *args):
        # remove empty list items
        page.text = re.sub(r'^\* *\n', '', page.text, flags=re.M)

        # sort categories
        categories = textlib.getCategoryLinks(page.text, site=page.site)
        category_living = pywikibot.Category(page.site, 'Žijící lidé')
        if category_living in categories:
            if any(cat.title(withNamespace=False).startswith('Úmrtí ')
                   for cat in categories):
                categories.remove(category_living)
                page.text = textlib.replaceCategoryLinks(
                    page.text, categories, page.site)

        page.text = re.sub(
            r'(\{\{ *(?:%s)[^}]+\}\}\n)\n(\[\[(?:%s))' % (
                '|'.join(map(re.escape, self.site.getmagicwords('defaultsort'))),
                '|'.join(self.site.namespaces[14])),
            r'\1\2', page.text) 
開發者ID:matejsuchanek,項目名稱:pywikibot-scripts,代碼行數:21,代碼來源:custome_fixes.py

示例8: clean_page

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def clean_page (page_wikitext, wikidata_id) :
    out = re.sub("(\[\[\s*[a-zA-Z]{2,3}\s*:.*?\]\]\s*\n)", '', page_wikitext)
    out = re.sub("(\[\[\s*[a-zA-Z]{2,3}\s*:.*?\]\]\s*)", '', out)
    out = re.sub("(\n{3,})", '\n\n', out)
    #out = out.replace('\n\n\n\n', '\n\n')
    #out = out.replace('\n\n\n', '\n\n')

    interwikis = u''

    wikidata_site = pb.Site("wikidata", "wikidata")
    repo = wikidata_site.data_repository()
    item = pb.ItemPage(repo, title=wikidata_id)
    try :
        item.get()
    except :
        pb.output('Processing --> Information from item not retrieved: ' + wikidata_id)
        return out

    commons_cat = list()
    if COMMONS_CAT_PROPERTY in item.claims :
        for claim in item.claims[COMMONS_CAT_PROPERTY]:
            commons_cat.append(claim.getTarget().title().lower().strip())
    if u"commonswiki" in item.sitelinks and len(item.sitelinks[u"commonswiki"]) > 0 :
        commonswiki_cat = item.sitelinks[u"commonswiki"].replace(u'Category:', '').lower().strip()
    else :
        commonswiki_cat = None

    if commonswiki_cat in commons_cat :
        pass
    elif len(item.sitelinks) > 0 :
        for sitelink in item.sitelinks :
            if sitelink != u'commonswiki' :
                interwikis += u'[[%s:%s]]\n' %(sitelink[:-4], item.sitelinks[sitelink])
        out += u'\n'+interwikis

    return out 
開發者ID:wmes,項目名稱:WikiLoves,代碼行數:38,代碼來源:WLF_commons_update.py

示例9: main

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def main():
    #dictGen = getDulwichGenerator()

    #for painting in dictGen:
    #   print painting

    imageFindBot = ImageFindBot(u'Category:Google_Art_Project_works_in_Dulwich_Picture_Gallery', u'Q1241163')
    imageFindBot.run() 
開發者ID:multichill,項目名稱:toollabs,代碼行數:10,代碼來源:dulwich_google_images.py

示例10: __init__

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def __init__(self):
        print "init WikiManager"
        self.reverseStemHashtable = {}
        self.yearRegex = re.compile("Category:\\d{4}.*")
        #self.p = stemmer.PorterStemmer()
        self.printMode = False
        cnt = cpu_count()
        self.cpuCount = 3 if cnt==4 else 8
        self.historicCats = {} 
開發者ID:DMTsurel,項目名稱:FunFacts,代碼行數:11,代碼來源:WikiManager.py

示例11: filterCategories

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def filterCategories(self, cats):
        
        cats = [cat for cat in cats if (not self.yearRegex.match(cat) 
                                        and not cat.startswith(("Category:Wikipedia", "Category:Living people")) )]
        return cats 
開發者ID:DMTsurel,項目名稱:FunFacts,代碼行數:7,代碼來源:WikiManager.py

示例12: hidden

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def hidden(category):
    return "Category:Hidden categories" in [c.title() for c in category.categories()] 
開發者ID:Commonists,項目名稱:Commons2Data,代碼行數:4,代碼來源:categorisation.py

示例13: print_category

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def print_category(item, title, addList):
    if title is not "":
        result = ""
        if item is not "":
            result = "<onlyinclude>\n{{User:Rama/Catdef|"+item+"}}\n</onlyinclude>"
        category = pywikibot.Category(commons, title)
        for add in addList:
            result = result+"\n[["+add+"]]"
        category.text = result
        category.save("#FileToCat Category creation") 
開發者ID:Commonists,項目名稱:Commons2Data,代碼行數:12,代碼來源:categorisation.py

示例14: clean_image

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def clean_image(image, title, removeList):
    t = image.text
    for r in removeList:
        t = t.replace("[["+r+"]]","")
    t = t+"\n[[Category:"+title+"]]"
    image.text = t
    image.save("#FileToCat Image in its own category") 
開發者ID:Commonists,項目名稱:Commons2Data,代碼行數:9,代碼來源:categorisation.py

示例15: create_request_list

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Category [as 別名]
def create_request_list(site, project_name, category_name, threshold, target_page):
    '''
    Scans the category and creates the requested links page
    project_name is purely to decide what page to put the list on
    '''
    cat = pywikibot.Category(site, category_name)
    gen = pagegenerators.CategorizedPageGenerator(cat)
    redlinks = {}
    for i, page in enumerate(gen):
        if page.title()[:5] == 'Talk:':
            page = pywikibot.Page(site, page.title()[5:])
        print(page.title())
        if config.max_catalog_pages is not None:
            if i > config.max_catalog_pages:
                break

        linkgen = page.linkedPages()
        for link in linkgen:
            if not link.exists():
                # if configured to only include articles, and link is to
                # a namespace other than an article, it does not add it to the list
                if config.article_namespace_only and link.namespace() != 0:
                    continue

                if link.title() in redlinks:
                    redlinks[link.title()] = redlinks[link.title()] + 1
                else:
                    redlinks[link.title()] = 1
    if config.actually_edit:
        write_listed_links(site, redlinks, target_page, project_name, threshold)
    else:
        print(redlinks) 
開發者ID:utilitarianexe,項目名稱:most_requested_wiki_articles_bot,代碼行數:34,代碼來源:requestedpages.py


注:本文中的pywikibot.Category方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。