forked from svrnwnsch/pywikidata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
36 lines (28 loc) · 780 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
import wikidata
"""
Create items
~~~~~~~~~~~~
"""
item = wikidata.Item({"cawiki":"Catalunya"}, {}, {}, {})
# sitelinks, aliases, labels, descriptions
item2 = wikidata.Item({"cawiki":"Catalunya"}, {}, {}, {})
wikidata.api.save([item, item2], 'Edit summary')
"""
Get an item by id
~~~~~~~~~~~~~~~~~
"""
item = wikidata.api.getItemById(1) # getItemsById also works
"""
Modify an item
~~~~~~~~~~~~~~
"""
item.sitelinks["cawiki"] = u"Barcelona"
item.sitelinks["eswiki"] = "Barna"
wikidata.api.save(item, 'Edit summary')
"""
Other notes
~~~~~~~~~~~
The locally stored item is updated with the changes remotely, e.g. if Wikidata has resolved a redirection.
"""
print item.sitelinks # eswiki points to Barcelona, following the redirect