summaryrefslogtreecommitdiffstats
path: root/examples/simple.py
blob: 6158f98924793ba52fd3dd49148d09ff25d02475 (plain)
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
37
38
39
40
41
42
43
44
45
46
47

from bbb import *

wikidata = WikibaseServer(api_url="https://test.wikidata.org/w/api.php",
    lang="en")

# This will check that the site and auth stuff works
wikidata.check()

earth = wikidata.get_item("Earth")
print(earth)
print(wikidata.get_item("Q10"))

# http://wikidata.wiki.local.wmftest.net:8080/wiki/Special:ListProperties
mass = wikidata.get_property("P2")
print(mass)

print(wikidata.search_items("love", limit=5))
print(wikidata.search_items("robot", limit=5))
print(wikidata.search_properties("mass", limit=5))

print(wikidata.search_items("coffee", limit=5, fetch=True))

# TODO: is this possible?
#print(wikidata.search_statements(earth))
#print(wikidata.search_statements(mass))

devsrv = WikibaseServer(
    api_url="http://wikidata.wiki.local.wmftest.net:8080/w/api.php")
devsrv.login("TestBaseBot", "TestBaseBot123", force_http=True)
print(devsrv)

thing = WikibaseItem("QWERTY Layout")
print(thing)
devsrv.create(thing)
print(thing)

thing.add(WikibaseStatement(
    "Inventor of", "Christopher Latham Sholes",
    qualifiers={'Year of Invention': 1860},
    refs=['http://www.smithsonianmag.com/arts-culture/fact-of-fiction-the-legend-of-the-qwerty-keyboard-49863249/']))

devsrv.save(thing)
print(thing)

thing.statements[0].deprecate()
devsrv.save(thing.statements[0])