本文整理汇总了Python中pywikibot.handle_args函数的典型用法代码示例。如果您正苦于以下问题:Python handle_args函数的具体用法?Python handle_args怎么用?Python handle_args使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了handle_args函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
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
"""
# Generate the question text
questions = '\n'
questionlist = {}
pywikibot.handle_args(*args)
site = pywikibot.Site()
if (site.lang not in list(templates.keys()) and
site.lang not in list(done.keys())):
pywikibot.output(
'\nScript is not localised for {0}. Terminating program.'
''.format(site))
else:
for i, t in enumerate(pywikibot.translate(site.lang, templates)):
questions += (u'%s) %s\n' % (i, t))
questionlist[i] = t
bot = CleaningBot(questions, questionlist)
bot.run()
示例2: main
def main(args):
letter = None
force_dump = False
bot_args = []
for arg in args:
print('\u05D0'.encode('utf-8'))
#print(arg.decode('utf-8'))
l = re.compile(r'^-letter:(.+)$').match(arg)
print(l)
if l:
letter = l.group(1)
elif arg == '--get-dump':
force_dump = True # download the latest dump if it doesnt exist
else:
bot_args.append(arg)
print(bot_args)
pywikibot.handle_args(bot_args)
site = pywikibot.Site('he', 'wiktionary')
if force_dump \
or not os.path.exists(DUMP_FILE) \
or file_age_by_days(DUMP_FILE) > 30:
get_dump()
all_wiktionary = XmlDump(DUMP_FILE).parse()
all_wiktionary = filter(lambda page: page.ns == '0' \
and not page.title.endswith('(שורש)') \
and not re.compile(r'[a-zA-Z]').search(page.title) \
and (not letter or page.title.startswith(letter))
and not page.isredirect,
all_wiktionary)
gen = (pywikibot.Page(site, p.title) for p in all_wiktionary)
gen = pagegenerators.PreloadingGenerator(gen)
words = []
for page in gen:
if not page.exists() or page.isRedirectPage():
continue
for lex in hewiktionary.lexeme_title_regex_grouped.findall(page.get()):
words.append("* [[%s#%s|%s]]" % (page.title(),lex,lex))
report_content = 'סך הכל %s ערכים\n' % str(len(words))
report_content += '\n'.join(['%s' % p for p in words])
report_content += "\n\n[[קטגוריה: ויקימילון - תחזוקה]]"
if letter:
report_page = pywikibot.Page(site, 'ויקימילון:תחזוקה/%s/%s' % ('רשימת_כל_המילים',letter))
else:
report_page = pywikibot.Page(site, 'ויקימילון:תחזוקה/%s' % ('רשימת_כל_המילים'))
report_page.text = report_content
report_page.save("סריקה עם בוט ")
示例3: main
def main(*args):
"""Script entry point."""
env = None
if args:
import pywikibot
pywikibot.handle_args(args)
env = locals()
import code
code.interact("""Welcome to the Pywikibot interactive shell!""", local=env)
示例4: main
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
"""
gen = None
options = {}
# Process global args and prepare generator args parser
local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
bot_class = TouchBot
for arg in local_args:
if arg == '-purge':
bot_class = PurgeBot
elif arg == '-redir':
pywikibot.output(u'-redirect option is deprecated, '
'do not use it anymore.')
elif not genFactory.handleArg(arg) and arg.startswith("-"):
options[arg[1:].lower()] = True
gen = genFactory.getCombinedGenerator()
if gen:
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = bot_class(generator=preloadingGen, **options)
pywikibot.Site().login()
bot.run()
else:
pywikibot.showHelp()
示例5: main
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
"""
local_args = pywikibot.handle_args(args)
start = local_args[0] if local_args else '!'
mysite = pywikibot.Site()
try:
mysite.disambcategory()
except pywikibot.Error as e:
pywikibot.bot.suggest_help(exception=e)
return False
generator = pagegenerators.CategorizedPageGenerator(
mysite.disambcategory(), start=start, content=True, namespaces=[0])
bot = DisambiguationRedirectBot(generator=generator)
bot.run()
示例6: main
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
"""
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(u'{0:d} pages in the watchlist.'.format(len(watchlist)))
for page in watchlist:
try:
pywikibot.stdout(page.title())
except pywikibot.InvalidTitle:
pywikibot.exception()
示例7: main
def main(*args):
generator = None
local_args = pywikibot.handle_args(args)
site = pywikibot.Site()
if str(site) != "commons:commons":
pywikibot.warning("The script has not been tested on sites other that "
"commons:commons.")
gen_factory = pagegenerators.GeneratorFactory(site)
for local_arg in local_args:
if gen_factory.handleArg(local_arg):
continue
arg, sep, value = local_arg.partition(':')
if arg in ('-showcats',):
options[arg[1:]] = True
else:
raise ValueError('Unknown argument: ' + local_arg)
generator = gen_factory.getCombinedGenerator(gen=generator)
if not generator:
pywikibot.bot.suggest_help(missing_generator=True)
else:
pregenerator = pagegenerators.PreloadingGenerator(generator)
for i, page in enumerate(pregenerator):
if page.exists():
log = handle_page(page)
pywikibot.output('\n'.join(log))
pywikibot.output("")
示例8: main
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
"""
local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
options = {}
for arg in local_args:
if genFactory.handleArg(arg):
continue
option, sep, value = arg.partition(':')
option = option[1:] if option.startswith('-') else None
if option == 'summary':
options[option] = value
else:
options[option] = True
site = pywikibot.Site()
generator = genFactory.getCombinedGenerator()
if generator:
generator = pagegenerators.PreloadingGenerator(generator)
bot = IWBot(generator=generator, site=site, **options)
bot.run()
else:
suggest_help(missing_generator=True)
return False
示例9: main
def main(*args):
# Process global args and prepare generator args parser
local_args = pywikibot.handle_args(args)
googlecat = False
collectionid = False
for arg in local_args:
if arg.startswith('-googlecat'):
if len(arg) == 10:
googlecat = pywikibot.input(
u'Please enter the category you want to work on:')
else:
googlecat = arg[11:]
elif arg.startswith('-collectionid'):
if len(arg) == 13:
collectionid = pywikibot.input(
u'Please enter the collectionid you want to work on:')
else:
collectionid = arg[14:]
#else:
# generator_factory.handleArg(arg)
if googlecat and collectionid:
imageFindBot = ImageFindBot(googlecat, collectionid)
imageFindBot.run()
else:
pywikibot.output(u'Usage: pwb.py add_google_images.py -googlecat:<category name> -collectionid:Q<123>')
示例10: main
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
"""
# Process global args and prepare generator args parser
local_args = pywikibot.handle_args(args)
gen = pagegenerators.GeneratorFactory()
options = {}
for arg in local_args:
if (
arg.startswith('-pageage:') or
arg.startswith('-lastedit:')):
key, val = arg.split(':', 1)
options[key[1:]] = int(val)
elif gen.handleArg(arg):
pass
else:
options[arg[1:].lower()] = True
generator = gen.getCombinedGenerator()
if not generator:
pywikibot.bot.suggest_help(missing_generator=True)
return False
bot = NewItemRobot(generator, **options)
bot.run()
return True
示例11: main
def main(*args):
"""
Do a query and have the bot process the items
:param args:
:return:
"""
# The queries for paintings without a creator, all or a specific collection
query = u'SELECT ?item WHERE { ?item wdt:P31 wd:Q3305213 . MINUS { ?item wdt:P170 [] } }'
querycollection = u"""SELECT ?item WHERE { ?item wdt:P31 wd:Q3305213 .
?item wdt:P195 wd:%s .
MINUS { ?item wdt:P170 [] }
}"""
for arg in pywikibot.handle_args(args):
print arg
if arg.startswith('-collectionid'):
if len(arg) == 13:
collectionid = pywikibot.input(
u'Please enter the collectionid you want to work on:')
else:
collectionid = arg[14:]
query = querycollection % (collectionid,)
repo = pywikibot.Site().data_repository()
generator = pagegenerators.PreloadingItemGenerator(pagegenerators.WikidataSPARQLPageGenerator(query, site=repo))
paintingBot = PaintingBot(generator, change=False)
paintingBot.run()
示例12: main
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
"""
options = {}
total = None
local_args = pywikibot.handle_args(args)
for arg in local_args:
arg, sep, value = arg.partition(':')
if arg == '-total':
total = value
else:
options[arg[1:]] = True
site = pywikibot.Site()
gen = pagegenerators.UnusedFilesGenerator(total=total, site=site)
gen = pagegenerators.PreloadingGenerator(gen)
bot = UnusedFilesBot(site, generator=gen, **options)
try:
bot.run()
except pywikibot.Error as e:
pywikibot.bot.suggest_help(exception=e)
return False
else:
return True
示例13: main
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
"""
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()
refresh(site, sysop=sysop)
watchlist = get(site)
pywikibot.output(u'%i pages in the watchlist.' % len(watchlist))
for pageName in watchlist:
pywikibot.output(pageName, toStdout=True)
示例14: main
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
"""
options = {}
local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
for arg in local_args:
if arg == '-always':
options['always'] = True
elif arg == '-titlecase':
options['titlecase'] = True
else:
genFactory.handleArg(arg)
gen = genFactory.getCombinedGenerator()
if gen:
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = CapitalizeBot(preloadingGen, **options)
bot.run()
return True
else:
pywikibot.bot.suggest_help(missing_generator=True)
return False
示例15: main
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
"""
# Process global arguments to determine desired site
local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
# If dry is True, doesn't do any real changes, but only show
# what would have been changed.
dry = False
targetpagesingles = u''
targetpagedoubles = u''
url = u''
# Parse command line arguments
for arg in local_args:
if arg.startswith("-dry"):
dry = True
if arg.startswith("-targetpagesingles"):
targetpagesingles = arg[len('-targetpagesingles:'):]
if arg.startswith("-targetpagedoubles"):
targetpagedoubles = arg[len('-targetpagedoubles:'):]
if arg.startswith("-url"):
url = arg[len('-url:'):]
else:
genFactory.handleArg(arg)
bot = StaticBot(dry, targetpagesingles, targetpagedoubles, url)
bot.run()