Page MenuHomePhabricator

Synchronising Wikidata and Wikipedias using pywikibot - Task 4
Closed, ResolvedPublic

Description

This is the fourth task for T276329, Synchronising Wikidata and Wikipedias using pywikibot, aimed at getting you familiar with adding info to Wikidata items.

  1. You should already have a Wikimedia account and set up pywikibot (if not, do Tasks 1 and 2 first).
  1. Find some pieces of information to add to a Wikidata item. You should have at least one QID, one image filename, one date, and one numerical ID (see under 'Identifiers'. You can take these from task 1, or find new ones if you want. If possible, use the script you wrote for Task 3 to find these, or you can define them manually in the code. Ideally they should not already be on Wikidata.
  1. Set up a script that connects to Wikidata, loads the target item, adds the pieces of information, and saves it back to Wikidata. You should save the information to the sandbox (https://www.wikidata.org/wiki/Q4115189) to start with. Once you are sure your code is working OK, and if the data is not already on Wikidata, then you should also save it to the live item.
  1. Bonus: also add a reference.
  1. Bonus: also add a qualifier.

Save your code to a repository, or create a page like https://www.wikidata.org/wiki/User:Mike_Peel/Outreachy_2 (under your username - and change the ending to '4'.) Add the links to the edits at the end of the code as a comment.

Once you are happy, send me a link to your page (by email, on my talk page, or replying to this ticket as you prefer). Make sure to also register it as a contribution on the Outreachy website (https://www.outreachy.org/outreachy-may-2021-internship-round/communities/wikimedia/synchronising-wikidata-and-wikipedias-using-pywiki/contributions/)!

Hints:

  • You can probably reuse code for earlier tasks to do this

Event Timeline

Hello! Can someone help with what Numerical ID means? I am kind of confused with the difference between the QID and the Numerical ID. Does that refer to the values of properties in the "Identifiers" section in the Wikidata?

Hello! Can someone help with what Numerical ID means? I am kind of confused with the difference between the QID and the Numerical ID. Does that refer to the values of properties in the "Identifiers" section in the Wikidata?

Yes, this is under 'identifiers'. For example, https://www.wikidata.org/wiki/Q555130 ('Lovell Telescope') has Property:P1216 ('National Heritage List for England number') as '1221685'.

Hello! Can someone help with what Numerical ID means? I am kind of confused with the difference between the QID and the Numerical ID. Does that refer to the values of properties in the "Identifiers" section in the Wikidata?

Yes, this is under 'identifiers'. For example, https://www.wikidata.org/wiki/Q555130 ('Lovell Telescope') has Property:P1216 ('National Heritage List for England number') as '1221685'.

Thank you very much!

@Mike_Peel Please I don't understand clearly this statement: "Use the sandbox to start with: if the data is not already on Wikidata, then use the live item."

@Mike_Peel Please I don't understand clearly this statement: "Use the sandbox to start with: if the data is not already on Wikidata, then use the live item."

I mean, save edits at https://www.wikidata.org/wiki/Q4115189 to start with - but once you are confident your code is working correctly, and the data isn't in the Wikidata item associated with the article, then you can add it directly to that Wikidata item as well. I'll try to make it clearer in the description.

Hey, can anyone help me out in adding a Numerical ID to a wikidata item. I am not able to find a way to get a Redirect Target for the link, which is a value for an identifier, since it's an external link and I don't know how pywikibot could access it.
P.S: I am trying to add " VIAF ID (P214): 139154440091835340978 (https://viaf.org/viaf/139154440091835340978/)" to https://www.wikidata.org/wiki/Q4115189

Hey, can anyone help me out in adding a Numerical ID to a wikidata item. I am not able to find a way to get a Redirect Target for the link, which is a value for an identifier, since it's an external link and I don't know how pywikibot could access it.
P.S: I am trying to add " VIAF ID (P214): 139154440091835340978 (https://viaf.org/viaf/139154440091835340978/)" to https://www.wikidata.org/wiki/Q4115189

Try something like this:
stringclaim = pywikibot.Claim(repo, u’P214’)
stringclaim.setTarget(‘139154440091835340978’)
wd_item.addClaim(stringclaim, summary=u'Adding VIAF ID')

Hey, can anyone help me out in adding a Numerical ID to a wikidata item. I am not able to find a way to get a Redirect Target for the link, which is a value for an identifier, since it's an external link and I don't know how pywikibot could access it.
P.S: I am trying to add " VIAF ID (P214): 139154440091835340978 (https://viaf.org/viaf/139154440091835340978/)" to https://www.wikidata.org/wiki/Q4115189

Try something like this:
stringclaim = pywikibot.Claim(repo, u’P214’)
stringclaim.setTarget(‘139154440091835340978’)
wd_item.addClaim(stringclaim, summary=u'Adding VIAF ID')

Thank you so much!!

Hi @Mike_Peel and @MSGJ, I have completed Task 4, please review and share your feedback.

Link to my page: https://www.wikidata.org/wiki/User:Srishti0gupta/Outreachy_4

Hey everyone, I'm unable to add source(s) to the Wikidata Sandbox for both-- pre-existing properties and the new ones that I'm adding as a statement.

Could anyone please help me out?

Thank you!

Hey everyone, I'm unable to add source(s) to the Wikidata Sandbox for both-- pre-existing properties and the new ones that I'm adding as a statement.

Could anyone please help me out?

Thank you!

@Poornima7 For new one you may use addSources() function, this tutorial will be helpful : https://www.wikidata.org/wiki/Wikidata:Pywikibot_-_Python_3_Tutorial/Setting_sources

@Srishti0gupta thank you, but it still isn't working. The terminal is not even showing any error, it's successfully passing the test (although there seems to be no sleep time for this as well, which I do think is an indication of not being saved online). I've tried to add a source on a couple of wikidata pages, but still no results. Also, I tried copy pasting the tutorial's code, and it doesn't work as well.
@Mike_Peel @MSGJ

@Srishti0gupta thank you, but it still isn't working. The terminal is not even showing any error, it's successfully passing the test (although there seems to be no sleep time for this as well, which I do think is an indication of not being saved online). I've tried to add a source on a couple of wikidata pages, but still no results. Also, I tried copy pasting the tutorial's code, and it doesn't work as well.
@Mike_Peel @MSGJ

Are you able to add statements ?
Would you like to share your code snippet ?

For pre-existing statements, I first retrieved the claim object for that Property and Target Value, then used getSources() to obtain the list of sources, post that I appended the list with new claim object which I want to set as sources and used addSources().

@Poornima7

Hello, I sent my task 4 code through email.