当前位置: 首页>>代码示例>>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;未经允许,请勿转载。