import pywikibot

repo = pywikibot.Site("test", "wikidata")
item = pywikibot.ItemPage(repo, 'Q167028')
print()
test
pywikibot.WbTime.fromTimestr('1950-07-28T00:00:00Z', precision=11)
WbTime(year=1950, month=7, day=28, hour=0, minute=0, second=0, precision=11, before=0, after=0, timezone=0, calendarmodel=http://www.wikidata.org/entity/Q1985727)
item.get()
claim = pywikibot.Claim(repo, 'P31')
pywikibot.output('Remplacement dans %s de %s : %s par %s' % (item.getID(), claim.getID(), item.claims['P31'][0], 'http://rien.org'))
assert len(item.claims['P31']) == 1
item.claims['P31'][0].changeTarget('http://rien.org')
Remplacement dans Q167028 de P31 : Claim.fromJSON(DataSite("test", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P31', 'datatype': 'url', 'datavalue': {'value': 'http://rien.de', 'type': 'string'}}, 'type': 'statement', 'id': 'Q167028$8CF7E578-51CA-4B8D-8C77-6E7F33AED83F', 'rank': 'normal'}) par http://rien.org
WARNING: API error editconflict: Edit conflict. Could not patch the current revision.
---------------------------------------------------------------------------
APIError                                  Traceback (most recent call last)
<ipython-input-89-7ec6dedf3e57> in <module>()
      3 pywikibot.output('Remplacement dans %s de %s : %s par %s' % (item.getID(), claim.getID(), item.claims['P31'][0], 'http://rien.org'))
      4 assert len(item.claims['P31']) == 1
----> 5 item.claims['P31'][0].changeTarget('http://rien.org')

/srv/paws/pwb/pywikibot/page.py in changeTarget(self, value, snaktype, **kwargs)
   5016 
   5017         data = self.repo.changeClaimTarget(self, snaktype=snaktype,
-> 5018                                            **kwargs)
   5019         # TODO: Re-create the entire item from JSON, not just id
   5020         self.snak = data['claim']['id']

/srv/paws/pwb/pywikibot/site.py in callee(self, *args, **kwargs)
   1319             else:
   1320                 raise Exception("Not implemented")
-> 1321             return fn(self, *args, **kwargs)
   1322 
   1323         if not __debug__:

/srv/paws/pwb/pywikibot/site.py in changeClaimTarget(self, claim, snaktype, bot, summary)
   7791         params['baserevid'] = claim.on_item.latest_revision_id
   7792         req = self._simple_request(**params)
-> 7793         data = req.submit()
   7794         return data
   7795 

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2215                               % result)
   2216 
-> 2217                 raise APIError(**result['error'])
   2218             except TypeError:
   2219                 raise RuntimeError(result)

APIError: editconflict: Edit conflict. Could not patch the current revision. [messages:[{'name': 'wikibase-api-editconflict', 'parameters': [], 'html': {'*': 'Edit conflict. Could not patch the current revision.'}}, {'name': 'edit-conflict', 'parameters': [], 'html': {'*': 'Conflit de modification.'}}]; help:See https://test.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.]
item.claims[claim.getID()][0].getSources()

return

ref = pywikibot.Claim(repo, 'P100')
target = pywikibot.ItemPage(repo, 'Q100')
ref.setTarget(target)
item.claims[claim.getID()][0].addSources(ref)
[]
claim = pywikibot.Claim(repo, 'p18')
claim.setTarget(time)
print(claim.getTarget())
item.addClaim(claim)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-59-ad3f7337ed5f> in <module>()
----> 1 print(claim.getID())
      2 return
      3 claim = pywikibot.Claim(repo, 'p18')
      4 claim.setTarget(time)
      5 print(claim.getTarget())

AttributeError: 'str' object has no attribute 'getID'
claim = pywikibot.Claim(repo, 'p18')

item.get()
claim = pywikibot.Claim(repo, 'p31')
claim.setTarget('http://rien.de')
item.addClaim(claim)

source = pywikibot.Claim(repo, 'p100')
target = pywikibot.ItemPage(repo, 'Q100')
source.setTarget(target)
claim.addSource(source)
WARNING: API warning (wbcreateclaim) of unknown format: {'messages': [{'name': 'wikibase-conflict-patched', 'parameters': [], 'html': {'*': 'Votre modification a été intégrée dans la dernière version.'}, 'type': 'warning'}]}
Sleeping for 9.6 seconds, 2018-07-26 16:06:06
s={u'type': u'statement', u'references': [{u'snaks': {u'P248': [{u'datatype': u'wikibase-item', u'datavalue': {u'type': u'wikibase-entityid', u'value': {u'entity-type': u'item', u'numeric-id': 5924723}}, u'property': u'P248', u'snaktype': u'value'}]}, u'hash': u'0b7065f4d06a3e13fb20236bf7d9bd7b7f2e51a3', u'snaks-order': [u'P248']}], u'mainsnak': {u'datatype': u'time', u'datavalue': {u'type': u'time', u'value': {u'after': 0, u'precision': 11, u'time': u'+00000001958-11-23T00:00:00Z', u'timezone': 0, u'calendarmodel': u'http://www.wikidata.org/entity/Q1985727', u'before': 0}}, u'property': u'P569', u'snaktype': u'value'}, u'id': u'Q2965963$D01FEC91-EAAA-42EB-AE49-97D953EE31AF', u'rank': u'normal'}['mainsnak']

exec('d=' + str(pywikibot.WbTime.fromTimestr('1958-11-23T00:00:00Z', precision=11)))
print(d)
print(s['datavalue']['value'])
s==s['datavalue']['value']
{'after': 0, 'before': 0, 'calendarmodel': 'http://www.wikidata.org/entity/Q1985727', 'precision': 11, 'time': '+00000001958-11-23T00:00:00Z', 'timezone': 0}
{'after': 0, 'precision': 11, 'time': '+00000001958-11-23T00:00:00Z', 'timezone': 0, 'calendarmodel': 'http://www.wikidata.org/entity/Q1985727', 'before': 0}
False
import pywikibot

repo = pywikibot.Site("test", "wikidata")
item = pywikibot.ItemPage(repo, 'Q167028')

item.get()
claim = pywikibot.Claim(repo, 'p31')
claim.setTarget('http://rien.de')
item.addClaim(claim)

ref = pywikibot.Claim(repo, 'P100')
ref.setTarget(pywikibot.ItemPage(repo, 'Q100'))

ref2 = pywikibot.Claim(repo, 'p31')
ref2.setTarget('http://rien.de')

claim.addSources([ref, ref2])
Sleeping for 9.7 seconds, 2018-07-27 16:00:20
WARNING: API warning (wbsetreference) of unknown format: {'messages': [{'name': 'wikibase-conflict-patched', 'parameters': [], 'html': {'*': 'Votre modification a été intégrée dans la dernière version.'}, 'type': 'warning'}]}
import pywikibot

repo = pywikibot.Site("wikidata", "wikidata")
item = pywikibot.ItemPage(repo, 'Q693819')

claim = item.get().get('claims').get('P569')[0]

claim.getSources()
[OrderedDict([('P248',
               [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'snaktype': 'value', 'property': 'P248', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 5924723}, 'type': 'wikibase-entityid'}, 'hash': '0b7065f4d06a3e13fb20236bf7d9bd7b7f2e51a3'})])])]