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


Python pywikibot.output方法代碼示例

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


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

示例1: setClaim

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def setClaim (item, claim_id, claim_target, source_id, source_target, prompt=False) :
    claim = pb.Claim(repo, claim_id)
    target = pb.ItemPage(repo, claim_target)
    claim.setTarget(target)
    pb.output('Adding %s --> %s' % (claim.getID(), claim.getTarget()))
    try :
        item.addClaim(claim)
    except Exception as e:
        raise e

    if source_id is not None and source_target is not None :
        source_claim = pb.Claim(repo, source)
        source_claim.setTarget(pb.ItemPage(repo, source_target))
        try :
            claim.addSource(source_claim)
        except Exception as e:
            raise e
    if prompt :
        prompt = '>'
        raw_input(prompt)

    return True 
開發者ID:wmes,項目名稱:WikiLoves,代碼行數:24,代碼來源:WLF_wikidata_update.py

示例2: delete

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def delete(filepage, msg):
    for i in range(8):
        filepage._file_revisions.clear()
        filepage.clear_cache()

        try:
            hist = filepage.get_file_history()
        except Exception:
            hist = None

        if not filepage.exists() and not hist:
            break
        else:
            if i:
                pywikibot.warning(
                    'File exist still before deletion on attempt %d' % i)
            pywikibot.output('Executing delete on %s' % filepage)

            retry_apierror(
                lambda:
                filepage.delete(MESSAGE_PREFIX+msg, prompt=False)
            )
    else:
        pywikibot.warning('FIXME: Deletion attempt exhausted') 
開發者ID:toolforge,項目名稱:embeddeddata,代碼行數:26,代碼來源:worker.py

示例3: run_watcher

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def run_watcher():
    site = pywikibot.Site(user="Embedded Data Bot")
    redis = Redis(host="tools-redis")

    signal.signal(signal.SIGALRM, on_timeout)
    signal.alarm(TIMEOUT)

    rc = site_rc_listener(site)
    for change in rc:
        signal.alarm(TIMEOUT)

        if (
            change['type'] == 'log' and
            change['namespace'] == 6 and
            change['log_type'] == 'upload'
        ):
            redis.rpush(REDIS_KEY, json.dumps(change))

    pywikibot.output("Exit - THIS SHOULD NOT HAPPEN") 
開發者ID:toolforge,項目名稱:embeddeddata,代碼行數:21,代碼來源:rcwatcher.py

示例4: getPhoto

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def getPhoto(flickr, photo_id):
    """
    Get the photo info and the photo sizes so we can use these later on.

    TODO: Add exception handling

    """
    while True:
        try:
            photoInfo = flickr.photos_getInfo(photo_id=photo_id)
            # xml.etree.ElementTree.dump(photoInfo)
            photoSizes = flickr.photos_getSizes(photo_id=photo_id)
            # xml.etree.ElementTree.dump(photoSizes)
            return photoInfo, photoSizes
        except flickrapi.exceptions.FlickrError:
            pywikibot.output(u'Flickr api problem, sleeping')
            time.sleep(30) 
開發者ID:multichill,項目名稱:toollabs,代碼行數:19,代碼來源:flickrripper_wlm2017.py

示例5: WikidataQueryItemPageGenerator

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def WikidataQueryItemPageGenerator(query, site=None):
    """Generate pages that result from the given WikidataQuery.

    @param query: the WikidataQuery query string.

    """
    if site is None:
        site = pywikibot.Site()
    repo = site.data_repository()

    wd_queryset = wdquery.QuerySet(query)

    wd_query = wdquery.WikidataQuery(cacheMaxAge=0)
    data = wd_query.query(wd_queryset)

    pywikibot.output(u'retrieved %d items' % data[u'status'][u'items'])
    for item in data[u'items']:
        yield pywikibot.ItemPage(repo, u'Q' + unicode(item)) 
開發者ID:multichill,項目名稱:toollabs,代碼行數:20,代碼來源:280_reports.py

示例6: WikidataQueryPageGenerator

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def WikidataQueryPageGenerator(query, site=None):
    """Generate pages that result from the given WikidataQuery.

    @param query: the WikidataQuery query string.
    @param site: Site for generator results.
    @type site: L{pywikibot.site.BaseSite}

    """
    if site is None:
        site = pywikibot.Site()
    repo = site.data_repository()

    wd_queryset = wdquery.QuerySet(query)

    wd_query = wdquery.WikidataQuery(cacheMaxAge=0)
    data = wd_query.query(wd_queryset)

    pywikibot.output(u'retrieved %d items' % data[u'status'][u'items'])
    for item in data[u'items']:
        itempage = pywikibot.ItemPage(repo, u'Q' + unicode(item))
        yield itempage 
開發者ID:multichill,項目名稱:toollabs,代碼行數:23,代碼來源:rijksmuseum_schilders.py

示例7: getArtistsGenerator

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def getArtistsGenerator(self):
        '''
        Generate a bunch of artists from RKD.
        '''
        limit = 2
        #baseurl = u'https://api.rkd.nl/api/search/artists?filters[kwalificatie]=painter&fieldset=detail&format=json&rows=%s&start=%s'
        baseurl = u'https://api.rkd.nl/api/search/artists?fieldset=detail&format=json&rows=%s&start=%s'


        for i in range(60000, 361707, limit):

            url = baseurl % (limit, i)
            #print url
            rkdartistsApiPage = requests.get(url, verify=False)
            rkdartistsApiPageJson = rkdartistsApiPage.json()
            #print rkdartistsApiPageJson
            if rkdartistsApiPageJson.get('content') and rkdartistsApiPageJson.get('content').get('message'):
                pywikibot.output(u'Something went wrong')
                continue

            for rkdartistsdocs in rkdartistsApiPageJson.get('response').get('docs'):
                yield rkdartistsdocs 
開發者ID:multichill,項目名稱:toollabs,代碼行數:24,代碼來源:aagartists_importer.py

示例8: filterArtists

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def filterArtists(self, generator):
        """
        Starts the robot.
        """
        for rkdartistsdocs in generator:
            if rkdartistsdocs.get('priref') in self.currentrkd:
                pywikibot.output(u'Already got %s on %s' % (rkdartistsdocs.get('priref'),
                                                            self.currentrkd.get(rkdartistsdocs.get('priref'))))
                continue
            if rkdartistsdocs.get(u'results_in_other_databases') and \
                rkdartistsdocs.get(u'results_in_other_databases').get(u'images_kunstenaar'):
                number = rkdartistsdocs.get(u'results_in_other_databases').get(u'images_kunstenaar').get('count')
                if number > 0:
                    print rkdartistsdocs.get('kwalificatie')
                    if u'schilder' in rkdartistsdocs.get('kwalificatie'):
                        yield rkdartistsdocs 
開發者ID:multichill,項目名稱:toollabs,代碼行數:18,代碼來源:aagartists_importer.py

示例9: main

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def main():
    lookuptable = makeLookupTable()
    #print lookuptable
    site = pywikibot.Site()
    repo = site.data_repository()
    query = u'SELECT ?item WHERE { ?item wdt:P359 [] . MINUS {?item wdt:P31 []} }'
    itemGen = pagegenerators.PreloadingItemGenerator(pagegenerators.WikidataSPARQLPageGenerator(query, site=repo))

    for item in itemGen:
        pywikibot.output(item.title())
        data = item.get()
        claims = data.get('claims')
        if u'P359' in claims:
            rijksid = claims.get(u'P359')[0].getTarget()
            if u'P31' not in claims:
                if rijksid in lookuptable:
                    summary = u'Adding instance of %s based on %s' % (lookuptable[rijksid], rijksid)
                    typeItem = pywikibot.ItemPage(repo, title=lookuptable[rijksid])

                    newclaim = pywikibot.Claim(repo, u'P31')
                    newclaim.setTarget(typeItem)
                    pywikibot.output('Adding instance claim to %s' % item)
                    item.addClaim(newclaim, summary=summary) 
開發者ID:multichill,項目名稱:toollabs,代碼行數:25,代碼來源:rijksmonumenten_fix.py

示例10: fillCache

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def fillCache(self, propertyId, cacheMaxAge=0):
        '''
        Query Wikidata to fill the cache of monuments we already have an object for
        '''
        result = {}
        
        query = u'CLAIM[%s]' % (propertyId,)
        wd_queryset = wdquery.QuerySet(query)

        wd_query = wdquery.WikidataQuery(cacheMaxAge=cacheMaxAge)
        data = wd_query.query(wd_queryset, props=[str(propertyId),])

        if data.get('status').get('error')=='OK':
            expectedItems = data.get('status').get('items')
            props = data.get('props').get(str(propertyId))
            for prop in props:
                # FIXME: This will overwrite id's that are used more than once.
                # Use with care and clean up your dataset first
                result[prop[2]] = prop[0]

            if expectedItems==len(result):
                pywikibot.output('I now have %s items in cache' % expectedItems)

        return result 
開發者ID:multichill,項目名稱:toollabs,代碼行數:26,代碼來源:rijksmonumenten_import.py

示例11: getVIAF

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def getVIAF(self, cacheMaxAge=0):
        '''
        Query Wikidata to fill the cache of monuments we already have an object for
        '''
        result = {}
        query = u'CLAIM[214]'
        
        wd_queryset = wdquery.QuerySet(query)

        wd_query = wdquery.WikidataQuery(cacheMaxAge=cacheMaxAge)
        data = wd_query.query(wd_queryset, props=[str(214),])

        if data.get('status').get('error')=='OK':
            expectedItems = data.get('status').get('items')
            props = data.get('props').get(str(214))
            for prop in props:
                # FIXME: This will overwrite id's that are used more than once.
                # Use with care and clean up your dataset first
                result[prop[2]] = u'Q%s' % (prop[0],)

            pywikibot.output('I expected %s items and now have %s items with VIAF in cache' % (expectedItems, len(result)))

        return result 
開發者ID:multichill,項目名稱:toollabs,代碼行數:25,代碼來源:groeninge_artists.py

示例12: addItemStatement

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def addItemStatement(self, item, pid, qid, url):
        '''
        Helper function to add a statement
        '''
        if not qid:
            return False

        claims = item.get().get('claims')
        if pid in claims:
            return
        
        newclaim = pywikibot.Claim(self.repo, pid)
        destitem = pywikibot.ItemPage(self.repo, qid)
        newclaim.setTarget(destitem)
        pywikibot.output(u'Adding %s->%s to %s' % (pid, qid, item))
        item.addClaim(newclaim)
        self.addReference(item, newclaim, url) 
開發者ID:multichill,項目名稱:toollabs,代碼行數:19,代碼來源:amsterdam_museum_fix.py

示例13: getCreatorItem

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def getCreatorItem(self, creator):
        '''
        '''
        try:
            site=pywikibot.Site('commons', 'commons')
            creatorPage = pywikibot.Page(site, title=creator, ns=100)

            if creatorPage.exists():
                if creatorPage.isRedirectPage():
                    creatorPage = creatorPage.getRedirectTarget()
                pywikibot.output(u'Got a creator page %s' % (creatorPage.title(),))
            
                regex = u'\|\s*[wW]ikidata\s*=\s*(Q\d+)\s*'
                match = re.search(regex, creatorPage.get())
                if match:
                    creatorItem = pywikibot.ItemPage(self.repo, title=match.group(1))
                    return creatorItem
        except pywikibot.exceptions.InvalidTitle:
            pywikibot.output(u'Found an invalid title')
            pass
        return None 
開發者ID:multichill,項目名稱:toollabs,代碼行數:23,代碼來源:walters_import.py

示例14: addItemStatement

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def addItemStatement(self, item, pid, qid):
        '''
        Helper function to add a statement
        '''
        if not qid:
            return False

        claims = item.get().get('claims')
        if pid in claims:
            return

        newclaim = pywikibot.Claim(self.repo, pid)
        destitem = pywikibot.ItemPage(self.repo, qid)
        newclaim.setTarget(destitem)
        pywikibot.output(u'Adding %s->%s to %s' % (pid, qid, item))
        item.addClaim(newclaim)
        return newclaim
        #self.addReference(item, newclaim, url) 
開發者ID:multichill,項目名稱:toollabs,代碼行數:20,代碼來源:biografisch_to_pp.py

示例15: treat

# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import output [as 別名]
def treat(self, item, collection, pattern, replacement):

        data = item.get()
        claims = data.get('claims')

        summary = u'Normaliz'

        for invnumberclaim in claims.get(u'P217'):
            if invnumberclaim.has_qualifier(u'P195', self.collectionitem):
                invnumber = invnumberclaim.getTarget()
                newinvnumber = re.sub(pattern, replacement, invnumber)
                if newinvnumber != invnumber:
                    summary = u'Normalization of inventory numbers in [[%s]] from "%s" to "%s"' % (collection.title(),
                                                                                               invnumber,
                                                                                               newinvnumber)
                    pywikibot.output(summary)
                    invnumberclaim.changeTarget(newinvnumber, summary=summary) 
開發者ID:multichill,項目名稱:toollabs,代碼行數:19,代碼來源:inventory_number_normalization.py


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