Wikipedia:Kothak Njajal

Sekang Wikipedia, Ensiklopedia Bebas sing nganggo Basa Banyumasan: dhialek Banyumas, Purbalingga, Tegal lan Purwokerto.
Mlumpat maring: navigasi, goleti
Sungeng teka nang kaca utawa halaman kanggo njajal gawe halaman utawa kaca nang Wikipedia.
  • Kanggo njajal, gunakna markah wiki, pencet Besut sumber nang duwur kaca iki.
  • Bar kothak sing nggo mbesut nongol, ketik apa bae sekarepmu lan bar ngetik pencet tombol "Simpan halaman" nangisor kothak pembesutan.
  • Perhatikna bahwa besutane rika wis dadi!

w uioi bune #!/usr/bin/python

  1. -*- coding: utf-8 -*-

""" This bot resets a (user) sandbox with predefined text.

This script understands the following command-line arguments:


Furthermore, the following command line parameters are supported:

   -hours:#       Use this parameter if to make the script repeat itself
                  after # hours. Hours can be defined as a decimal. 0.01
                  hours are 36 seconds; 0.1 are 6 minutes.
   -delay:#       Use this parameter for a wait time after the last edit
                  was made. If no parameter is given it takes it from
                  hours and limits it between 5 and 15 minutes.
                  The minimum delay time is 5 minutes.
   -text          The text that substitutes in the sandbox, you can use this
                  when you haven't configured clean_candbox for your wiki.
   -summary       Summary of the edit made by bot.


  1. (C) Leonardo Gregianin, 2006
  2. (C) Wikipedian, 2006-2007
  3. (C) Andre Engels, 2007
  4. (C) Siebrand Mazeland, 2007
  5. (C) xqt, 2009-2017
  6. (C) Dr. Trigon, 2012
  7. (C) Pywikibot team, 2012-2017
  8. Distributed under the terms of the MIT license.

from __future__ import absolute_import, division, unicode_literals

import datetime import time

import pywikibot

from pywikibot import i18n, Bot, pagegenerators

content = {

   'map-bms': u'Cithakan:Bakpasir\n',


sandbox_titles = ('Q38383602')

  1. This is required for the text that is shown when you run this script
  2. with the parameter -help.

docuReplacements = {

   '&params;': pagegenerators.parameterHelp,


class SandboxBot(Bot):

   """Sandbox reset bot."""
   availableOptions = {
       'hours': 1,
       'no_repeat': True,
       'delay': None,
       'delay_td': None,
       'text': "",
       'summary': "",
   def __init__(self, **kwargs):
       super(SandboxBot, self).__init__(**kwargs)
       if self.getOption('delay') is None:
           d = min(15, max(5, int(self.getOption('hours') * 60)))
           self.availableOptions['delay_td'] = datetime.timedelta(minutes=d)
           d = max(5, self.getOption('delay'))
           self.availableOptions['delay_td'] = datetime.timedelta(minutes=d) = pywikibot.Site()
       if not content.get( and not self.getOption('text'):
           pywikibot.error(u'No content is given for pages, exiting.')
           raise RuntimeError
       if not self.generator:
           pages = []
           for item in sandbox_titles:
               p =
               if p is not None:
           if not pages:
               raise RuntimeError
           self.generator = pages
   def run(self):
       """Run bot."""
       while True:
           wait = False
           now = time.strftime("%d %b %Y %H:%M:%S (UTC)", time.gmtime())
           for sandboxPage in self.generator:
               pywikibot.output(u'Preparing to process sandbox page %s'
                                % sandboxPage.title(asLink=True))
               if sandboxPage.isRedirectPage():
                       u'%s is a redirect page, cleaning it anyway'
                       % sandboxPage.title(asLink=True))
                   text = sandboxPage.text
                   if not self.getOption('text'):
                       translatedContent = i18n.translate(, content)
                       translatedContent = self.getOption('text')
                   if self.getOption('summary'):
                       translatedMsg = self.getOption('summary')
                       translatedMsg = i18n.twtranslate(
                 , 'clean_sandbox-cleaned')
                   subst = 'subst:' in translatedContent
                   pos = text.find(translatedContent.strip())
                   if text.strip() == translatedContent.strip():
                           u'The sandbox is still clean, no change necessary.')
                   elif subst and sandboxPage.userName() ==
                           u'The sandbox might be clean, no change necessary.')
                   elif pos != 0 and not subst:
                       sandboxPage.put(translatedContent, translatedMsg)
                       pywikibot.showDiff(text, translatedContent)
                       pywikibot.output(u'Standard content was changed, '
                                        u'sandbox cleaned.')
                       edit_delta = (datetime.datetime.utcnow() -
                       delta = self.getOption('delay_td') - edit_delta
                       # Is the last edit more than 'delay' minutes ago?
                       if delta <= datetime.timedelta(0):
                           sandboxPage.put(translatedContent, translatedMsg)
                           pywikibot.showDiff(text, translatedContent)
                           pywikibot.output(u'Standard content was changed, '
                                            u'sandbox cleaned.')
                       else:  # wait for the rest
                               u'Sandbox edited %.1f minutes ago...'
                               % (edit_delta.seconds / 60.0))
                           pywikibot.output(u'Sleeping for %d minutes.'
                                            % (delta.seconds // 60))
                           wait = True
               except pywikibot.EditConflict:
                       u'*** Loading again because of edit conflict.\n')
               except pywikibot.NoPage:
                       u'*** The sandbox is not existent, skipping.')
           if self.getOption('no_repeat'):
           elif not wait:
               if self.getOption('hours') < 1.0:
                   pywikibot.output('\nSleeping %s minutes, now %s'
                                    % ((self.getOption('hours') * 60), now))
                   pywikibot.output('\nSleeping %s hours, now %s'
                                    % (self.getOption('hours'), now))
               time.sleep(self.getOption('hours') * 60 * 60)

def main(*args):

   Process command line arguments and invoke bot.
   If args is an empty list, sys.argv is used.
   @param args: command line arguments
   @type args: list of unicode
   opts = {}
   local_args = pywikibot.handle_args(args)
   gen_factory = pagegenerators.GeneratorFactory()
   for arg in local_args:
       if arg.startswith('-hours:'):
           opts['hours'] = float(arg[7:])
           opts['no_repeat'] = False
       elif arg.startswith('-delay:'):
           opts['delay'] = int(arg[7:])
       elif arg.startswith('-text'):
           if len(arg) == 5:
               opts['text'] = pywikibot.input(
                   u'What text do you want to substitute?')
               opts['text'] = arg[6:]
       elif arg.startswith('-summary'):
           if len(arg) == len('-summary'):
               opts['summary'] = pywikibot.input(u'Enter the summary:')
               opts['summary'] = arg[9:]