-
Notifications
You must be signed in to change notification settings - Fork 9
/
import_one.py
31 lines (25 loc) · 916 Bytes
/
import_one.py
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
# configuration for pywikibot
import sys
import pywikibot
# connect to the wikibase
wikibase = pywikibot.Site("my", "my")
wikibase_repo = wikibase.data_repository()
wikibase_repo.login()
# connect to wikidata
wikidata = pywikibot.Site("wikidata", "wikidata")
wikidata_repo = wikidata.data_repository()
from util.util import WikibaseImporter
wikibase_importer = WikibaseImporter(wikibase_repo, wikidata_repo)
# import a single item or property
arg = sys.argv[1]
print(f"Importing {arg}")
if arg.startswith("Q"):
print("before get")
wikidata_item = pywikibot.ItemPage(wikidata_repo, arg)
wikidata_item.get()
print("after get")
wikibase_importer.change_item(wikidata_item, wikibase_repo, True)
elif arg.startswith("P"):
wikidata_property = pywikibot.PropertyPage(wikidata_repo, arg)
wikidata_property.get()
wikibase_importer.change_property(wikidata_property, wikibase_repo, True)