import pywikibot
import re
import time
from datetime import date
from datetime import datetime
from pywikibot import pagegenerators

site = pywikibot.Site('commons', fam='commons')
count = 0

def stopWatch(value):
    '''From seconds to Hours:Minutes:Seconds'''

    valueH = (value/3600)
    Hours = int(valueH)
    valueM = (valueH - Hours)*60
    Minutes = int(valueM)
    valueS = (valueM - Minutes)*60
    Seconds = int(valueS)
    print ('\ntime consumed: ', Hours,"h",Minutes,"m",Seconds,"s")

### BEGIN ###
timestamp =
start = time.time() # start stopwatch

cat1 = pywikibot.Category(site,'Category:Town halls and municipal offices in Austria')
cat2 = pywikibot.Category(site,'Category:Vienna')

### test case
pages = pagegenerators.intersect_generators(

for page in pages:
    print (page)
    count = count + 1
end = time.time() # start stopwatch

print ('finished:', count, 'pages found.')
[[commons:File:Die Gartenlaube (1882) b 032.jpg]]
[[commons:File:IMG 0145 - Wien - Rathaus (foreground) and Votivkirche (background).JPG]]
[[commons:File:IMG 0157 - Wien - Parlament (foreground), Rathaus (central), Votivkirche (background).JPG]]
[[commons:File:Wien Rathaus Leopoldsberg Weinberge 2012.jpg]]
[[commons:File:Volksgarten 6652-Pano groß 100.jpg]]
[[commons:File:Blick aufs Rathaus und die Votivkirche, Wien - panoramio.jpg]]
[[commons:File:GuentherZ 2008-04-26 0736 Wien Hochhaus Herrengasse.jpg]]
[[commons:File:Vienna view towards Rathaus from Hoch Haus Dec 2013 - 2 (11254966743).jpg]]
[[commons:File:Wien Heldenplatz 2015-07 a.jpg]]
[[commons:File:Weihnachtskrippe für den Kronprinzen Otto.jpg]]
[[commons:File:WEISS(1872) p579 Portal der Salvatorkapelle.jpg]]
[[commons:File:BERMANN(1880) p0803 Portal der Sallvatorkirche.jpg]]
[[commons:File:St Salvator Orgel0001.JPG]]
[[commons:File:St Salvator Seitenaltar.JPG]]
[[commons:File:St Salvator vom alten Rathaus.JPG]]
[[commons:File:St Salvator-Salvatorg 5.JPG]]
[[commons:File:St Salvator.JPG]]
[[commons:File:St. Salvator Wien Österreich.jpg]]
[[commons:File:Salvatorkapelle v Salvatorg.JPG]]
[[commons:File:Wien Heldenplatz Prinz Eugen Rathaus.jpg]]
[[commons:File:Wiener Christkindlmarkt (10).jpg]]
[[commons:File:Blick über Wien - panoramio (1).jpg]]
[[commons:File:Blick vom Südturm des Stephansdoms zu Wien 15.jpg]]
WARNING: Http response status 503
WARNING: Non-JSON response received from server commons:commons; the server may be down.
Set gcmlimit = ['250']
WARNING: Waiting 5 seconds before retrying.
[[commons:File:Wikimedia Hackathon 2017 (34020358833).jpg]]
[[commons:File:Wikimedia Hackathon 2017 (34444088340).jpg]]
[[commons:File:Fischer von Erlach cropped.jpg]]
[[commons:File:Fischer von Erlach.jpg]]
[[commons:File:Leopold der Glorreiche.Rathausplatz.Wien.JPG]]
[[commons:File:Niklas, Graf Salm, Purkartshofer Vienna.jpg]]
[[commons:File:Rathauspark mit Denkmälern, Skulpturen, Brunnen und Baulichkeiten (66299) IMG 9901.jpg]]
[[commons:File:Rathauspark mit Denkmälern, Skulpturen, Brunnen und Baulichkeiten (66299) IMG 9902.jpg]]
[[commons:File:Rathauspark mit Denkmälern, Skulpturen, Brunnen und Baulichkeiten (66299) IMG 9905.jpg]]
[[commons:File:Rathauspark mit Denkmälern, Skulpturen, Brunnen und Baulichkeiten (66299) IMG 9906.jpg]]
[[commons:File:Rathausplatz Niklas Graf Salm.JPG]]
[[commons:File:Rathausplatz Vienna June 2006 168.jpg]]
[[commons:File:Rathausplatz, 1010 Wien, Austria - panoramio (1).jpg]]
[[commons:File:Wien-Donauturm, Blick zum Rathaus und zum Wiener Wald.JPG]]