User:Ronhjones/Python

MODIFIED lines in

def deletefile(page, version, token): #Un-url-ify params = {'action':'delete', 'title':page.unprefixedtitle, 'oldimage':version, 'token':token }   print "Done" return #Stop the function, ready for the next def main: pages = findpages for page in pages: #For page in the list #try: #Try to delete the old revision(s) todelete = versiontodelete(page) print todelete for version in todelete: #Get a token params = { 'action':'query', 'meta':'tokens' } token = api.APIRequest(site, params).query['query']['tokens']['csrftoken'] deletefile(page, version, token) #except: #If there's an error, ignore the file #pass if __name__ == "__main__": with warnings.catch_warnings: warnings.simplefilter("ignore", FutureWarning) main

The nice examples vanished as more items added to list! Murphy's Law... Never mind - found one.

See "File:2016_CONCACAF_Girls'_U-15_Championship.png" - only one should be deleting.
 * 20160715182133 is the hidden one - I can see that in the url if I view it
 * 20170222185852 is the one to delete

Page File u'File:File:2015 CampingWorld.com 500 logo.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20170222201938!2015_CampingWorld.com_500_logo.png'} [{u'archivename': u"20170222185852!2016_CONCACAF_Girls'_U-15_Championship.png"}, {u'archivename': u"20160715182133!2016_CONCACAF_Girls'_U-15_Championship.png"}] Done Page File u"File:File:2016 CONCACAF Girls' U-15 Championship.png" from 'https://en.wikipedia.org' Version {u'archivename': u"20170222185852!2016_CONCACAF_Girls'_U-15_Championship.png"} Done Page File u"File:File:2016 CONCACAF Girls' U-15 Championship.png" from 'https://en.wikipedia.org' Version {u'archivename': u"20160715182133!2016_CONCACAF_Girls'_U-15_Championship.png"} [{u'archivename': u'20170222205208!2016_COTIF_Tournament.jpg'}] Done Page File u'File:File:2016 COTIF Tournament.jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20170222205208!2016_COTIF_Tournament.jpg'} [{u'archivename': u'20170222190254!2016_FIVB_Volleyball_World_Grand_Prix_Finals.png'}] ^C C:\Python27\bot>

Processed a few hundred files to get rid of all file up to "K" - now found them again!
- See also User:Ronhjones/Python2 for why it is happening. C:\Python27\bot>python deleter.py [{u'archivename': u'20170204000319!Knatterton-cover.jpg'}] Done Page File u'File:File:Knatterton-cover.jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20170204000319!Knatterton-cover.jpg'} [{u'archivename': u'20170210161123!KNBN_Logo.png'}, {u'archivename': u'20170209023545!KNBN_Logo.png'}, {u'archivename': u'20170207223115!KNBN_Logo.png'}, {u'archivename': u'20170205070251!KNBN_Logo.pn g'}, {u'archivename': u'20160511060241!KNBN_Logo.png'}] Done Page File u'File:File:KNBN Logo.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20170210161123!KNBN_Logo.png'} Done Page File u'File:File:KNBN Logo.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20170209023545!KNBN_Logo.png'} Done Page File u'File:File:KNBN Logo.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20170207223115!KNBN_Logo.png'} Done Page File u'File:File:KNBN Logo.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20170205070251!KNBN_Logo.png'} Done Page File u'File:File:KNBN Logo.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20160511060241!KNBN_Logo.png'} [{u'archivename': u'20170215195056!Knockout_(comic_book_cover,_30_October_1971).jpg'}] Done Page File u'File:File:Knockout (comic book cover, 30 October 1971).jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20170215195056!Knockout_(comic_book_cover,_30_October_1971).jpg'} [{u'archivename': u'20170215201827!Knockout_issue_723_(comic_book_cover,_1953).jpg'}] Done Page File u'File:File:Knockout issue 723 (comic book cover, 1953).jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20170215201827!Knockout_issue_723_(comic_book_cover,_1953).jpg'} [{u'archivename': u'20170207223805!Knol_screenshot.png'}] Done Page File u'File:File:Knol screenshot.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20170207223805!Knol_screenshot.png'} [{u'archivename': u'20170213155230!KNTM_4_CAST.jpg'}, {u'archivename': u'20151027145115!KNTM_4_CAST.jpg'}] Done Page File u'File:File:KNTM 4 CAST.jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20170213155230!KNTM_4_CAST.jpg'} Done Page File u'File:File:KNTM 4 CAST.jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20151027145115!KNTM_4_CAST.jpg'} [{u'archivename': u'20170210151737!KNTM_season_3_cast_.jpg'}, {u'archivename': u'20160522151158!KNTM_season_3_cast_.jpg'}, {u'archivename': u'20151027144143!KNTM_season_3_cast_.jpg'}] Done Page File u'File:File:KNTM season 3 cast .jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20170210151737!KNTM_season_3_cast_.jpg'} Done Page File u'File:File:KNTM season 3 cast .jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20160522151158!KNTM_season_3_cast_.jpg'} Done Page File u'File:File:KNTM season 3 cast .jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20151027144143!KNTM_season_3_cast_.jpg'} [{u'archivename': u'20170126080107!Knysna_Elephant_-_Hylton_Herd_SANParks_smaller.jpg'}] Done Page File u'File:File:Knysna Elephant - Hylton Herd SANParks smaller.jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20170126080107!Knysna_Elephant_-_Hylton_Herd_SANParks_smaller.jpg'} [{u'archivename': u'20170215193019!Knytt_Underground_Main_Menu_Title.png'}] Done Page File u'File:File:Knytt Underground Main Menu Title.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20170215193019!Knytt_Underground_Main_Menu_Title.png'} [{u'archivename': u'20170207214204!Kobralazarus.png'}] Done Page File u'File:File:Kobralazarus.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20170207214204!Kobralazarus.png'} [{u'archivename': u'20170203214057!Koda_Kumi_-_7_SPIRITS_DVD_cover.JPG'}] Done Page File u'File:File:Koda Kumi - 7 SPIRITS DVD cover.JPG' from 'https://en.wikipedia.org' Version {u'archivename': u'20170203214057!Koda_Kumi_-_7_SPIRITS_DVD_cover.JPG'} [{u'archivename': u'20170207212702!Krindlekrax.jpg'}] Done Page File u'File:File:Krindlekrax.jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20170207212702!Krindlekrax.jpg'} [{u'archivename': u'20170211164211!Kristin_Hersh_-_Hips_and_Makers.jpg'}] Done Page File u'File:File:Kristin Hersh - Hips and Makers.jpg' from 'https://en.wikipedia.org' Version {u'archivename': u'20170211164211!Kristin_Hersh_-_Hips_and_Makers.jpg'} [{u'archivename': u'20170208203816!KRJW-AM_Logo.png'}] Done Page File u'File:File:KRJW-AM Logo.png' from 'https://en.wikipedia.org' Version {u'archivename': u'20170208203816!KRJW-AM_Logo.png'} [{u'archivename': u'20170215202703!KRMD_(AM)_logo.jpg'}] ^C C:\Python27\bot>
 * 20160511060241!KNBN_Logo.png - is hidden
 * 20151027144143!KNTM_season_3_cast_.jpg is hidden
 * 20160522151158!KNTM_season_3_cast_.jpg is hidden