Quickstart#

 1from wikidata_bot_framework import (
 2    PropertyAdderBot,
 3    ExtraProperty,
 4    ExtraQualifier,
 5    ExtraReference,
 6    OutputHelper,
 7    site,
 8)
 9from pywikibot import Claim, ItemPage
10
11
12class MyBot(PropertyAdderBot):
13    def get_edit_summary(self, page):
14        return "Doing some stuff..."
15
16    def run_item(self, item):
17        helper = OutputHelper()
18        helper.add_property_from_property_id_and_value("P31", "Q5")  # instance of human
19        extra_prop = ExtraProperty.from_property_id_and_value(
20            "P106", "Q82955"
21        )  # occupation: politican
22        extra_qual = ExtraQualifier.from_property_id_and_value(
23            "P580", "2020-01-01T00:00:00Z"
24        )  # qualifier: start time: 2020-01-01
25        extra_ref = ExtraReference()
26        claim = Claim(site, "P854")
27        claim.setTarget("https://www.example.com")
28        extra_ref.add_claim(
29            claim, True
30        )  # reference: stated in: https://www.example.com
31        extra_prop.add_qualifier(extra_qual)
32        extra_prop.add_reference(extra_ref)
33        helper.add_property(extra_prop)
34        return helper
35
36
37def run_bot():
38    bot = MyBot()
39    bot.act_on_item(ItemPage(site, "Q4115189"))
40
41
42if __name__ == "__main__":
43    run_bot()