diff --git a/bot.php b/bot.php index 69e3b82..ee268a0 100644 --- a/bot.php +++ b/bot.php @@ -1,89 +1,90 @@ + createQuery( [ 'action' => 'query', 'generator' => 'categorymembers', 'prop' => 'imageinfo', 'iiprop' => [ 'url', 'mime' ], 'gcmtitle' => $CATEGORY_NAME, ] ); foreach( $queries as $query ) { foreach( $query->query->pages as $page ) { if( !isset( $page->imageinfo ) ) { continue; } $imageinfo = $page->imageinfo[0] ?? null; if( !$imageinfo ) { continue; } $mime = $imageinfo->mime ?? null; if( $mime !== 'image/jpeg' ) { echo "bad mime $mime\n"; continue; } $image = ( new Query() ) ->from( 'image' ) ->whereInt( 'commons_pageid', $page->pageid ) ->queryRow(); if( $image ) { // try to update existing image foreach( $CONNOTATION_IDs as $CONNOTATION_ID ) { // try to relate if possible try { insert_row( 'image_connotation', [ 'image_ID' => $image->image_ID, 'connotation_ID' => $CONNOTATION_ID, ] ); echo "Updated\n"; } catch( Exception $e ) { echo "Already added\n"; } } } else { // create a new Image query( 'START TRANSACTION' ); insert_row( 'image', [ 'image_src' => $imageinfo->url, 'commons_pageid' => $page->pageid ] ); $inserted = last_inserted_ID(); foreach( $CONNOTATION_IDs as $CONNOTATION_ID ) { insert_row( 'image_connotation', [ 'image_ID' => $inserted, 'connotation_ID' => $CONNOTATION_ID, ] ); } query( 'COMMIT' ); - echo "created $page->pageid"; + echo "created $page->pageid\n"; } } } diff --git a/load-example.php b/load-example.php index 2559dac..720e84b 100644 --- a/load-example.php +++ b/load-example.php @@ -1,6 +1,6 @@