本文整理匯總了Python中pywikibot.ItemPage方法的典型用法代碼示例。如果您正苦於以下問題:Python pywikibot.ItemPage方法的具體用法?Python pywikibot.ItemPage怎麽用?Python pywikibot.ItemPage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pywikibot
的用法示例。
在下文中一共展示了pywikibot.ItemPage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setClaim
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [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
示例2: create_references
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [as 別名]
def create_references(claim, references):
try:
source_claim_list = []
for k, v in references.items():
source_claim = pywikibot.Claim(repo, k, isReference=True)
trgt_item = None
if v[0] == 'id':
trgt_item = pywikibot.ItemPage(repo, v[1])
elif v[0] == 'url':
trgt_item = v[1]
source_claim.setTarget(trgt_item)
source_claim_list.append(source_claim)
claim.addSources(source_claim_list)
logging.info('{} References added to claim'.format(len(source_claim_list)))
return True
except:
return False
示例3: WikidataQueryItemPageGenerator
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [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))
示例4: WikidataQueryPageGenerator
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [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
示例5: __init__
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [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')
示例6: addItemStatement
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [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)
示例7: main
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [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)
示例8: addItemStatement
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [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)
示例9: getCreatorItem
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [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
示例10: __init__
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [as 別名]
def __init__(self, dictGenerator, create=False):
"""
Arguments:
* generator - A generator that yields Dict objects.
The dict in this generator needs to contain 'idpid' and 'collectionqid'
* create - Boolean to say if you want to create new items or just update existing
"""
firstrecord = next(dictGenerator)
self.generator = itertools.chain([firstrecord], dictGenerator)
self.repo = pywikibot.Site().data_repository()
self.create = create
self.idProperty = firstrecord.get(u'idpid')
self.collectionqid = firstrecord.get(u'collectionqid')
self.collectionitem = pywikibot.ItemPage(self.repo, self.collectionqid)
self.artworkIds = self.fillCache(self.collectionqid,self.idProperty)
示例11: addItemStatement
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [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)
if destitem.isRedirectPage():
destitem = destitem.getRedirectTarget()
newclaim.setTarget(destitem)
pywikibot.output(u'Adding %s->%s to %s' % (pid, qid, item))
item.addClaim(newclaim)
self.addReference(item, newclaim, url)
示例12: __init__
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [as 別名]
def __init__(self, generator):
"""
Arguments:
* generator - A generator that yields Dict objects.
"""
self.repo = pywikibot.Site().data_repository()
self.generator = generator
self.progressPage = pywikibot.Page(self.repo, title=u'User:Multichill/SMAK creators')
#self.progressPage.get()
self.rkditems = self.getRKD()
#print self.rkditems
self.viafitems = self.getVIAF()
self.museumitem = pywikibot.ItemPage(self.repo, title=u'Q1540707')
示例13: wikidataCategoryGenerator
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [as 別名]
def wikidataCategoryGenerator(repo, qid, project):
'''
Generator that takes a category item
'''
categoryitem = pywikibot.ItemPage(repo, title=qid)
for categorypage in categoryitem.iterlinks(family=project):
gennostatements = petscanGenerator(repo,
categorypage.site.lang,
u'wikipedia',
8,
categorypage.title(withNamespace=False),
typequery='nostatements')
for item in gennostatements:
yield item
genwithoutitem = petscanGenerator(repo,
categorypage.site.lang,
u'wikipedia',
8,
categorypage.title(withNamespace=False),
typequery='withoutitem')
for item in genwithoutitem:
yield item
示例14: addCollection
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [as 別名]
def addCollection(repo, item, metadata):
collections = { u'Private collection' : u'Q768717',
u'Otterlo, Kröller-Müller Museum' : u'Q1051928',
u'The Hague, Haags Gemeentemuseum' : u'Q1499958',
u'Den Bosch, Noordbrabants Museum' : u'Q12013217',
}
data = item.get()
claims = data.get('claims')
collection = metadata.get(u'collection')
if u'P195'not in claims:
if collection in collections:
collectionitem = pywikibot.ItemPage(repo, title=collections.get(collection))
newclaim = pywikibot.Claim(repo, u'P195')
newclaim.setTarget(collectionitem)
item.addClaim(newclaim)
addReference(repo, item, newclaim, metadata.get(u'url'))
elif collection not in collections:
print u'Did not find the collection %s for %s' % (collection, item.title(), )
示例15: addRkdimagesLink
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import ItemPage [as 別名]
def addRkdimagesLink(itemTitle, rkdid, summary):
repo = pywikibot.Site().data_repository()
item = pywikibot.ItemPage(repo, title=itemTitle)
if not item.exists():
return False
if item.isRedirectPage():
return False
data = item.get()
claims = data.get('claims')
if u'P350' in claims:
claim = claims.get('P350')[0]
if claim.getTarget()==u'%s' % (rkdid,):
pywikibot.output(u'Already got the right link on %s to rkdid %s!' % (itemTitle, rkdid))
return True
pywikibot.output(u'Already got a link to %s on %s, I\'m trying to add %s' % (claim.getTarget(),
itemTitle,
rkdid))
return False
newclaim = pywikibot.Claim(repo, u'P350')
newclaim.setTarget(u'%s' % (rkdid,))
pywikibot.output(summary)
item.addClaim(newclaim, summary=summary)
return True