In [3]:
# Wikidata item: Sandbox Q4115189, 
# Sandbox2 Q13406268, Sandbox3 Q15397819
# https://m.wikidata.org/wiki/Category:Sandbox_properties
# наприклад, Property:P368 - тестова властивість для значення типу "медіа-файл Вікісховища"

# Import modules
import pywikibot
from pywikibot import page
# from LexData/LexData import LexData

class Entity(dict): # див. LexData entity.py
    def __init__(self, repo: str):
        pass

print('nnnnnnnnnnnnn')
ukwiki = pywikibot.Site('uk', 'wikipedia')
print(ukwiki)
ukdikt = pywikibot.Site('uk', 'wiktionary')
print(ukdikt)
wiki_repo = ukdikt.data_repository()
print(wiki_repo)


lexeme = page.WikibasePage(wiki_repo, "Q4115189"); # , ns = 146
# lexeme = page.WikibasePage(wiki_repo, "Lexeme:L130966", ns=146); # , ns = 146
# !!! Mediawiki title normalization ->
# -> https://github.com/wikimedia/mediawiki-title
print('------------------------------')
print(lexeme)
print(type(lexeme))
lexeme_dict = lexeme.toJSON()
print(len(lexeme_dict))
print(lexeme_dict)
print('-------')
for part in lexeme_dict:
    print(part)

"""
page = pywikibot.ItemPage(wiki_repo, 'Q4115189')
print(page)
# test = printwikidata(page)
qid = page.title()
print(qid)

Accessing the Wikidata item directly
It is also possible to call the Wikidata item directly. All that is needed is the Q-code of the item. This code will allow the same access to the ItemPage-object
import pywikibot

item = pywikibot.ItemPage(wiki_repo, "Q42")
print(item.get().keys())
print('== == ==')
# dict_keys(['aliases', 'labels', 'descriptions', 'claims', 'sitelinks'])
# Now we know that the returned dictionary is similar to the previous.

# Task is Lexeme read from repo
item = pywikibot.ItemPage(wiki_repo, "Lexeme:L130966") #"L130966"
# InvalidTitle: 'L130966' is not a valid item page title
# ValueError: 'Lexeme:L130966' is not in the namespace 0

print(item.get().keys())
print('== == ==')
"""
print('----------------------')


t
nnnnnnnnnnnnn
wikipedia:uk
wiktionary:uk
wikidata:wikidata
------------------------------
[[wikidata:Q4115189]]
<class 'pywikibot.page.WikibasePage'>
0
{}
-------
----------------------
In [ ]: