Project:BotBased imports: Difference between revisions
From MaRDI portal
No edit summary |
No edit summary |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
If you want to use a script to import / update items in the MaRDI Knowledge Graph, you might want to to that by using a Python script and the MardiClient library. This document describes the main steps. | If you want to use a script to import / update items in the MaRDI Knowledge Graph, you might want to to that by using a Python script and the MardiClient library. This document describes the main steps. | ||
===== Create the Python script | ==== Create a bot that will do the changes ==== | ||
# Login to the mardi-wikibase docker container | |||
# Execute: php /var/www/html/w/maintenance/createAndPromote.php <BOTUSER_NAME> <BOTUSER_PW> --bot | |||
# In case you need to change the Bot's password, use: php /var/www/html/w/maintenance/run.php changePassword --user=example --password=newpassword | |||
==== Create the Python script ==== | |||
The core is something like this: | The core is something like this: | ||
<syntaxhighlight lang="python" line> | <syntaxhighlight lang="python" line> | ||
from mardiclient import MardiClient | from mardiclient import MardiClient | ||
mc = MardiClient(user=" | mc = MardiClient(user="bot_username", password="bot_password", login_with_bot=True) | ||
item = mc.item.new() | item = mc.item.new() | ||
item.labels.set(language='en', value='My Label') | item.labels.set(language='en', value='My Label') | ||
item.write() | item.write() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==== Run the Python script ==== | |||
:-) | |||
Latest revision as of 10:30, 28 March 2025
Synopsis
If you want to use a script to import / update items in the MaRDI Knowledge Graph, you might want to to that by using a Python script and the MardiClient library. This document describes the main steps.
Create a bot that will do the changes
- Login to the mardi-wikibase docker container
- Execute: php /var/www/html/w/maintenance/createAndPromote.php <BOTUSER_NAME> <BOTUSER_PW> --bot
- In case you need to change the Bot's password, use: php /var/www/html/w/maintenance/run.php changePassword --user=example --password=newpassword
Create the Python script
The core is something like this:
from mardiclient import MardiClient
mc = MardiClient(user="bot_username", password="bot_password", login_with_bot=True)
item = mc.item.new()
item.labels.set(language='en', value='My Label')
item.write()
Run the Python script
- -)