http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11664
Revision: 11664 Author: legoktm Date: 2013-06-18 08:00:37 +0000 (Tue, 18 Jun 2013) Log Message: ----------- Enable support for harvesting string properties
Modified Paths: -------------- branches/rewrite/scripts/harvest_template.py
Modified: branches/rewrite/scripts/harvest_template.py =================================================================== --- branches/rewrite/scripts/harvest_template.py 2013-06-18 07:43:45 UTC (rev 11663) +++ branches/rewrite/scripts/harvest_template.py 2013-06-18 08:00:37 UTC (rev 11664) @@ -100,24 +100,32 @@ pywikibot.output(u'A claim for %s already exists. Skipping' % (claim.getID(),)) #TODO FIXME: This is a very crude way of dupe checking else: - # Try to extract a valid page - match = re.search(pywikibot.link_regex, value) - if match: - try: - link = pywikibot.Link(match.group(1)) - linkedPage = pywikibot.Page(link) - if linkedPage.isRedirectPage(): - linkedPage = linkedPage.getRedirectTarget() - linkedItem = pywikibot.ItemPage.fromPage(linkedPage) - claim.setTarget(linkedItem) - pywikibot.output('Adding %s --> %s' % (claim.getID(), claim.getTarget().getID())) - item.addClaim(claim) - if self.source: - claim.addSource(self.source, bot=True) - except pywikibot.exceptions.NoPage: - pywikibot.output('[[%s]] doesn't exist so I can't link to it' % (linkedItem.title(),)) - + if claim.getType() == 'wikibase-item': + # Try to extract a valid page + match = re.search(pywikibot.link_regex, value) + if match: + try: + link = pywikibot.Link(match.group(1)) + linkedPage = pywikibot.Page(link) + if linkedPage.isRedirectPage(): + linkedPage = linkedPage.getRedirectTarget() + linkedItem = pywikibot.ItemPage.fromPage(linkedPage) + claim.setTarget(linkedItem) + except pywikibot.exceptions.NoPage: + pywikibot.output('[[%s]] doesn't exist so I can't link to it' % (linkedItem.title(),)) + continue + elif claim.getType() == 'string': + claim.setTarget(value.strip()) + else: + print "%s is not a supported datatype." % claim.getType() + continue
+ pywikibot.output('Adding %s --> %s' % (claim.getID(), claim.getTarget())) + item.addClaim(claim) + if self.source: + claim.addSource(self.source, bot=True) + + def main(): gen = pagegenerators.GeneratorFactory() commandline_arguments = list()