本文整理汇总了Python中wikipedia.stopme函数的典型用法代码示例。如果您正苦于以下问题:Python stopme函数的具体用法?Python stopme怎么用?Python stopme使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stopme函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: abort
def abort(self, status = u'Ok', msg = None):
log = u'Bot aborted with status: '+status
if msg:
log += u' and message: '+msg
self.log(log)
wikipedia.stopme()
exit(1)
示例2: checktalk
def checktalk():
site = wikipedia.getSite()
path = site.put_address('Non-existing_page')
text = site.getUrl(path)
if '<div class="usermessage">' in text:
wikipedia.output(u'NOTE: You have unread messages on %s' % site)
wikipedia.stopme()
sys.exit()
示例3: Import
def Import(self, target, project = 'w', crono = '1', namespace = '', prompt = True):
"""Import the page from the wiki. Requires administrator status.
If prompt is True, asks the user if he wants to delete the page.
"""
# Fixing the crono value...
if crono == True:
crono = '1'
elif crono == False:
crono = '0'
elif crono == '0':
pass
elif crono == '1':
pass
else:
wikipedia.output(u'Crono value set wrongly.')
wikipedia.stopme()
# Fixing namespace's value.
if namespace == '0':
namespace == ''
answer = 'y'
if prompt:
answer = wikipedia.inputChoice(u'Do you want to import %s?' % target, ['Yes', 'No'], ['y', 'N'], 'N')
if answer in ['y', 'Y']:
host = self.site().hostname()
address = '/w/index.php?title=%s&action=submit' % self.urlname()
# You need to be a sysop for the import.
self.site().forceLogin(sysop = True)
# Getting the token.
token = self.site().getToken(self, sysop = True)
# Defing the predata.
predata = {
'action' : 'submit',
'source' : 'interwiki',
# from what project do you want to import the page?
'interwiki' : project,
# What is the page that you want to import?
'frompage' : target,
# The entire history... or not?
'interwikiHistory' : crono,
# What namespace do you want?
'namespace': '',
}
if self.site().hostname() in config.authenticate.keys():
predata['Content-type'] = 'application/x-www-form-urlencoded'
predata['User-agent'] = useragent
data = self.site().urlEncode(predata)
response = urllib2.urlopen(urllib2.Request('http://' + self.site().hostname() + address, data))
data = u''
else:
response, data = self.site().postForm(address, predata, sysop = True)
if data:
wikipedia.output(u'Page imported, checking...')
if wikipedia.Page(site, target).exists():
wikipedia.output(u'Import success!')
return True
else:
wikipedia.output(u'Import failed!')
return False
示例4: main
def main():
summary_commandline,template,gen = None,None,None
exceptions,PageTitles,namespaces = [],[],[]
cat=''
autoText,autoTitle = False,False
genFactory = pagegenerators.GeneratorFactory()
arg=False#------if you dont want to work with arguments leave it False if you want change it to True---
if arg==False:
for arg in wikipedia.handleArgs():
if arg == '-autotitle':
autoTitle = True
elif arg == '-autotext':
autoText = True
elif arg.startswith( '-page:' ):
if len(arg) == 6:
PageTitles.append(wikipedia.input( u'Which page do you want to chage?' ))
else:
PageTitles.append(arg[6:])
elif arg.startswith( '-cat:' ):
if len(arg) == 5:
cat=wikipedia.input( u'Which Category do you want to chage?' )
else:
cat='Category:'+arg[5:]
elif arg.startswith( '-template:' ):
if len(arg) == 10:
template.append(wikipedia.input( u'Which Template do you want to chage?' ))
else:
template.append('Template:'+arg[10:])
elif arg.startswith('-except:'):
exceptions.append(arg[8:])
elif arg.startswith( '-namespace:' ):
namespaces.append( int( arg[11:] ) )
elif arg.startswith( '-ns:' ):
namespaces.append( int( arg[4:] ) )
elif arg.startswith( '-summary:' ):
wikipedia.setAction( arg[9:] )
summary_commandline = True
else:
generator = genFactory.handleArg(arg)
if generator:
gen = generator
else:
PageTitles = [raw_input(u'Page:> ').decode('utf-8')]
if cat!='':
facatfalist=facatlist(cat)
if facatfalist!=False:
run(facatfalist)
if PageTitles:
pages = [wikipedia.Page(faSite,PageTitle) for PageTitle in PageTitles]
gen = iter( pages )
if not gen:
wikipedia.stopme()
sys.exit()
if namespaces != []:
gen = pagegenerators.NamespaceFilterPageGenerator( gen,namespaces )
preloadingGen = pagegenerators.PreloadingGenerator( gen,pageNumber = 60 )#---number of pages that you want load at same time
run(preloadingGen)
示例5: main
def main():
site = pywikibot.getSite('en', 'wikipedia')
prefix = 'Uw-'
ns = 10
for p in site.prefixindex(prefix, namespace=ns):
print p.title()
pywikibot.stopme()
示例6: delTestPage
def delTestPage(pagename):
myuserpage = u"ഉപയോക്താവ്:" + 'Manubot'
mypage = myuserpage + "/BotLabs/test" + pagename
# doing the job
site = wikipedia.getSite('ml','wikipedia')
page = wikipedia.Page(site,mypage)
page.delete(reason='Deleting Test pages', prompt=False, throttle=True, mark=True)
wikipedia.stopme()
示例7: shutoffcheck
def shutoffcheck(self):
return # Not implemented
print u'Checking emergency shutoff page %s.' % self.shutoffpage.title(asLink=True)
self.shutoffpagetext = self.shutoffpage.get()
if unicode(self.shutoffpagetext.strip()) != u'enable':
print u'Emergency shutoff enabled; stopping.'
pywikibot.stopme()
exit()
else:
print u'Emergency shutoff disabled; continuing.'
示例8: shutoffcheck
def shutoffcheck():
site = wikipedia.getSite()
pagename = "User:Hazard-Bot/Check/Wikiproject"
page = wikipedia.Page(site, pagename)
print "Checking [[" + pagename + "]]for emergency shutoff."
text = page.get()
if text.lower() != 'enable':
print "Emergency shutoff enabled; stopping."
wikipedia.stopme()
exit()
print "Emergency shutoff disabled; continuing."
示例9: udate2wiki
def udate2wiki(pagename=u'ഉപയോക്താവ്:Manubot/sandbox',towiki=True):
global gpageData
if towiki:
site = wikipedia.getSite('ml','wikipedia')
page = wikipedia.Page(site,pagename)
page.put(gpageData,u'ബോട്ടിന്റെ കൂന്തി വിളയാട്ടം')
wikipedia.stopme()
else:
f = codecs.open(pagename+u'.txt',encoding='utf-8', mode='w')
f.write(gpageData)
f.close()
示例10: main
def main(*args):
global bot
try:
a = pywikibot.handleArgs(*args)
if len(a) == 1:
raise RuntimeError('Unrecognized argument "%s"' % a[0])
elif a:
raise RuntimeError("Unrecognized arguments: " + " ".join(('"%s"' % arg) for arg in a))
bot = CategoryRedirectBot()
bot.run()
finally:
pywikibot.stopme()
示例11: main
def main():
summary_commandline,gen,template = None,None,None
namespaces,PageTitles,exceptions = [],[],[]
encat=''
autoText,autoTitle = False,False
recentcat,newcat=False,False
genFactory = pagegenerators.GeneratorFactory()
for arg in wikipedia.handleArgs():
if arg == '-autotitle':
autoTitle = True
elif arg == '-autotext':
autoText = True
elif arg.startswith( '-except:' ):
exceptions.append( arg[8:] )
elif arg.startswith('-start'):
firstPageTitle = arg[7:]
if not firstPageTitle:
firstPageTitle = wikipedia.input(
u'At which page do you want to start?')
firstPageTitle = wikipedia.Page(fasite,firstPageTitle).title(withNamespace=False)
gen = pagegenerators.AllpagesPageGenerator(firstPageTitle, 0,
includeredirects=True)
elif arg.startswith( '-template:' ):
template = arg[10:]
elif arg.startswith( '-namespace:' ):
namespaces.append( int( arg[11:] ) )
elif arg.startswith( '-summary:' ):
wikipedia.setAction( arg[9:] )
summary_commandline = True
else:
generator = genFactory.handleArg( arg )
if generator:
gen = generator
if not gen:
wikipedia.stopme()
sys.exit()
if namespaces != []:
gen = pagegenerators.PreloadingGenerator(gen,pageNumber = 60)
preloadingGen = pagegenerators.NamespaceFilterPageGenerator( gen,namespaces )
else:
preloadingGen = pagegenerators.PreloadingGenerator(gen,pageNumber = 60)
_cache,last_timestamp=get_cache()
add_text(preloadingGen)
now = str(datetime.now())
todaynum=int(now.split('-')[2].split(' ')[0])+int(now.split('-')[1])*30+(int(now.split('-')[0])-2000)*365
if last_timestamp+3 < todaynum:
put_cache(_cache,todaynum)
else:
put_cache({},0)
示例12: post
def post(unlock = True):
"""
This function removes throttle file. It also removes lockfile unless
unlock variable is set to False
"""
if unlock and lockfile:
try:
os.remove(lockfile)
except OSError:
error(u"Unable to remove lockfile.")
pywikibot.output(u"The script " + fullname + u". Stop at " + getTime())
pywikibot.stopme()
sys.exit()
示例13: getInfobox
def getInfobox(film):
info_box_data = []
if type(film).__name__ == 'str' or type(film).__name__ == 'unicode':
site = wikipedia.getSite('en','wikipedia') # Taking the default site
page = wikipedia.Page(site, film) # Calling the constructor
if page.isRedirectPage():
page = page.getRedirectTarget()
else:
page = film
page_data = page.get()
#print page_data
page_data = page_data.split(u'\n')
info_box = 0
#remove the |
r = re.compile(r'^\s*\|\s*',re.UNICODE)
info_re = re.compile(r'\s*{{\s*Infobox\s*film\s*',re.IGNORECASE|re.UNICODE)
#remove spaces
r1 = re.compile(r'\s*=\s*',re.UNICODE)
#remove comments
#r2 = re.compile(r'<!--.*-->')
#Get the info box data
for line in page_data:
if len(line) == 0:
continue
if info_re.search(line) and info_box == 0:
print 'Found infobox'
info_box = 1
elif line == u'}}' or line == u'|}}' and info_box ==1:
info_box = 0
break
elif info_box == 1:
#remove unnecessary data
line = r.sub('',line)
#line = r2.sub('',line)
line = r1.sub('=',line)
print line
info_box_data.append(line)
else:
pass
#update in dictionary
for i in info_box_data:
info_box_dict[i.split(u'=',1)[0].strip()] = i.split(u'=',1)[1].strip()
#print info_box_data
#print info_box_dict
wikipedia.stopme()
示例14: udate2wiki
def udate2wiki(pagename=u'',towiki=True):
global data
if towiki:
myuserpage = u"ഉപയോക്താവ്:" + 'Manubot'
mypage = myuserpage + "/BotLabs/" + (pagename)
# doing the job
site = wikipedia.getSite('ml','wikipedia')
page = wikipedia.Page(site,mypage)
page.put(data,u'ബോട്ടിന്റെ കൂന്തി വിളയാട്ടം')
wikipedia.stopme()
else:
f = codecs.open(pagename+u'.txt',encoding='utf-8', mode='w')
f.write(data)
f.close()
示例15: main
def main(*args):
try:
genFactory = GeneratorFactory()
for arg in pywikibot.handleArgs():
if not genFactory.handleArg(arg):
pywikibot.showHelp('pagegenerators')
break
else:
gen = genFactory.getCombinedGenerator()
if gen:
i = 0
for page in gen:
i+=1
pywikibot.output("%4d: %s" % (i, page.title()), toStdout = True)
else:
pywikibot.showHelp('pagegenerators')
finally:
pywikibot.stopme()