本文整理匯總了Python中pywikibot.WbTime方法的典型用法代碼示例。如果您正苦於以下問題:Python pywikibot.WbTime方法的具體用法?Python pywikibot.WbTime怎麽用?Python pywikibot.WbTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pywikibot
的用法示例。
在下文中一共展示了pywikibot.WbTime方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: make_time_item
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def make_time_item(self, quantity, repo):
"""
Create a WbTime item.
quantity: {'time_value': <dict>}
with <dict> per utils.datetime_object_to_dict
This only works for full years and dates.
@TODO: Make it work for year range!
"""
value = quantity['time_value']
return pywikibot.WbTime(**value)
示例2: make_stated_in_reference
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def make_stated_in_reference(self, ref_dict):
prop = ref_dict["source"]["prop"]
if ref_dict.get("published"):
prop_date = ref_dict["published"]["prop"]
date = ref_dict["published"]["value"]
elif ref_dict.get("retrieved"):
prop_date = ref_dict["retrieved"]["prop"]
date = ref_dict["retrieved"]["value"]
date_item = pywikibot.WbTime(**date)
source_item = self.wdstuff.QtoItemPage(ref_dict["source"]["value"])
source_claim = self.wdstuff.make_simple_claim(prop, source_item)
if "reference_url" in ref_dict:
ref_url = ref_dict["reference_url"]["value"]
ref_url_prop = ref_dict["reference_url"]["prop"]
ref_url_claim = self.wdstuff.make_simple_claim(
ref_url_prop, ref_url)
ref = self.wdstuff.Reference(
source_test=[source_claim, ref_url_claim],
source_notest=self.wdstuff.make_simple_claim(
prop_date, date_item))
else:
ref = self.wdstuff.Reference(
source_test=[source_claim],
source_notest=self.wdstuff.make_simple_claim(
prop_date, date_item))
return ref
示例3: create_qualifiers
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def create_qualifiers(claim, qualifiers, year):
for q in qualifiers:
qualifier = pywikibot.Claim(repo, q[0])
if q[1][0] == 'time':
trgt_item = pywikibot.WbTime(int(year))
elif q[1][0] == 'item':
trgt_item = pywikibot.ItemPage(repo, q[1][1])
qualifier.setTarget(trgt_item)
claim.addQualifier(qualifier)
logging.info('Qualifier: {} added to claim'.format(q[0]))
return True
示例4: addDateProperty
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def addDateProperty(self, itempage, datestring, property, refurl):
'''
Try to find a valid date and add it to the itempage using property
:param itempage: The ItemPage to update
:param datestring: The string containing the date
:param property: The property to add (for example date of birth or date of death)
:param refurl: The url to add as reference
:return:
'''
dateregex = u'^(?P<year>\d\d\d\d)-(?P<month>\d\d)-(?P<day>\d\d)$'
monthregex = u'^(?P<year>\d\d\d\d)-(?P<month>\d\d)$'
yearregex = u'^(?P<year>\d\d\d\d)$'
datematch = re.match(dateregex, datestring)
monthmatch = re.match(monthregex, datestring)
yearmatch = re.match(yearregex, datestring)
newdate = None
if datematch:
newdate = pywikibot.WbTime( year=int(datematch.group(u'year')),
month=int(datematch.group(u'month')),
day=int(datematch.group(u'day')))
elif monthmatch:
newdate = pywikibot.WbTime( year=int(monthmatch.group(u'year')),
month=int(monthmatch.group(u'month')))
elif yearmatch:
newdate = pywikibot.WbTime( year=int(yearmatch.group(u'year')))
else:
return False
newclaim = pywikibot.Claim(self.repo, property)
newclaim.setTarget(newdate)
itempage.addClaim(newclaim)
self.addReference(itempage, newclaim, refurl)
示例5: addReference
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def addReference(self, item, newclaim, url):
"""
Add a reference with a retrieval url and todays date
"""
pywikibot.output('Adding new reference claim to %s' % item)
refurl = pywikibot.Claim(self.repo, u'P854') # Add url, isReference=True
refurl.setTarget(url)
refdate = pywikibot.Claim(self.repo, u'P813')
today = datetime.datetime.today()
date = pywikibot.WbTime(year=today.year, month=today.month, day=today.day)
refdate.setTarget(date)
newclaim.addSources([refurl, refdate])
示例6: addReference
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def addReference(self, paintingItem, newclaim, uri):
"""
Add a reference with a retrieval url and todays date
"""
pywikibot.output('Adding new reference claim to %s' % paintingItem)
refurl = pywikibot.Claim(self.repo, u'P854') # Add url, isReference=True
refurl.setTarget(uri)
refdate = pywikibot.Claim(self.repo, u'P813')
today = datetime.datetime.today()
date = pywikibot.WbTime(year=today.year, month=today.month, day=today.day)
refdate.setTarget(date)
newclaim.addSources([refurl, refdate])
示例7: addReference
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def addReference(self, item, newclaim, uri):
"""
Add a reference with a retrieval url and todays date
"""
pywikibot.output('Adding new reference claim to %s' % item)
refstated = pywikibot.Claim(self.repo, u'P248')
refstated.setTarget(self.moma)
refurl = pywikibot.Claim(self.repo, u'P854')
refurl.setTarget(uri)
refdate = pywikibot.Claim(self.repo, u'P813')
today = datetime.datetime.today()
date = pywikibot.WbTime(year=today.year, month=today.month, day=today.day)
refdate.setTarget(date)
newclaim.addSources([refstated, refurl, refdate])
示例8: addReference
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def addReference(repo, item, newclaim, url):
"""
Add a reference with a retrieval url and todays date
"""
pywikibot.output('Adding new reference claim to %s' % item)
refurl = pywikibot.Claim(repo, u'P854') # Add url, isReference=True
refurl.setTarget(url)
refdate = pywikibot.Claim(repo, u'P813')
today = datetime.datetime.today()
date = pywikibot.WbTime(year=today.year, month=today.month, day=today.day)
refdate.setTarget(date)
newclaim.addSources([refurl, refdate])
示例9: addReleased
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def addReleased(self, item, imdbid):
'''
Add the first airdate to the item based on the imdbid
'''
pywikibot.output(u'Trying to add date to %s based on %s' % (item, imdbid))
data = item.get()
claims = data.get('claims')
if u'P1191' in claims:
return True
if imdbid not in self.imdbcache:
return False
releasedate = self.imdbcache[imdbid].get('released')
regex = u'^(\d\d\d\d)-(\d\d)-(\d\d)$'
match = re.match(regex, releasedate)
if not match:
return False
newdate = pywikibot.WbTime(year=int(match.group(1)),
month=int(match.group(2)),
day=int(match.group(3)),)
newclaim = pywikibot.Claim(self.repo, u'P1191')
newclaim.setTarget(newdate)
pywikibot.output('Adding release date claim %s to %s' % (releasedate, item))
item.addClaim(newclaim)
refurl = pywikibot.Claim(self.repo, u'P854')
refurl.setTarget(u'http://www.omdbapi.com/?i=%s' % (imdbid,))
refdate = pywikibot.Claim(self.repo, u'P813')
today = datetime.datetime.today()
date = pywikibot.WbTime(year=today.year, month=today.month, day=today.day)
refdate.setTarget(date)
newclaim.addSources([refurl, refdate])
示例10: run
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def run(self):
"""
Starts the robot.
"""
for itempage in self.generator:
pywikibot.output(u'Working on %s' % (itempage.title(),))
if not itempage.exists():
pywikibot.output(u'Item does not exist, skipping')
continue
data = itempage.get()
claims = data.get('claims')
# Do some checks so we are sure we found exactly one inventory number and one collection
if u'P650' not in claims:
pywikibot.output(u'No RKDArtists found, skipping')
continue
rkdartistsid = claims.get(u'P650')[0].getTarget()
rkdartistsurl = u'https://api.rkd.nl/api/record/artists/%s?format=json' % (rkdartistsid,)
refurl = u'https://rkd.nl/explore/artists/%s' % (rkdartistsid,)
# Do some checking if it actually exists?
rkdartistsPage = requests.get(rkdartistsurl, verify=False)
rkdartistsJson = rkdartistsPage.json()
if rkdartistsJson.get('content') and rkdartistsJson.get('content').get('message'):
pywikibot.output(u'Something went wrong, got "%s" for %s, skipping' % (rkdartistsJson.get('content').get('message'),
rkdartistsid))
continue
rkdartistsdocs = rkdartistsJson.get(u'response').get(u'docs')[0]
if u'P21' not in claims:
self.addGender(itempage, rkdartistsdocs, refurl)
elif len(claims.get(u'P21'))==1:
self.addGender(itempage, rkdartistsdocs, refurl, claim=claims.get(u'P21')[0])
if u'P106' not in claims:
self.addOccupation(itempage, rkdartistsdocs, refurl)
if u'P569' not in claims:
self.addDateOfBirth(itempage, rkdartistsdocs, refurl)
elif len(claims.get(u'P569'))==1:
self.addDateOfBirth(itempage, rkdartistsdocs, refurl, claim=claims.get(u'P569')[0])
if u'P570' not in claims:
self.addDateOfDeath(itempage, rkdartistsdocs, refurl)
elif len(claims.get(u'P570'))==1:
self.addDateOfDeath(itempage, rkdartistsdocs, refurl, claim=claims.get(u'P570')[0])
if u'P19' not in claims:
self.addPlaceOfBirth(itempage, rkdartistsdocs, refurl)
if u'P20' not in claims:
self.addPlaceOfDeath(itempage, rkdartistsdocs, refurl)
# Disabled for now. WbTime comparison seems to contain bugs
# Can be enabled when https://phabricator.wikimedia.org/T148280 is fixed
#if u'P27' not in claims and (u'P569' in claims or u'P570' in claims):
# self.addCountry(itempage, rkdartistsdocs, refurl)
示例11: treat
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [as 別名]
def treat(self, item):
data = item.get()
claims = data.get('claims')
snkinvnumber = u''
dvrinvnumber = u''
rbkinvnumber = u''
icninvnumber = u''
#rceinvnumber = u''
for invnumberclaim in claims.get(u'P217'):
if invnumberclaim.has_qualifier(u'P195', self.snkitem):
snkinvnumber = invnumberclaim.getTarget()
elif invnumberclaim.has_qualifier(u'P195', self.dvritem):
dvrinvnumber = invnumberclaim.getTarget()
elif invnumberclaim.has_qualifier(u'P195', self.rbkitem):
rbkinvnumber = invnumberclaim.getTarget()
elif invnumberclaim.has_qualifier(u'P195', self.icnitem):
icninvnumber = invnumberclaim.getTarget()
#elif invnumberclaim.has_qualifier(u'P195', self.rceitem):
# rceinvnumber = invnumberclaim.getTarget()
if not snkinvnumber:
print u'Something went wrong, skipping'
return
if not dvrinvnumber:
self.addInventoryNumber(item, snkinvnumber, self.dvritem)
if not rbkinvnumber:
self.addInventoryNumber(item, snkinvnumber, self.rbkitem)
if not icninvnumber:
self.addInventoryNumber(item, snkinvnumber, self.icnitem)
collectiontargets = []
for collectionclaim in claims.get(u'P195'):
collectiontargets.append(collectionclaim.getTarget())
if self.jgsitem not in collectiontargets:
self.addCollection(item, self.jgsitem)
if self.dvritem not in collectiontargets:
self.addCollection(item, self.dvritem)
if self.rbkitem not in collectiontargets:
self.addCollection(item, self.rbkitem)
if self.icnitem not in collectiontargets:
newclaim = self.addCollection(item, self.icnitem)
endtime = pywikibot.WbTime(year=2006, month=2)
colqualifier = pywikibot.Claim(self.repo, u'P582')
colqualifier.setTarget(endtime)
pywikibot.output('Adding end date to the ICN collection')
newclaim.addQualifier(colqualifier)
示例12: fusion_cat
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import WbTime [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")