diff --git a/.gitmodules b/.gitmodules index 8a1d29e..7690e43 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,27 +1,30 @@ [submodule "includes/boz-mw"] path = includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw.git [submodule "2018-06-wikidata-volleyball-players/includes/boz-mw"] path = 2018-06-wikidata-volleyball-players/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw [submodule "2018-06-wikidata-soccer-serie-a/includes/boz-mw"] path = 2018-06-wikidata-soccer-serie-a/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw.git [submodule "2018-02-italian-parks/includes/boz-mw"] path = 2018-02-italian-parks/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw.git [submodule "2018-07-wikipedia-citation-language-migration/includes/boz-mw"] path = 2018-07-wikipedia-citation-language-migration/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw [submodule "2017-11-wikidata-volleyball-players/includes/boz-mw"] path = 2017-11-wikidata-volleyball-players/includes/boz-mw url = https://github.com/valerio-bozzolan/boz-mw [submodule "2018-08-wiki-loves-monuments-switzerland/boz-mw"] path = 2018-08-wiki-loves-monuments-switzerland/includes/boz-mw url = git@github.com:valerio-bozzolan/boz-mw.git [submodule "2018-09-mibact-fixer/boz-mw"] path = 2018-09-mibact-fixer/boz-mw url = git@github.com:valerio-bozzolan/boz-mw.git [submodule "2018-09-23-itwiki-gnu-fdl/boz-mw"] path = 2018-09-23-itwiki-gnu-fdl/boz-mw url = https://github.com/valerio-bozzolan/boz-mw +[submodule "2019-05-commons-volleyball-players-upload/boz-mw"] + path = 2019-05-commons-volleyball-players-upload/include/boz-mw + url = https://github.com/valerio-bozzolan/boz-mw diff --git a/2019-05-commons-volleyball-players-upload/README.md b/2019-05-commons-volleyball-players-upload/README.md index 7cdc2af..b929c28 100644 --- a/2019-05-commons-volleyball-players-upload/README.md +++ b/2019-05-commons-volleyball-players-upload/README.md @@ -1,22 +1,21 @@ # 2019 Wikimedia Commons volleyball players uploader bot This PHP bot was developed to import LegaVolley volleyball players in Wikimedia Commons. ## Consensus - [X] [Consensus on it.wiki](https://it.wikipedia.org/wiki/Progetto:Sport/Pallavolo/Legavolley) - [X] [Similar consensus on Wikimedia Commons](https://commons.wikimedia.org/wiki/Commons:Bots/Requests/Valerio_Bozzolan_bot) (previous year) -- [ ] Consensus on Wikimedia Commons - +- [ ] [Consensus on Wikimedia Commons](https://commons.wikimedia.org/wiki/Commons:Bots/Requests/Valerio_Bozzolan_bot_(5)) ## Usage ./bot.php ## License Copyright (C) 2019 Valerio Bozzolan This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . diff --git a/2019-05-commons-volleyball-players-upload/bot.php b/2019-05-commons-volleyball-players-upload/bot.php new file mode 100755 index 0000000..cb3d4e8 --- /dev/null +++ b/2019-05-commons-volleyball-players-upload/bot.php @@ -0,0 +1,135 @@ +#!/usr/bin/php +. + +require 'include/boz-mw/autoload.php'; +require '../config.php'; + +use \web\MediaWikis; +use \cli\Log; + +$wiki = MediaWikis::findFromUID( 'commonswiki' ); +//$wiki->login(); + +// fingerprint of the default pic +$default_pic_md5 = md5( file_get_contents( 'data/default-pic.jpg' ) ); + +$header = true; +$handle = fopen( 'data/2019-volleyball-players.csv', 'r' ); +while( ( $data = fgetcsv( $handle ) ) !== false ) { + if( $header ) { + $header = false; + continue; + } + $n = count( $data ); + + /* + array(11) { + [0]=> + string(2) "id" + [1]=> + string(7) "cognome" + [2]=> + string(4) "nome" + [3]=> + string(7) "Altezza" + [4]=> + string(11) "DataNascita" + [5]=> + string(14) "NazioneNascita" + [6]=> + string(12) "LuogoNascita" + [7]=> + string(19) "NazionalitaSportiva" + [8]=> + string(13) "UltimaSquadra" + [9]=> + string(14) "ultimastagione" + [10]=> + string(7) "urlFoto" + } + */ + + list( $id, $surname, $name, $h, $birth, $birth_nation, $birth_where, $nation, $last_team, $last_season, $url_photo ) = $data; + + if( empty( $url_photo ) ) { + Log::warn( "skip $id $surname $name without URL" ); + continue; + } + + $pic = file_get_contents( $url_photo ); + if( strlen( $pic ) < 300 ) { + Log::warn( "skip $id $surname $name with no pic $url_photo" ); + continue; + } + + if( md5( $pic ) === $default_pic_md5 ) { + Log::warn( "skip $id $surname $name with default pic $url_photo" ); + continue; + } + + if( empty( $name ) || empty( $surname ) ) { + Log::warn( "skip $id without name or surname" ); + continue; + } + + $filename = "$name $surname (Legavolley 2019).jpg"; + +$date = date('Y-m-d H:i:s'); +$text = <<fetch( [ + 'action' => 'query', + 'prop' => 'info', + 'titles' => "File:$filename", + ] ); + $exists = false; + foreach( $response->query as $pages ) { + foreach( $pages as $page ) { + $exists = empty( $page->missing ); + } + } + + if( !$exists ) { + Log::warn( "skip File:$filename already existing" ); + continue; + } + + $comment = "Bot: test [[Commons:Bots/Requests/Valerio Bozzolan bot (5)|upload 2019 volleyball players from Legavolley]]"; + $token = $commons->getToken( \mw\Tokens::CSRF ); + $commons->post( [ + 'filename' => $filename, + 'comment' => $comment, + 'text' => $text, + 'url' > $url_photo, + 'token' => $token, + ] ); + exit; +} diff --git a/2019-05-commons-volleyball-players-upload/data/default-pic.jpg b/2019-05-commons-volleyball-players-upload/data/default-pic.jpg new file mode 100644 index 0000000..154874d Binary files /dev/null and b/2019-05-commons-volleyball-players-upload/data/default-pic.jpg differ