Hi,
I'm using an old version of pywikibot to edit our private wiki. I would like to upgrade, but I'm not able to configure the bot properly. (Note: at the end I say that with an older version it was working, not that you loose time in reading detailed configuration files)
My minimal example looks like
pywikibot==5.3.0
./config/my_family.py
from __future__ import absolute_import, division, unicode_literals
from pywikibot import config
from pywikibot import family
# The Wikidata family
class Family(family.WikimediaFamily):
"""Family class for Wikidata."""
name = 'my'
langs = {
'my': 'linkedopendata.eu',
}
interwiki_forward = 'wikipedia'
category_redirect_templates = {
'my': (
'Category redirect',
),
}
# Subpages for documentation.
doc_subpages = {
'_default': (('/doc', ), ['wikidata']),
}
# Disable cosmetic changes
config.cosmetic_changes_disable.update({
'my': ('wikidata2', 'test', 'beta')
})
def interface(self, code):
"""Return 'DataSite'."""
return 'DataSite'
def calendarmodel(self, code):
"""Default calendar model for WbTime datatype."""
return 'http://www.wikidata.org/entity/Q1985727'
def shared_geo_shape_repository(self, code):
"""Return Wikimedia Commons as the repository for geo-shapes."""
# Per geoShapeStorageFrontendUrl settings in Wikibase
return ('commons', 'commons')
def shared_tabular_data_repository(self, code):
"""Return Wikimedia Commons as the repository for tabular-datas."""
# Per tabularDataStorageFrontendUrl settings in Wikibase
return ('commons', 'commons')
def default_globe(self, code):
"""Default globe for Coordinate datatype."""
return 'earth'
def protocol(self, code):
return {
'my': 'https',
}[code]
def globes(self, code):
"""Supported globes for Coordinate datatype."""
return {
'ariel': 'http://www.wikidata.org/entity/Q3343',
'callisto': 'http://www.wikidata.org/entity/Q3134',
'ceres': 'http://www.wikidata.org/entity/Q596',
'deimos': 'http://www.wikidata.org/entity/Q7548',
'dione': 'http://www.wikidata.org/entity/Q15040',
'earth': 'http://www.wikidata.org/entity/Q2',
'enceladus': 'http://www.wikidata.org/entity/Q3303',
'eros': 'http://www.wikidata.org/entity/Q16711',
'europa': 'http://www.wikidata.org/entity/Q3143',
'ganymede': 'http://www.wikidata.org/entity/Q3169',
'gaspra': 'http://www.wikidata.org/entity/Q158244',
'hyperion': 'http://www.wikidata.org/entity/Q15037',
'iapetus': 'http://www.wikidata.org/entity/Q17958',
'io': 'http://www.wikidata.org/entity/Q3123',
'jupiter': 'http://www.wikidata.org/entity/Q319',
'lutetia': 'http://www.wikidata.org/entity/Q107556',
'mars': 'http://www.wikidata.org/entity/Q111',
'mercury': 'http://www.wikidata.org/entity/Q308',
'mimas': 'http://www.wikidata.org/entity/Q15034',
'miranda': 'http://www.wikidata.org/entity/Q3352',
'moon': 'http://www.wikidata.org/entity/Q405',
'oberon': 'http://www.wikidata.org/entity/Q3332',
'phobos': 'http://www.wikidata.org/entity/Q7547',
'phoebe': 'http://www.wikidata.org/entity/Q17975',
'pluto': 'http://www.wikidata.org/entity/Q339',
'rhea': 'http://www.wikidata.org/entity/Q15050',
'steins': 'http://www.wikidata.org/entity/Q150249',
'tethys': 'http://www.wikidata.org/entity/Q15047',
'titan': 'http://www.wikidata.org/entity/Q2565',
'titania': 'http://www.wikidata.org/entity/Q3322',
'triton': 'http://www.wikidata.org/entity/Q3359',
'umbriel': 'http://www.wikidata.org/entity/Q3338',
'venus': 'http://www.wikidata.org/entity/Q313',
'vesta': 'http://www.wikidata.org/entity/Q3030',
}user_config.py
from pywikibot.config2 import usernames, register_families_folder
register_families_folder('./config')
mylang = "my"
family = "my"
usernames['my']['my'] = u'WikidataUpdater'
password_file = "user-password.py"simpleTest.py
import pywikibot
wikibase = pywikibot.Site("my", "my")
wikibase_repo = wikibase.data_repository()
wikibase_item = pywikibot.PropertyPage(wikibase_repo, datatype='external-id')
mylabels = {"en": "Wikidata QID"}
wikibase_item.editLabels(mylabels, summary=u'Insert a property')Running python simpleTest.py gives the error:
File "/Users/Dennis/PycharmProjects/wikibaseEditor/venv/lib/python3.7/site-packages/pywikibot/family.py", line 709, in load
raise UnknownFamily('Family %s does not exist' % fam)
pywikibot.exceptions.UnknownFamily: Family my does not exist
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.UnknownFamily'>which I already find strange. I feel I followed the instructions at "https://www.mediawiki.org/wiki/Manual:Pywikibot/Use_on_third-party_wikis".
I can avoid this problem by setting:
simpleTest.py
import os
import pywikibot
from pywikibot import config2
family = 'my'
mylang = 'my'
familyfile=os.path.relpath("./config/my_family.py")
if not os.path.isfile(familyfile):
print ("family file %s is missing" % (familyfile))
config2.register_family_file(family, familyfile)
config2.password_file = "user-password.py"
config2.usernames['my']['my'] = 'WikidataUpdater'
wikibase = pywikibot.Site("my", "my")
wikibase_repo = wikibase.data_repository()
wikibase_item = pywikibot.PropertyPage(wikibase_repo, datatype='external-id')
mylabels = {"en": "Wikidata QID"}
wikibase_item.editLabels(mylabels, summary=u'Insert a property')which is far from ideal (I really would like to clean the code here) .... Running python simpleTest.py gives the error:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Dennis/PycharmProjects/wikibaseEditor/simpleTest.py", line 22, in <module>
wikibase_item.editLabels(mylabels, summary=u'Insert a property')
File "/Users/Dennis/PycharmProjects/wikibaseEditor/venv/lib/python3.7/site-packages/pywikibot/page/__init__.py", line 4215, in editLabels
self.editEntity(data, **kwargs)
File "/Users/Dennis/PycharmProjects/wikibaseEditor/venv/lib/python3.7/site-packages/pywikibot/page/__init__.py", line 138, in wrapper
handle(func, self, *args, **kwargs)
File "/Users/Dennis/PycharmProjects/wikibaseEditor/venv/lib/python3.7/site-packages/pywikibot/page/__init__.py", line 130, in handle
raise pywikibot.OtherPageSaveError(self, err)
pywikibot.exceptions.OtherPageSaveError: Edit to page [[my:Property:-1]] failed:
User "None" does not have required user right "edit"
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.OtherPageSaveError'>so the user is not passed correctly. Note that if I use as a pywikibot dependency
-e git+https://github.com/wikimedia/pywikibot.git@083ed9341881f562167e732974df35ee051ba994#egg=pywikibot
which is much older .... this worked. My guess is that there is either a bug or the documentation has to be changed.
Thank you for your help
D063520