本文整理匯總了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')
示例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)
示例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()
示例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())
示例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)
示例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
示例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)
示例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
示例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()
示例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 = {}
示例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
示例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()]
示例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")
示例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")
示例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)