本文整理汇总了Python中pywikibot.Site方法的典型用法代码示例。如果您正苦于以下问题:Python pywikibot.Site方法的具体用法?Python pywikibot.Site怎么用?Python pywikibot.Site使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywikibot
的用法示例。
在下文中一共展示了pywikibot.Site方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_watcher
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [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")
示例2: findDuplicateImages
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [as 别名]
def findDuplicateImages(photo, site=None):
"""Find duplicate images.
Take the photo, calculate the SHA1 hash and ask the MediaWiki api
for a list of duplicates.
TODO: Add exception handling.
@param photo: Photo
@type photo: io.BytesIO
@param site: Site to search for duplicates.
Defaults to using Wikimedia Commons if not supplied.
@type site: APISite or None
"""
if not site:
site = pywikibot.Site('commons', 'commons')
hashObject = hashlib.sha1()
hashObject.update(photo.getvalue())
return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
示例3: main
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [as 别名]
def main():
"""
Do a query for items that do have RKDartists (P650) and VIAF (P214), but no ULAN (P245)
:return:
"""
query = u"""SELECT ?item WHERE {
?item wdt:P650 [] .
?item wdt:P214 [] .
MINUS { ?item wdt:P245 [] }
}"""
repo = pywikibot.Site().data_repository()
generator = pagegenerators.PreloadingItemGenerator(pagegenerators.WikidataSPARQLPageGenerator(query, site=repo))
viafImportBot = ViafImportBot(generator)
viafImportBot.run()
示例4: __init__
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [as 别名]
def __init__(self, dictGenerator):
"""
Arguments:
* generator - A generator that yields Dict objects.
"""
self.generator = dictGenerator
self.repo = pywikibot.Site().data_repository()
self.progressPage = pywikibot.Page(self.repo, title=u'User:Multichill/Rijksmuseum creators')
self.progressPage.get()
self.creators = self.fillCache()
self.missingCreators = self.getMissingCreators()
#self.paintingIdProperty = paintingIdProperty
#self.paintingIds = self.fillCache(self.paintingIdProperty)
示例5: WikidataQueryPageGenerator
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [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
示例6: __init__
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [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')
示例7: main
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [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: __init__
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [as 别名]
def __init__(self, dictGenerator, monumentIdProperty):
"""
Arguments:
* generator - A generator that yields Dict objects.
* monumentId - The property that's used to identify a monument
"""
self.generator = dictGenerator
self.repo = pywikibot.Site().data_repository()
self.monumentIdProperty = monumentIdProperty
self.monumentType = u'Q916333'
self.monumentIds = self.fillCache(self.monumentIdProperty)
self.iso3166_1Property = '297'
self.iso3166_1Codes = self.fillCache(self.iso3166_1Property, cacheMaxAge=30)
self.iso3166_2Property = '300'
self.iso3166_2Codes = self.fillCache(self.iso3166_2Property, cacheMaxAge=30)
示例9: __init__
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [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/Groeningemuseum creators')
#self.progressPage.get()
self.rkditems = self.getRKD()
#print self.rkditems
self.viafitems = self.getVIAF()
self.museumitem = pywikibot.ItemPage(self.repo, title=u'Q1948674')
示例10: getCreatorItem
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [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
示例11: makeRijksReport
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [as 别名]
def makeRijksReport(rijksworks):
text = u'List of %s Rijksmuseum paintings to match. Find the right painting, add the inventory number qualified with {{Q|18600731}} \n\n' % (len(rijksworks),)
text = text + u'{| class="wikitable"\n! Title !! Creator !! Search !! Inventory number !! Source\n'
for work in rijksworks:
text = text + u'|-\n | %s || %s || [//www.wikidata.org/w/index.php?search=&search={{urlencode:%s %s}}] || %s || [%s]\n' % (work.get('title').get(u'nl'),
work.get('creatorname'),
work.get('title').get(u'nl'),
work.get('creatorname'),
work.get('id'),
work.get('url'),
)
text = text + u'|}\n\n[[Category:User:Multichill]]\n'
repo = pywikibot.Site().data_repository()
summary = u'Update Rijksmuseum report with %s paintings' % (len(rijksworks),)
pageTitle = u'User:Multichill/Zandbak'
page = pywikibot.Page(repo, title=pageTitle)
page.put(text, summary=summary)
示例12: main
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [as 别名]
def main():
"""
Main function. Grab a generator and pass it to the bot to work on
"""
query = u"""SELECT DISTINCT ?item
WHERE
{
?item p:P217 ?inventory . # with an inventory number and we want the statement
?item wdt:P195 ?collection . # with a collection set
FILTER NOT EXISTS { ?inventory pq:P195 ?somecollection } # and the inventory statement is missing the collection qualifier
}
LIMIT 1000"""
repo = pywikibot.Site().data_repository()
generator = pagegenerators.PreloadingItemGenerator(pagegenerators.WikidataSPARQLPageGenerator(query, site=repo))
fixInventoryCollectionBot = FixInventoryCollectionBot(generator)
fixInventoryCollectionBot.run()
示例13: __init__
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [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)
示例14: __init__
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [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')
示例15: __init__
# 需要导入模块: import pywikibot [as 别名]
# 或者: from pywikibot import Site [as 别名]
def __init__(self):
"""
Arguments:
* generator - A generator that yields Dict objects.
"""
self.repo = pywikibot.Site().data_repository()
self.progressPage = pywikibot.Page(self.repo, title=u'User:Multichill/Rijksmuseum creators RKD')
#self.progressPage.get()
self.creators = self.getCreators()
self.rkditems = self.getRKD()
#self.creators = self.fillCache()
#self.missingCreators = self.getMissingCreators()
#self.paintingIdProperty = paintingIdProperty
#self.paintingIds = self.fillCache(self.paintingIdProperty)