import pywikibot
site = pywikibot.Site('test', 'wikidata')
repo = site.data_repository()
ZURICH = u'Q83992'
CONTAINS = u'P395'
HAS_COLOR = u'P42284'
# retrieve the ZURICH item
zh = pywikibot.ItemPage(repo, ZURICH)

# get claims
zh_claims = zh.get()['claims']
print(zh_claims)
{'P395': [<pywikibot.page.Claim object at 0x7f49012f9780>, <pywikibot.page.Claim object at 0x7f49012b0438>]}
# iterate over CONTAINS claims...
for contains_claim in zh_claims[CONTAINS]:
    # ... handle trees (all items are trees in our example)
    tree = pywikibot.ItemPage(repo, contains_claim.target.id)
    tree_dict = tree.get()

    # print item description
    print(tree_dict['descriptions'])
    
     # get HAS_COLOR claims
    tree_color_claims = tree_dict['claims'][HAS_COLOR]

    # ...iterate over them ...
    for tree_color_claim in tree_color_claims:
        # ... if the target of the HAS_COLOR claim is 'purple'...
        if tree_color_claim.target == u'purple':
            print('found a purple tree')
            # ... create new 'has color' claim with 'green' as value
            green_tree_claim = pywikibot.Claim(repo, HAS_COLOR)
            green_tree_claim.target = u'green'
            
            # add it to the tree (this is the bot part)
            tree.addClaim(green_tree_claim, \
                          summary=u'add claim that this should be a green tree')
            
            print('added green as color')
{'en': 'A green tree in Zurich'}
{'en': 'purple colored tree in Zurich'}
found a purple tree
added green as color