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


Python pywikibot.FilePage方法代碼示例

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


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

示例1: make_image_item

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import FilePage [as 別名]
def make_image_item(self, filename):
        commonssite = utils.create_site_instance("commons", "commons")
        imagelink = pywikibot.Link(
            filename, source=commonssite, defaultNamespace=6)
        return pywikibot.FilePage(imagelink) 
開發者ID:Vesihiisi,項目名稱:COH-tools,代碼行數:7,代碼來源:Uploader.py

示例2: addMissingCommonsWikidataLink

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import FilePage [as 別名]
def addMissingCommonsWikidataLink(self, filename, wikidataitem):
        """
        Try to add a missing link to Commons. Returns True if it worked and False if it failed
        """
        filepage = pywikibot.FilePage(self.commons, title=filename)

        text = filepage.get()
        replaceregex = u'\{\{(Artwork|Painting|Art Photo|Google Art Project|Google Cultural Institute|Walters Art Museum artwork|NARA-image-full)'
        emptywikidataregex = u'(\s*\|\s*wikidata\s*=)\s*\n'
        wikidataregex = u'[wW]ikidata\s*=\s*(Q\d+)\s*'

        pywikibot.output(u'Working on %s' % (filepage.title(),))

        wdmatch = re.search(wikidataregex, text)

        if wdmatch:
            # Template with duplicate template problems might hit this one or when database query is a bit stale
            pywikibot.output(u'Seems to already link to Wikidata %s' % (wdmatch.group(1),))
            return False

        # First try to update an existing field
        newtext = re.sub(emptywikidataregex, u'\\1%s\n' % (wikidataitem,), text, count=1)

        if text==newtext:
            #Ok, that didn't work, just slap it at the top
            newtext = re.sub(replaceregex, u'{{\\1\n|wikidata=%s' % (wikidataitem,), text, count=1, flags=re.I)
            if text==newtext:
                pywikibot.output(u'Unable to add Wikidata link to %s' % (filename,))
                return False

        pywikibot.showDiff(text, newtext)
        summary = u'Adding link to [[:d:%s]] based on usage on that item' % (wikidataitem,)
        pywikibot.output(summary)
        filepage.put(newtext, summary=summary)
        return True 
開發者ID:multichill,項目名稱:toollabs,代碼行數:37,代碼來源:find_painting_images.py

示例3: make_summary

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import FilePage [as 別名]
def make_summary(self, prop, value):
        if isinstance(value, pywikibot.ItemPage):
            value = value.title(insite=self.repo, asLink=True)
        elif isinstance(value, pywikibot.FilePage):
            value = '[[%s|%s]]' % (value.title(insite=self.repo),
                                   value.title(withNamespace=False))
        elif isinstance(value, pywikibot.PropertyPage):
            value = '[[%s|%s]]' % (value.title(), value.getID())
        rev_id = self.current_talk_page.latest_revision_id
        return ('Importing "[[Property:%s]]: %s" from '
                '[[Special:PermaLink/%s|talk page]]' % (prop, value, rev_id)) 
開發者ID:matejsuchanek,項目名稱:pywikibot-scripts,代碼行數:13,代碼來源:metabot.py

示例4: fusion_cat

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import FilePage [as 別名]
def fusion_cat(tempCat,qitem=""):
    categories=[]
    img = None
    item = None
    page = pywikibot.Category(commons, tempCat)
    for image in page.members(namespaces=FILE_NAMESPACE):
        img = image.title()[5:]
        for cat in image.categories():
            if cat.title() not in blackList and not hidden(cat):
                categories.append(cat.title())
                blackList.append(cat.title())
    if qitem is not "":
        item = pywikibot.ItemPage(repo,qitem)
    else:
        item = pywikibot.ItemPage(wikidata)
        item.editLabels(label_dict, summary="#Commons2Data label")
        item.editDescriptions(descr_dict, summary="#Commons2Data description")
        item.get()
        for cat in categories:
            if cat in cache:
                for p in cache[cat]["Properties"]:
                    if p not in item.claims or p in duplicates:
                        claim = pywikibot.Claim(repo, p)
                        if "Q" in cache[cat]["Properties"][p]["Value"]:
                            claim.setTarget(pywikibot.ItemPage(repo,cache[cat]["Properties"][p]["Value"]))
                        else:
                            claim.setTarget(pywikibot.WbTime(year=cache[cat]["Properties"][p]["Value"]["Year"]))
                        item.addClaim(claim, summary=u'#Commons2Data adding claim')
            else:
                print (cat)
    title = label(item)
    print_category(item.title(), title, categories)
    categories.append("Category:"+tempCat)
    for image in page.members(namespaces=FILE_NAMESPACE):
        clean_image(image, title, categories)
    # Wikidata
    if imageProperty not in item.claims:
        claim = pywikibot.Claim(repo, imageProperty)
        claim.setTarget(pywikibot.FilePage(commons,img))
        item.addClaim(claim, summary=u"Commons2Data image")
    category = pywikibot.Category(commons, title)
    item.setSitelink(category, summary="#FileToCat Commons sitelink.")
    claim = pywikibot.Claim(repo, commonsCat)
    claim.setTarget(title)
    item.addClaim(claim, summary="#FileToCat Commons claim") 
開發者ID:Commonists,項目名稱:Commons2Data,代碼行數:47,代碼來源:categorisation.py


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