本文整理汇总了Python中wikipedia.handleArgs函数的典型用法代码示例。如果您正苦于以下问题:Python handleArgs函数的具体用法?Python handleArgs怎么用?Python handleArgs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了handleArgs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
'''
The main loop
'''
wikipedia.handleArgs()
conn = None
cursor = None
(conn, cursor) = connectDatabase()
for templateTitle in getUncategorizedTemplates(cursor):
tagUncategorized(templateTitle)
示例2: main
def main():
'''
The main loop
'''
wikipedia.handleArgs()
conn = None
cursor = None
(conn, cursor) = connectDatabase()
imageList = getImagesToNowcommons(cursor)
for (wImage, cImage, timestamp) in imageList:
tagNowCommons(unicode(wImage, 'utf-8'), unicode(cImage, 'utf-8'), timestamp)
示例3: main
def main():
#page generator
gen = None
# If the user chooses to work on a single page, this temporary array is
# used to read the words from the page title. The words will later be
# joined with spaces to retrieve the full title.
pageTitle = []
# 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.
genFactory = pagegenerators.GeneratorFactory()
for arg in pywikibot.handleArgs():
if not genFactory.handleArg(arg):
pageTitle.append(arg)
if pageTitle:
# work on a single page
page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
gen = iter([page])
if not gen:
gen = genFactory.getCombinedGenerator()
if not gen:
pywikibot.showHelp('inline_images')
else:
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = InlineImagesRobot(preloadingGen)
bot.run()
示例4: main
def main():
operation = None
argsList = []
namespaces = []
for arg in wikipedia.handleArgs():
if arg == '-count':
operation = "Count"
elif arg == '-list':
operation = "List"
elif arg.startswith('-namespace:'):
try:
namespaces.append(int(arg[len('-namespace:'):]))
except ValueError:
namespaces.append(arg[len('-namespace:'):])
else:
argsList.append(arg)
if operation == None:
wikipedia.showHelp('templatecount')
else:
robot = TemplateCountRobot()
if not argsList:
argsList = ['ref', 'note', 'ref label', 'note label']
if operation == "Count":
robot.countTemplates(argsList, namespaces)
elif operation == "List":
robot.listTemplates(argsList, namespaces)
示例5: main
def main(*args):
# Disable cosmetic changes because we don't want to modify any page
# content, so that we don't flood the histories with minor changes.
config.cosmetic_changes = False
#page generator
gen = None
genFactory = pagegenerators.GeneratorFactory()
redirs = False
# If the user chooses to work on a single page, this temporary array is
# used to read the words from the page title. The words will later be
# joined with spaces to retrieve the full title.
pageTitle = []
for arg in pywikibot.handleArgs(*args):
if genFactory.handleArg(arg):
continue
if arg == '-redir':
redirs = True
else:
pageTitle.append(arg)
gen = genFactory.getCombinedGenerator()
if not gen:
if pageTitle:
# work on a single page
page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
gen = iter([page])
else:
pywikibot.showHelp()
return
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = TouchBot(preloadingGen, redirs)
bot.run()
示例6: main
def main():
countrycode = u''
# Connect database, we need that
(conn, cursor) = connectDatabase()
(conn2, cursor2) = connectDatabase2()
generator = None
genFactory = pagegenerators.GeneratorFactory()
for arg in wikipedia.handleArgs():
if arg.startswith('-countrycode:'):
countrycode = arg [len('-countrycode:'):]
lang = wikipedia.getSite().language()
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
if countrycode:
if not mconfig.countries.get((countrycode, lang)):
wikipedia.output(u'I have no config for countrycode "%s" in language "%s"' % (countrycode, lang))
return False
wikipedia.output(u'Working on countrycode "%s" in language "%s"' % (countrycode, lang))
locateCountry(countrycode, lang, mconfig.countries.get((countrycode, lang)), conn, cursor, conn2, cursor2)
else:
for (countrycode, lang), countryconfig in mconfig.countries.iteritems():
if not countryconfig.get('autoGeocode'):
wikipedia.output(u'"%s" in language "%s" is not supported in auto geocode mode (yet).' % (countrycode, lang))
else:
wikipedia.output(u'Working on countrycode "%s" in language "%s"' % (countrycode, lang))
locateCountry(countrycode, lang, countryconfig, conn, cursor, conn2, cursor2)
示例7: main
def main(args):
'''
Main loop. Get a generator and options. Work on all images in the generator.
'''
generator = None
onlyFilter = False
onlyUncat = False
genFactory = pagegenerators.GeneratorFactory()
global search_wikis
global hint_wiki
site = pywikibot.getSite(u'commons', u'commons')
pywikibot.setSite(site)
for arg in pywikibot.handleArgs():
if arg == '-onlyfilter':
onlyFilter = True
elif arg == '-onlyuncat':
onlyUncat = True
elif arg.startswith('-hint:'):
hint_wiki = arg [len('-hint:'):]
elif arg.startswith('-onlyhint'):
search_wikis = arg [len('-onlyhint:'):]
else:
genFactory.handleArg(arg)
generator = genFactory.getCombinedGenerator()
if not generator:
generator = pagegenerators.CategorizedPageGenerator(
catlib.Category(site, u'Category:Media needing categories'),
recurse=True)
initLists()
categorizeImages(generator, onlyFilter, onlyUncat)
pywikibot.output(u'All done')
示例8: main
def main():
global always
always = False
for arg in pywikibot.handleArgs():
if arg == '-always':
always = True
mysite = pywikibot.getSite()
# If anything needs to be prepared, you can do it here
template_image = pywikibot.translate(pywikibot.getSite(),
template_to_the_image)
template_user = pywikibot.translate(pywikibot.getSite(),
template_to_the_user)
except_text_translated = pywikibot.translate(pywikibot.getSite(),
except_text)
basicgenerator = pagegenerators.UnusedFilesGenerator()
generator = pagegenerators.PreloadingGenerator(basicgenerator)
for page in generator:
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% page.title())
if except_text_translated not in page.getImagePageHtml() and \
'http://' not in page.get():
pywikibot.output(u'\n' + page.title())
if template_image in page.get():
pywikibot.output(u"%s done already" % page.aslink())
continue
appendtext(page, u"\n\n"+template_image)
uploader = page.getFileVersionHistory().pop()[1]
usertalkname = u'User Talk:%s' % uploader
usertalkpage = pywikibot.Page(mysite, usertalkname)
msg2uploader = template_user % {'title': page.title()}
appendtext(usertalkpage, msg2uploader)
示例9: main
def main():
# If debug is True, don't edit pages, but only show what would have been
# changed.
debug = False
# The AfD log that should be treated.
date = None
# Whether to confirm edits.
always = False
# Parse command line arguments
for arg in wikipedia.handleArgs():
if arg.startswith('-debug'):
wikipedia.output(u'Debug mode.')
debug = True
elif arg.startswith('-date'):
if len(arg) == 5:
date = wikipedia.input(u'Please enter the date of the log that should be treated (yyyymmdd):')
else:
date = arg[6:]
elif arg.startswith('-always'):
always = True
if date:
page_title = u'Wikipedia:Te verwijderen pagina\'s/Toegevoegd %s' % date
else:
page_title = u'Wikipedia:Te verwijderen pagina\'s/Toegevoegd %s' % time.strftime("%Y%m%d", time.localtime(time.time()-60*60*24))
wikipedia.output(u'Checking: %s.' % page_title)
page = wikipedia.Page(wikipedia.getSite(code = 'nl', fam = 'wikipedia'), page_title)
bot = AfDBot(page, always, debug)
bot.run()
示例10: main
def main(args):
'''
Grab a bunch of images and tag them if they are not categorized.
'''
generator = None
genFactory = pagegenerators.GeneratorFactory()
site = pywikibot.getSite(u'commons', u'commons')
pywikibot.setSite(site)
for arg in pywikibot.handleArgs():
if arg.startswith('-yesterday'):
generator = uploadedYesterday(site)
elif arg.startswith('-recentchanges'):
generator = recentChanges(site=site, delay=120)
else:
genFactory.handleArg(arg)
if not generator:
generator = genFactory.getCombinedGenerator()
if not generator:
pywikibot.output(
u'You have to specify the generator you want to use for the program!')
else:
pregenerator = pagegenerators.PreloadingGenerator(generator)
for page in pregenerator:
if page.exists() and (page.namespace() == 6) \
and (not page.isRedirectPage()) :
if isUncat(page):
addUncat(page)
示例11: main
def main():
oldImage = None
newImage = None
summary = ''
always = False
loose = False
# read command line parameters
for arg in pywikibot.handleArgs():
if arg == '-always':
always = True
elif arg == '-loose':
loose = True
elif arg.startswith('-summary'):
if len(arg) == len('-summary'):
summary = pywikibot.input(u'Choose an edit summary: ')
else:
summary = arg[len('-summary:'):]
else:
if oldImage:
newImage = arg
else:
oldImage = arg
if not oldImage:
pywikibot.showHelp('image')
else:
mysite = pywikibot.getSite()
ns = mysite.image_namespace()
oldImagePage = pywikibot.ImagePage(mysite, ns + ':' + oldImage)
gen = pagegenerators.FileLinksGenerator(oldImagePage)
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = ImageRobot(preloadingGen, oldImage, newImage, summary, always,
loose)
bot.run()
示例12: main
def main(args):
"""
Main loop. Get a generator and options.
"""
generator = None
parent = u""
basename = u""
always = False
genFactory = pagegenerators.GeneratorFactory()
for arg in pywikibot.handleArgs():
if arg == "-always":
always = True
elif arg.startswith("-parent:"):
parent = arg[len("-parent:") :].strip()
elif arg.startswith("-basename"):
basename = arg[len("-basename:") :].strip()
else:
genFactory.handleArg(arg)
generator = genFactory.getCombinedGenerator()
if generator:
for page in generator:
createCategory(page, parent, basename)
else:
pywikibot.output(u"No pages to work on")
pywikibot.output(u"All done")
示例13: main
def main():
global autonomous
global replace, replacealways, replaceloose, replaceonly
global use_hash
autonomous = False
replace = False
replacealways = False
replaceloose = False
replaceonly = False
use_hash = False
for arg in pywikibot.handleArgs():
if arg == '-autonomous':
autonomous = True
if arg == '-replace':
replace = True
if arg == '-replacealways':
replace = True
replacealways = True
if arg == '-replaceloose':
replaceloose = True
if arg == '-replaceonly':
replaceonly = True
if arg == '-hash':
use_hash = True
bot = NowCommonsDeleteBot()
bot.run()
示例14: main
def main():
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
bigcategory = u''
target = u''
generator = None
for arg in wikipedia.handleArgs():
if arg.startswith('-page'):
if len(arg) == 5:
generator = [wikipedia.Page(wikipedia.getSite(), wikipedia.input(u'What page do you want to use?'))]
else:
generator = [wikipedia.Page(wikipedia.getSite(), arg[6:])]
elif arg.startswith('-bigcat'):
if len(arg) == 7:
bigcategory = wikipedia.input(u'What category do you want to split out?')
else:
bigcategory = arg[8:]
elif arg.startswith('-target'):
if len(arg) == 7:
target = wikipedia.input(u'What category is the target category?')
else:
target = arg[8:]
if not bigcategory==u'':
splitOutCategory(bigcategory, target)
else:
if not generator:
generator = pagegenerators.NamespaceFilterPageGenerator(pagegenerators.ReferringPageGenerator(wikipedia.Page(wikipedia.getSite(), u'Template:Intersect categories'), onlyTemplateInclusion=True), [14])
for cat in generator:
intersectCategories(cat)
示例15: main
def main():
'''
The main loop
'''
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
conn = None
cursor = None
(conn, cursor) = connectDatabase()
imagerecat.initLists()
generator = None;
genFactory = pagegenerators.GeneratorFactory()
mark = True
for arg in wikipedia.handleArgs():
if arg.startswith('-dontmark'):
mark = False
elif arg.startswith('-page'):
if len(arg) == 5:
generator = [wikipedia.Page(wikipedia.getSite(), wikipedia.input(u'What page do you want to use?'))]
else:
generator = [wikipedia.Page(wikipedia.getSite(), arg[6:])]
elif arg.startswith('-yesterday'):
generator = [wikipedia.Page(wikipedia.getSite(), u'Category:Media_needing_categories_as_of_' + getYesterday())]
else:
generator = genFactory.handleArg(arg)
if generator:
for page in generator:
if((page.namespace() == 14) and (page.title().startswith(u'Category:Media needing categories as of'))):
wikipedia.output(u'Working on ' + page.title())
for (image, gals, cats) in getImagesToCategorize(cursor, page.titleWithoutNamespace()):
categorizeImage(image, gals, imagerecat.applyAllFilters(cats))
if (mark):
categoriesChecked(page.title())