From 69b26a25282454695c87844ad9a868bf6dbf2c0a Mon Sep 17 00:00:00 2001 From: bnewbold Date: Mon, 25 Jan 2016 13:26:42 -0800 Subject: add a simple example script --- examples/simple.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 examples/simple.py (limited to 'examples/simple.py') diff --git a/examples/simple.py b/examples/simple.py new file mode 100644 index 0000000..6158f98 --- /dev/null +++ b/examples/simple.py @@ -0,0 +1,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]) -- cgit v1.2.3