#2019-09-23 20:30
import pywikibot
import pywikibot.pagegenerators as pg 

def action_one_template(p):
    orgtxt=p.text
    p.text=p.text.replace('<div class="center">','<div class="center" style="width:auto; margin-left:auto; margin-right:auto;">')
    p.text=p.text.replace('<center>','<div class="center" style="width:auto; margin-left:auto; margin-right:auto;">')
    p.text=p.text.replace('</center>','</div>')
    if (orgtxt!=p.text):
      p.put(p.text,summary=f'lintfoutenisatie: <center> vervangen: [https://paws-public.wmflabs.org/paws-public/User:Edoderoo/center-from-templates.ipynb src]')
      #print(1/0)

def all_from_cat(here):
  cat=pywikibot.Category(site,here)
  for subcat in pg.SubCategoriesPageGenerator(cat):
    print(subcat)

def pages_from_cat(thiscat):
  cat=pywikibot.Category(site,thiscat)
  gen=pg.CategorizedPageGenerator(cat,123)
  for page in gen:
    yield(page)

site=pywikibot.Site('nl','wikipedia')
for page in pages_from_cat('Categorie:Wikipedia:Sjablonen techniek'):
    action_one_template(page)
WARNING: API error badtoken: Invalid CSRF token.
Sleeping for 9.8 seconds, 2019-09-22 16:56:29
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen 15 km mannen]] saved
Sleeping for 9.4 seconds, 2019-09-22 16:56:39
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen 15 km vrouwen]] saved
Sleeping for 9.3 seconds, 2019-09-22 16:56:50
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen 18 km mannen]] saved
Sleeping for 9.4 seconds, 2019-09-22 16:56:59
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen 20 km vrouwen]] saved
Sleeping for 9.3 seconds, 2019-09-22 16:57:10
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen 50 km mannen]] saved
Sleeping for 9.4 seconds, 2019-09-22 16:57:19
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen 5 km vrouwen]] saved
Sleeping for 9.5 seconds, 2019-09-22 16:57:29
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen achtervolging mannen]] saved
Sleeping for 9.5 seconds, 2019-09-22 16:57:39
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen achtervolging vrouwen]] saved
Sleeping for 9.4 seconds, 2019-09-22 16:57:49
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen estafette mannen]] saved
Sleeping for 9.4 seconds, 2019-09-22 16:57:59
Page [[nl:Sjabloon:Navigatie olympisch kampioen/langlaufen estafette vrouwen]] saved
Sleeping for 9.4 seconds, 2019-09-22 16:58:10
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-4-039129096e24> in <module>
     25 site=pywikibot.Site('nl','wikipedia')
     26 for page in pages_from_cat('Categorie:Wikipedia:Sjablonen olympisch kampioen'):
---> 27     action_one_template(page)
     28 

<ipython-input-4-039129096e24> in action_one_template(p)
      8     p.text=p.text.replace('</center>','</div>')
      9     if (orgtxt!=p.text):
---> 10       p.put(p.text,summary=f'lintfoutenisatie: <center> vervangen: [https://paws-public.wmflabs.org/paws-public/User:Edoderoo/center-from-templates.ipynb src]')
     11       #print(1/0)
     12 

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1736                              cls, depth)
   1737                     del __kw[old_arg]
-> 1738             return obj(*__args, **__kw)
   1739 
   1740         if not __debug__:

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1736                              cls, depth)
   1737                     del __kw[old_arg]
-> 1738             return obj(*__args, **__kw)
   1739 
   1740         if not __debug__:

/srv/paws/pwb/pywikibot/page.py in put(self, newtext, summary, watch, minor, botflag, force, asynchronous, callback, **kwargs)
   1358         self.save(summary=summary, watch=watch, minor=minor, botflag=botflag,
   1359                   force=force, asynchronous=asynchronous, callback=callback,
-> 1360                   **kwargs)
   1361 
   1362     @deprecated('put(asynchronous=True) or save(asynchronous=True)')

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1736                              cls, depth)
   1737                     del __kw[old_arg]
-> 1738             return obj(*__args, **__kw)
   1739 
   1740         if not __debug__:

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1736                              cls, depth)
   1737                     del __kw[old_arg]
-> 1738             return obj(*__args, **__kw)
   1739 
   1740         if not __debug__:

/srv/paws/pwb/pywikibot/page.py in save(self, summary, watch, minor, botflag, force, asynchronous, callback, apply_cosmetic_changes, quiet, **kwargs)
   1280         self._save(summary=summary, watch=watch, minor=minor, botflag=botflag,
   1281                    asynchronous=asynchronous, callback=callback,
-> 1282                    cc=apply_cosmetic_changes, quiet=quiet, **kwargs)
   1283 
   1284     @allow_asynchronous

/srv/paws/pwb/pywikibot/page.py in wrapper(self, *args, **kwargs)
    126             pywikibot.async_request(handle, func, self, *args, **kwargs)
    127         else:
--> 128             handle(func, self, *args, **kwargs)
    129 
    130     manage_wrapping(wrapper, func)

/srv/paws/pwb/pywikibot/page.py in handle(func, self, *args, **kwargs)
    105         err = None
    106         try:
--> 107             func(self, *args, **kwargs)
    108         # TODO: other "expected" error types to catch?
    109         except pywikibot.Error as edit_err:

/srv/paws/pwb/pywikibot/page.py in _save(self, summary, watch, minor, botflag, cc, quiet, **kwargs)
   1291 
   1292         done = self.site.editpage(self, summary=summary, minor=minor,
-> 1293                                   watch=watch, bot=botflag, **kwargs)
   1294         if not done:
   1295             if not quiet:

/srv/paws/pwb/pywikibot/site.py in callee(self, *args, **kwargs)
   1318             else:
   1319                 raise Exception('Not implemented')
-> 1320             return fn(self, *args, **kwargs)
   1321 
   1322         if not __debug__:

/srv/paws/pwb/pywikibot/site.py in editpage(self, page, summary, minor, notminor, bot, recreate, createonly, nocreate, watch, **kwargs)
   5265             while True:
   5266                 try:
-> 5267                     result = req.submit()
   5268                     pywikibot.debug('editpage response: %s' % result,
   5269                                     _logger)

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   1975 
   1976             if self.throttle:
-> 1977                 self.site.throttle(write=self.write)
   1978             else:
   1979                 pywikibot.log(

/srv/paws/pwb/pywikibot/throttle.py in __call__(self, requestsize, write)
    276             self.next_multiplicity = math.log(1 + requestsize) / math.log(2.0)
    277 
--> 278             self.wait(wait)
    279 
    280             if write:

/srv/paws/pwb/pywikibot/throttle.py in wait(self, seconds)
    254             pywikibot.log(message)
    255 
--> 256         time.sleep(seconds)
    257 
    258     def __call__(self, requestsize=1, write=False):

KeyboardInterrupt: