A simple script to update YouTube channel stats in a Wikidata page. Like BorkedBot, but simpler.
Basically, this script does three things:
- Get all YouTube channel ID (P2397) values in a Wikidata page
- Query the statistics for each channel ID to the YouTube API
- Update the stats in Wikidata
Requires Pywikibot, Python 3, and a YouTube API key.
Replace the subscribers
, views
, and stats_update
fields in the Youtube personality infobox as follows. If there are more than one channel, the stats will be displayed as a list. Remove the list
parameter if there's only one YouTube channel.
| subscribers = {{#invoke:WikidataIB|getValue|P2397|qo=yes|qual=P3744|list=ubl|fetchwikidata=ALL|onlysourced=no|scale=a|noicon=yes}}
| views = {{#invoke:WikidataIB|getValue|P2397|qo=yes|qual=P5436|list=ubl|fetchwikidata=ALL|onlysourced=no|scale=a|noicon=yes}}
| stats_update = {{#invoke:WikidataIB|getValue|P2397|qo=yes|qual=P585|maxvals=1|fetchwikidata=ALL|onlysourced=no|noicon=no}}