Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_options(self, *args):
"""Parse commandline and set options attribute."""
my_args = pywikibot.handle_args(args)
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-r', '--edit_redirect', '--edit-redirect',
action='store_true', help='Ignore/edit redirects')
parser.add_argument('-p', '--page', help='Page to edit')
parser.add_argument('-w', '--watch', action='store_true',
help='Watch article after edit')
# convenience positional argument so we can act like a normal editor
parser.add_argument('wikipage', nargs='?', help='Page to edit')
self.options = parser.parse_args(my_args)
if self.options.page and self.options.wikipage:
pywikibot.error('Multiple pages passed. Please specify a single '
'page to edit.')
sys.exit(1)
self.options.page = self.options.page or self.options.wikipage
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: unicode
@rtype: bool
"""
exists_arg = ''
commandline_claims = []
# Process global args and prepare generator args parser
local_args = pywikibot.handle_args(args)
gen = pagegenerators.GeneratorFactory()
for arg in local_args:
# Handle args specifying how to handle duplicate claims
if arg.startswith('-exists:'):
exists_arg = arg.split(':')[1]
continue
# Handle page generator args
if gen.handleArg(arg):
continue
commandline_claims.append(arg)
if len(commandline_claims) % 2:
pywikibot.error('Incomplete command line property-value pair.')
return False
claims = []
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: unicode
"""
# This temporary string is used to read the title
# of the page that should be unlinked.
page_title = None
options = {}
for arg in pywikibot.handle_args(args):
if arg.startswith('-namespace:'):
if 'namespaces' not in options:
options['namespaces'] = []
try:
options['namespaces'].append(int(arg[11:]))
except ValueError:
options['namespaces'].append(arg[11:])
elif arg == '-always':
options['always'] = True
else:
page_title = arg
if page_title:
page = pywikibot.Page(pywikibot.Site(), page_title)
bot = UnlinkBot(page, **options)
bot.run()
time_sleep = 30 # How many time sleep after the check?
skip_number = 0 # How many images to skip before checking?
waitTime = 0 # How many time sleep before the check?
commonsActive = False # Is there's an image with the same name at commons?
normal = False # Check the new images or use another generator?
urlUsed = False # Use the url-related function instead of the new-pages
regexGen = False # Use the regex generator
duplicatesActive = False # Use the duplicate option
duplicatesReport = False # Use the duplicate-report option
max_user_notify = None
sendemailActive = False # Use the send-email
logFullError = True # Raise an error when the log is full
generator = None
unknown = [] # unknown parameters
local_args = pywikibot.handle_args(args)
site = pywikibot.Site()
# Here below there are the local parameters.
for arg in local_args:
if arg.startswith('-limit'):
if len(arg) == 6:
limit = int(pywikibot.input(
'How many files do you want to check?'))
else:
limit = int(arg[7:])
elif arg.startswith(('-sleep', '-time')):
if arg.startswith('-sleep'):
length = len('-sleep')
else:
issue_deprecation_warning('-time', '-sleep', 2,
ArgumentDeprecationWarning,
since='20151209')
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: unicode
"""
options = {}
local_args = pywikibot.handle_args(args)
gen_factory = pagegenerators.GeneratorFactory()
for arg in local_args:
if arg == '-always':
options['always'] = True
elif arg == '-titlecase':
options['titlecase'] = True
else:
gen_factory.handleArg(arg)
gen = gen_factory.getCombinedGenerator(preload=True)
if gen:
bot = CapitalizeBot(gen, **options)
bot.run()
return True
else:
def main(*args):
"""Process command line arguments and invoke PatrolBot."""
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
# to work on.
usercontribs = None
gen = None
recentchanges = False
newpages = False
repeat = False
options = {}
# Parse command line arguments
local_args = pywikibot.handle_args(args)
site = pywikibot.Site()
gen_factory = pagegenerators.GeneratorFactory(site)
for arg in local_args:
if arg.startswith('-ask'):
options['ask'] = True
elif arg.startswith('-autopatroluserns'):
options['autopatroluserns'] = True
elif arg.startswith('-repeat'):
repeat = True
elif arg.startswith('-newpages'):
newpages = True
elif arg.startswith('-recentchanges'):
recentchanges = True
elif arg.startswith('-usercontribs:'):
usercontribs = arg[14:]
elif arg.startswith('-versionchecktime:'):
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: unicode
"""
operation = None
args_list = []
namespaces = []
for arg in pywikibot.handle_args(args):
if arg in ('-count', '-list'):
operation = arg[1:]
elif arg.startswith('-namespace:'):
try:
namespaces.append(int(arg[len('-namespace:'):]))
except ValueError:
namespaces.append(arg[len('-namespace:'):])
else:
args_list.append(arg)
if not operation:
pywikibot.bot.suggest_help(missing_parameters=['operation'])
return False
robot = TemplateCountRobot()
if not args_list:
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: unicode
"""
all = False
new = False
sysop = False
for arg in pywikibot.handle_args(args):
if arg in ('-all', '-update'):
all = True
elif arg == '-new':
new = True
elif arg == '-sysop':
sysop = True
if all:
refresh_all(sysop=sysop)
elif new:
refresh_new(sysop=sysop)
else:
site = pywikibot.Site()
watchlist = refresh(site, sysop=sysop)
pywikibot.output('{} pages in the watchlist.'.format(len(watchlist)))
for page in watchlist:
try:
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: unicode
"""
my_args = pywikibot.handle_args(args)
parser = ArgumentParser(add_help=False)
parser.add_argument('-r', '--replace', action='store_true',
help='actually replace pages (without this '
'option you will only get an overview page)')
parser.add_argument('-o', '--original', dest='original_wiki',
help='original wiki')
parser.add_argument('destination_wiki', metavar='destination',
type=str, nargs='+', help='destination wiki(s)')
parser.add_argument('-ns', '--namespace', dest='namespace',
help='specify namespace')
parser.add_argument('-dns', '--dest-namespace', dest='dest_namespace',
help='destination namespace (if different)')
options = parser.parse_args(my_args)
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: unicode
"""
local_args = pywikibot.handle_args(args)
# Get the api key
if not config.flickr['api_key']:
pywikibot.output('Flickr api key not found! Get yourself an api key')
pywikibot.output(
'Any flickr user can get a key at '
'https://www.flickr.com/services/api/keys/apply/')
return
if 'api_secret' in config.flickr and config.flickr['api_secret']:
flickr = flickrapi.FlickrAPI(config.flickr['api_key'],
config.flickr['api_secret'])
else:
pywikibot.output('Accessing public content only')
flickr = flickrapi.FlickrAPI(config.flickr['api_key'])