rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
class Error(Exception): """Wikipedia error""" class NoPage(Error): """Wikipedia page does not exist""" class IsRedirectPage(Error): """Wikipedia page is a redirect page""" class IsNotRedirectPage(Error): """Wikipedia page is not a redirect page""" class LockedPage(Error): """Wikipedia page is locked""" class NoSuc...
def altlang(code): if code in ['fa','ku']: return ['ar'] if code=='sk': return ['cs'] if code=='nds': return ['de','nl'] if code in ['ca','gn','nah']: return ['es'] if code=='eu': return ['es','fr'] if code=='gl': return ['es','pt'] if code in ['br','oc','th','vi','wa']: return ['fr'] if code=='als': return ['fr','de']...
for alternative in altlang(code): if dict.has_key(alternative): return dict[alternative]
for alt in altlang(code): if dict.has_key(alt): return dict[alt]
def translate(code, dict): """ Given a language code and a dictionary, returns the dictionary's value for key 'code' if this key exists; otherwise tries to return a value for an alternative language that is most applicable to use on the Wikipedia in language 'code'. The language itself is always checked first, then lan...
address = '/w/wiki.phtml?title='+name
address = '/w/wiki.phtml?title='+name+"&redirect=no"
def getPage(code, name, do_edit=1, do_quote=1): """Get the contents of page 'name' from the 'code' language wikipedia""" host = langs[code] if code in oldsoftware: # Old algorithm name = re.sub('_', ' ', name) n=[] for x in name.split(): n.append(x[0].capitalize()+x[1:]) name='_'.join(n) #print name else: name = re.sub...
assert edittime[code,name]!=0 or code in oldsoftware, "No edittime on non-empty page?! %s:%s\n%s"%(code,name,text)
if needput: assert edittime[code,name]!=0 or code in oldsoftware, "No edittime on non-empty page?! %s:%s\n%s"%(code,name,text)
def getPage(code, name, do_edit=1, do_quote=1): """Get the contents of page 'name' from the 'code' language wikipedia""" host = langs[code] if code in oldsoftware: # Old algorithm name = re.sub('_', ' ', name) n=[] for x in name.split(): n.append(x[0].capitalize()+x[1:]) name='_'.join(n) #print name else: name = re.sub...
if code in ['meta','bs','ru','eo','ja','zh','hi','he','hu','pl','ko','cs','el','sl']:
if code in ['meta','bs','ru','eo','ja','zh','hi','he','hu','pl','ko','cs','el','sl','ro']:
def code2encoding(code): if code in ['meta','bs','ru','eo','ja','zh','hi','he','hu','pl','ko','cs','el','sl']: return 'utf-8' return 'iso-8859-1'
raise ValueError("Cannot locate entity for character %s"%repr(c))
raise NoSuchEntity("Cannot locate entity for character %s"%repr(c))
def addEntity(name): """Convert a unicode name into ascii name with entities""" import htmlentitydefs result='' for c in name: if ord(c)<128: result+=str(c) else: for k,v in htmlentitydefs.entitydefs.iteritems(): if (len(v)==1 and ord(c)==ord(v)) or v=='&#%d;'%ord(c): result+='&%s;'%k; break else: raise ValueError("Can...
w2=r'([^\]\|]*)'
w2=r'([^\]]*)'
def imagelinks(self): result = [] if self._code in image: im=image[self._code] + ':' else: im='Image:' w1=r'('+im+'[^\]\|]*)' w2=r'([^\]\|]*)' Rlink = re.compile(r'\[\['+w1+r'(\|'+w2+r')?\]\]') for l in Rlink.findall(self.get()): result.append(PageLink(self._code,l[0])) return result
def read_pages_from_sql_dump(sqlfilename, old, regex):
def read_pages_from_sql_dump(sqlfilename, replacements, exceptions, regex):
def read_pages_from_sql_dump(sqlfilename, old, regex): import sqldump dump = sqldump.SQLdump(sqlfilename, wikipedia.myencoding()) for entry in dump.entries(): if regex: if old.search(entry.text): yield wikipedia.PageLink(wikipedia.mylang, entry.full_title()) else: if entry.text.find(old) != -1: yield wikipedia.PageLink...
if regex: if old.search(entry.text): yield wikipedia.PageLink(wikipedia.mylang, entry.full_title()) else: if entry.text.find(old) != -1: yield wikipedia.PageLink(wikipedia.mylang, entry.full_title())
for exception in exceptions: if regex: exception = re.compile(exception) if exception.search(entry.text): break else: if entry.text.find(exception) != -1: break for old in replacements.keys(): if regex: old = re.compile(old) if old.search(entry.text): yield wikipedia.PageLink(wikipedia.mylang, entry.full_title()) break...
def read_pages_from_sql_dump(sqlfilename, old, regex): import sqldump dump = sqldump.SQLdump(sqlfilename, wikipedia.myencoding()) for entry in dump.entries(): if regex: if old.search(entry.text): yield wikipedia.PageLink(wikipedia.mylang, entry.full_title()) else: if entry.text.find(old) != -1: yield wikipedia.PageLink...
def read_pages_from_text_file(textfilename, old, regex):
def read_pages_from_text_file(textfilename):
def read_pages_from_text_file(textfilename, old, regex): f = open(textfilename, 'r') # regular expression which will find [[wiki links]] R = re.compile(r'.*\[\[([^\]]*)\]\].*') m = False for line in f.readlines(): m=R.match(line) if m: yield wikipedia.PageLink(wikipedia.mylang, m.group(1)) f.close()
def generator(source, old, regex, textfilename = None, sqlfilename = None):
def generator(source, replacements, exceptions, regex, textfilename = None, sqlfilename = None, pagename = None):
def generator(source, old, regex, textfilename = None, sqlfilename = None): if source == 'sqldump': for pl in read_pages_from_sql_dump(sqlfilename, old, regex): yield pl elif source == 'textfile': for pl in read_pages_from_text_file(textfilename, old, regex): yield pl
for pl in read_pages_from_sql_dump(sqlfilename, old, regex):
for pl in read_pages_from_sql_dump(sqlfilename, replacements, exceptions, regex):
def generator(source, old, regex, textfilename = None, sqlfilename = None): if source == 'sqldump': for pl in read_pages_from_sql_dump(sqlfilename, old, regex): yield pl elif source == 'textfile': for pl in read_pages_from_text_file(textfilename, old, regex): yield pl
for pl in read_pages_from_text_file(textfilename, old, regex):
for pl in read_pages_from_text_file(textfilename):
def generator(source, old, regex, textfilename = None, sqlfilename = None): if source == 'sqldump': for pl in read_pages_from_sql_dump(sqlfilename, old, regex): yield pl elif source == 'textfile': for pl in read_pages_from_text_file(textfilename, old, regex): yield pl
replacements = []
commandline_replacements = [] replacements = {} exceptions = []
def generator(source, old, regex, textfilename = None, sqlfilename = None): if source == 'sqldump': for pl in read_pages_from_sql_dump(sqlfilename, old, regex): yield pl elif source == 'textfile': for pl in read_pages_from_text_file(textfilename, old, regex): yield pl
replacements.append(arg) if source == None or len(replacements) != 2:
commandline_replacements.append(arg) if source == None:
def generator(source, old, regex, textfilename = None, sqlfilename = None): if source == 'sqldump': for pl in read_pages_from_sql_dump(sqlfilename, old, regex): yield pl elif source == 'textfile': for pl in read_pages_from_text_file(textfilename, old, regex): yield pl
old = replacements[0] new = replacements[1] if regex: old = re.compile(old)
if (len(commandline_replacements) == 2 and fix == None): replacements[commandline_replacements[0]] = commandline_replacements[1] elif fix == None: old = wikipedia.input(u'Please enter the text that should be replaced:') new = wikipedia.input(u'Please enter the new text:') replacements[old] = new while True: old = wikip...
def generator(source, old, regex, textfilename = None, sqlfilename = None): if source == 'sqldump': for pl in read_pages_from_sql_dump(sqlfilename, old, regex): yield pl elif source == 'textfile': for pl in read_pages_from_text_file(textfilename, old, regex): yield pl
wikipedia.setAction(msg[wikipedia.chooselang(wikipedia.mylang, msg)]) for pl in generator(source, old, regex, textfilename, sqlfilename):
for pl in generator(source, replacements, exceptions, regex, textfilename, sqlfilename, pagename):
def generator(source, old, regex, textfilename = None, sqlfilename = None): if source == 'sqldump': for pl in read_pages_from_sql_dump(sqlfilename, old, regex): yield pl elif source == 'textfile': for pl in read_pages_from_text_file(textfilename, old, regex): yield pl
if regex: new_text = old.sub(new, original_text) else: new_text = original_text.replace(old, new) if new_text == original_text: print 'No changes were necessary in %s' % pl.linkname() else: showDiff(original_text, new_text) if not acceptall: choice = wikipedia.input(u'Do you want to accept these changes? [y|n|a(ll)]') ...
skip_page = False for exception in exceptions: if regex: exception = re.compile(exception) hit = exception.search(original_text) if hit: wikipedia.output('Skipping %s because it contains %s' % (pl.linkname(), hit.group(0))) skip_page = True break else: hit = original_text.find(exception) if hit != -1: wikipedia.outpu...
def generator(source, old, regex, textfilename = None, sqlfilename = None): if source == 'sqldump': for pl in read_pages_from_sql_dump(sqlfilename, old, regex): yield pl elif source == 'textfile': for pl in read_pages_from_text_file(textfilename, old, regex): yield pl
path = 'copyright/' + i[0] + '/' + i[2]
path = appdir + i[0] + '/' + i[2]
def exclusion_file_list(): for i in pages_for_exclusion_database: path = 'copyright/' + i[0] + '/' + i[2] mediawiki_messages.makepath(path) p = wikipedia.Page(wikipedia.getSite(i[0]),i[1]) yield p, path
def load_pages(): write = False
def load_pages(force_update = False):
def load_pages(): write = False for page, path in exclusion_file_list(): try: file_age = time.time() - os.path.getmtime(path) if file_age > 24 * 60 * 60: print 'Updating source pages to exclude new URLs...' write = True except OSError: write = True if write: f = codecs.open(path, 'w', 'utf-8') f.write(page.get()) f.cl...
print 'Updating source pages to exclude new URLs...' write = True
print 'Updating page [[' + page.title() + ']] to exclude new URLs...' length = 0
def load_pages(): write = False for page, path in exclusion_file_list(): try: file_age = time.time() - os.path.getmtime(path) if file_age > 24 * 60 * 60: print 'Updating source pages to exclude new URLs...' write = True except OSError: write = True if write: f = codecs.open(path, 'w', 'utf-8') f.write(page.get()) f.cl...
write = True if write: f = codecs.open(path, 'w', 'utf-8') f.write(page.get()) f.close()
pass if length == 0 or force_update: try: data = page.get() f = codecs.open(path, 'w', 'utf-8') f.write(data) f.close() except wikipedia.IsRedirectPage: data = page.get(get_redirect=True) except: print 'Getting page failed'
def load_pages(): write = False for page, path in exclusion_file_list(): try: file_age = time.time() - os.path.getmtime(path) if file_age > 24 * 60 * 60: print 'Updating source pages to exclude new URLs...' write = True except OSError: write = True if write: f = codecs.open(path, 'w', 'utf-8') f.write(page.get()) f.cl...
def check_list(text, cl):
def check_list(text, cl, debug=False):
def check_list(text, cl): for entry in cl: if entry: if text.find(entry) != -1: print 'SKIP URL ' + text #print 'DEBUG: ' + entry return True
print 'SKIP URL ' + text
if debug: print 'SKIP URL ' + text
def check_list(text, cl): for entry in cl: if entry: if text.find(entry) != -1: print 'SKIP URL ' + text #print 'DEBUG: ' + entry return True
f = codecs.open(path, "r", 'utf-8') data = f.read() f.close() prelist += re.findall("(?i)url\s*=\s*<nowiki>(?:http://)?(.*?)</nowiki>", data) prelist += re.findall("(?i)\*\s*Site:\s*\[?(?:http://)?(.*?)\]?", data) if 'copyright/it/Cloni.txt' in path: prelist += re.findall('(?i)^==(?!=)\s*\[?\s*(?:<nowiki>)?(?:http://...
if 'exclusion_list.txt' in path: result_list += re.sub("</?pre>","", read_file(path, cut_comment = True)).splitlines() else: data = read_file(path) prelist += re.findall("(?i)url\s*=\s*<nowiki>(?:http://)?(.*)</nowiki>", data) prelist += re.findall("(?i)\*\s*Site:\s*\[?(?:http://)?(.*)\]?", data) if 'it/Cloni.txt' in...
def exclusion_list(): prelist = [] load_pages() for page, path in exclusion_file_list(): f = codecs.open(path, "r", 'utf-8') data = f.read() f.close() # wikipedia:en:Wikipedia:Mirrors and forks prelist += re.findall("(?i)url\s*=\s*<nowiki>(?:http://)?(.*?)</nowiki>", data) prelist += re.findall("(?i)\*\s*Site:\s*\[?(?:...
list3 = []
def exclusion_list(): prelist = [] load_pages() for page, path in exclusion_file_list(): f = codecs.open(path, "r", 'utf-8') data = f.read() f.close() # wikipedia:en:Wikipedia:Mirrors and forks prelist += re.findall("(?i)url\s*=\s*<nowiki>(?:http://)?(.*?)</nowiki>", data) prelist += re.findall("(?i)\*\s*Site:\s*\[?(?:...
list3 += [re.sub(" .*", "", entry[:entry.rfind('/')])] else: list3 += [re.sub(" .*", "", entry)] f = codecs.open('copyright/exclusion_list.txt', 'r','utf-8') list3 += re.sub(" ?
result_list += [re.sub(" .*", "", entry[:entry.rfind('/')])] else: result_list += [re.sub(" .*", "", entry)] result_list += read_file(appdir + 'exclusion_list.txt', cut_comment = True).splitlines() return result_list def read_file(filename, cut_comment = False): text = u"" f = codecs.open(filename, 'r','utf-8') text ...
def exclusion_list(): prelist = [] load_pages() for page, path in exclusion_file_list(): f = codecs.open(path, "r", 'utf-8') data = f.read() f.close() # wikipedia:en:Wikipedia:Mirrors and forks prelist += re.findall("(?i)url\s*=\s*<nowiki>(?:http://)?(.*?)</nowiki>", data) prelist += re.findall("(?i)\*\s*Site:\s*\[?(?:...
return list3 def write_log(text, filename = "copyright/output.txt"): file1=codecs.open(filename, 'a', 'utf-8') file1.write(text) file1.close()
return text def write_log(text, filename = output_file): f = codecs.open(filename, 'a', 'utf-8') f.write(text) f.close()
def exclusion_list(): prelist = [] load_pages() for page, path in exclusion_file_list(): f = codecs.open(path, "r", 'utf-8') data = f.read() f.close() # wikipedia:en:Wikipedia:Mirrors and forks prelist += re.findall("(?i)url\s*=\s*<nowiki>(?:http://)?(.*?)</nowiki>", data) prelist += re.findall("(?i)\*\s*Site:\s*\[?(?:...
text = text.replace("<br>", "") text = text.replace("<br/>", "") text = text.replace("<br />", "")
text = re.sub('(?i)<br(\s*/)?>', '', text)
def cleanwikicode(text): if not text: return "" #wikipedia.output(text) text = text.replace("<br>", "") text = text.replace("<br/>", "") text = text.replace("<br />", "") text = re.sub('<!--.*?-->', '', text) if exclude_quote: text = re.sub("(?i){{quote|.*?}}", "", text) text = re.sub("^:''.*?''\.?\s*((\(|<ref>).*?(\)...
text = re.sub("^:''.*?''\.?\s*((\(|<ref>).*?(\)|</ref>))?\.?$", "", text) text = re.sub('^[:*]?["][^"]+["]\.?\s*((\(|<ref>).*?(\)|</ref>))?\.?$', "", text) text = re.sub('^[:*]?[«][^»]+[»]\.?\s*((\(|<ref>).*?(\)|</ref>))?\.?$', "", text) text = re.sub('^[:*]?[“][^”]+[”]\.?\s*((\(|<ref>).*?(\)|</ref>))?\.?$', "...
text = re.sub("^[:*]?\s*''.*?''\.?\s*((\(|<ref>).*?(\)|</ref>))?\.?$", "", text) text = re.sub('^[:*]?\s*["][^"]+["]\.?\s*((\(|<ref>).*?(\)|</ref>))?\.?$', "", text) text = re.sub('^[:*]?\s*[«][^»]+[»]\.?\s*((\(|<ref>).*?(\)|</ref>))?\.?$', "", text) text = re.sub('^[:*]?\s*[“][^”]+[”]\.?\s*((\(|<ref>).*?(\)|</ref>))?\...
def cleanwikicode(text): if not text: return "" #wikipedia.output(text) text = text.replace("<br>", "") text = text.replace("<br/>", "") text = text.replace("<br />", "") text = re.sub('<!--.*?-->', '', text) if exclude_quote: text = re.sub("(?i){{quote|.*?}}", "", text) text = re.sub("^:''.*?''\.?\s*((\(|<ref>).*?(\)...
text = text.replace("''", "")
text = re.sub('<math>.*?</math>', '', text)
def cleanwikicode(text): if not text: return "" #wikipedia.output(text) text = text.replace("<br>", "") text = text.replace("<br/>", "") text = text.replace("<br />", "") text = re.sub('<!--.*?-->', '', text) if exclude_quote: text = re.sub("(?i){{quote|.*?}}", "", text) text = re.sub("^:''.*?''\.?\s*((\(|<ref>).*?(\)...
if len(line)>200: n_query+=1 if n_query>max_query_for_page: print "Max query limit for page reached" return output if len(line)>max_query_len: line=line[:max_query_len] glen=len(line) while line[glen-1] != ' ': glen -= 1 line = line[:glen] results = get_results(line) for url, engine in results: output += '\n*%s - %s' ...
for search_words in mysplit(line,31," "): if len(search_words)>120: n_query += 1 if max_query_for_page and n_query>max_query_for_page: print "Max query limit for page reached" return output if len(search_words)>max_query_len: search_words=search_words[:max_query_len] if " " in search_words: search_words = search_words[...
def query(lines = [], max_query_len = 1300): # Google max_query_len = 1480? # - '-Wikipedia ""' = 1467 output = u"" n_query = 0 for line in lines: line = cleanwikicode(line) if len(line)>200: n_query+=1 if n_query>max_query_for_page: print "Max query limit for page reached" return output if len(line)>max_query_len: li...
if check_list(url[i+offset][0], excl_list):
if check_list(url[i+offset][0], excl_list, debug=True):
def get_results(query, numresults = 10): url = list() if search_in_google: import google google.LICENSE_KEY = config.google_key print " google query..." search_request_retry = 6 while search_request_retry: #SOAP.faultType: <Fault SOAP-ENV:Server: Exception from service object: # Daily limit of 1000 queries exceeded fo...
write_log('=== [[' + page.title() + ']] ===' + output + '\n')
write_log('=== [[' + page.title() + ']] ===' + output + '\n', filename = output_file)
def run(self): """ Starts the robot. """ # Run the generator which will yield Pages which might need to be # checked. for page in self.generator: try: # Load the page's text from the wiki original_text = page.get() except wikipedia.NoPage: wikipedia.output(u'Page %s not found' % page.title()) continue except wikipedia....
global search_in_google, search_in_yahoo
global search_in_google, search_in_yahoo, max_query_for_page, output_file
def main(): global search_in_google, search_in_yahoo gen = None # Can either be 'xmldump', 'textfile' or 'userinput'. source = None # the textfile's path, either absolute or relative, which will be used when # source is 'textfile'. textfilename = None # the category name which will be used when source is 'category'. ca...
startpage = None
def main(): global search_in_google, search_in_yahoo gen = None # Can either be 'xmldump', 'textfile' or 'userinput'. source = None # the textfile's path, either absolute or relative, which will be used when # source is 'textfile'. textfilename = None # the category name which will be used when source is 'category'. ca...
gen = pagegenerators.NewpagesPageGenerator(number=80, repeat = repeat)
gen = pagegenerators.NewpagesPageGenerator(number=60, repeat = repeat)
def main(): global search_in_google, search_in_yahoo gen = None # Can either be 'xmldump', 'textfile' or 'userinput'. source = None # the textfile's path, either absolute or relative, which will be used when # source is 'textfile'. textfilename = None # the category name which will be used when source is 'category'. ca...
gen = pagegenerators.CategorizedPageGenerator(cat)
if firstPageTitle: gen = pagegenerators.CategorizedPageGenerator(cat, recurse = catrecurse, start = firstPageTitle) else: gen = pagegenerators.CategorizedPageGenerator(cat, recurse = catrecurse)
def main(): global search_in_google, search_in_yahoo gen = None # Can either be 'xmldump', 'textfile' or 'userinput'. source = None # the textfile's path, either absolute or relative, which will be used when # source is 'textfile'. textfilename = None # the category name which will be used when source is 'category'. ca...
if not gen:
if ids: checks_by_ids(ids) if not gen and not ids:
def main(): global search_in_google, search_in_yahoo gen = None # Can either be 'xmldump', 'textfile' or 'userinput'. source = None # the textfile's path, either absolute or relative, which will be used when # source is 'textfile'. textfilename = None # the category name which will be used when source is 'category'. ca...
debugDump( 'MediaWiki_Msg', site, u'Error URL: '+unicode(path), allmessages )
wikipedia.debugDump( 'MediaWiki_Msg', site, u'Error URL: '+unicode(path), allmessages )
def refresh_messages(site = None): site = site or wikipedia.getSite() # get 'all messages' special page's path path = site.allmessages_address() print 'Retrieving MediaWiki messages for %s' % repr(site) wikipedia.put_throttle() # It actually is a get, but a heavy one. allmessages = site.getUrl(path) print 'Parsing Med...
def get_image(fn,target,description):
def get_image(fn, target, description, debug=False):
def get_image(fn,target,description): uploadaddr='/wiki/%s:Upload'%wikipedia.special[wikipedia.mylang] # Get file contents uo = wikipedia.MyURLopener() file = uo.open(fn) contents = file.read() file.close() # Isolate the pure name if '/' in fn: fn = fn.split('/')[-1] if '\\' in fn: fn = fn.split('\\')[-1] print "The fi...
print description
def get_image(fn,target,description): uploadaddr='/wiki/%s:Upload'%wikipedia.special[wikipedia.mylang] # Get file contents uo = wikipedia.MyURLopener() file = uo.open(fn) contents = file.read() file.close() # Isolate the pure name if '/' in fn: fn = fn.split('/')[-1] if '\\' in fn: fn = fn.split('\\')[-1] print "The fi...
data = post_multipart(wikipedia.langs[wikipedia.mylang], uploadaddr, (('wpUploadDescription', description), ('wpUploadAffirm', '1'), ('wpUpload','upload bestand')), (('wpUploadFile',fn,contents),) )
if not debug: data = post_multipart(wikipedia.langs[wikipedia.mylang], uploadaddr, (('wpUploadDescription', description), ('wpUploadAffirm', '1'), ('wpUpload','upload bestand')), (('wpUploadFile',fn,contents),) )
def get_image(fn,target,description): uploadaddr='/wiki/%s:Upload'%wikipedia.special[wikipedia.mylang] # Get file contents uo = wikipedia.MyURLopener() file = uo.open(fn) contents = file.read() file.close() # Isolate the pure name if '/' in fn: fn = fn.split('/')[-1] if '\\' in fn: fn = fn.split('\\')[-1] print "The fi...
'li': [u'Verdudeliking', u'Verdudelikingpazjena'],
'li': [u'Verdudeliking', u'Verdudelikingpazjena', u'Vp'],
def __init__(self): family.Family.__init__(self) self.name = 'wikipedia'
if site.sitename() == 'wikipedia:de':
if self.site.sitename() == 'wikipedia:de':
def cleanUpLinks(self, text): trailR = re.compile(self.site.linktrail()) # The regular expression which finds links. Results consist of four groups: # group title is the target page title, that is, everything before | or ]. # group section is the page section. It'll include the # to make life easier for us. # group lab...
if first in self.validLanguageLinks() or (first in self.family.known_families and self.family.known_families[first] != self.family.name):
if first in self.validLanguageLinks() or (first in self.validLanguageLinks() and self.family.known_families[first] != self.family.name):
def isInterwikiLink(self, s): """ Try to check whether s is in the form "foo:bar" where foo is a known language code or family. In such a case we are dealing with an interwiki link. """ if not ':' in s: return False first, rest = s.split(':',1) # interwiki codes are case-insensitive first = first.lower() if first in se...
if not language in self.namespaces():
if not language[0].upper()+language[1:] in self.namespaces():
def validLanguageLinks(self): langlist = [] for language in self.languages(): if not language in self.namespaces(): langlist += [language] return langlist
print "%s doesn't exit yet. Ignoring."%(pl2.aslocallink())
print "%s doesn't exist yet. Ignoring."%(pl2.aslocallink())
def add_category(): print "This bot has two modes: you can add a category link to all" print "pages mentioned in a List that is now in another wikipedia page" print "or you can add a category link to all pages that link to a" print "specific page. If you want the second, please give an empty" print "answer to the first...
Multiple references in one page will be scanned in order, but typing 'n' on any one of them will leave the complete page unchanged; it is not possible to leave only one reference unchanged.
If you don't want to move the article to a subcategory, but to another category, you can use the 'j' (jump) command. Typing 's' will leave the complete page unchanged.
def remove_category(): old_title = wikipedia.input('Please enter the name of the category that should be removed: ') old_cat = catlib.CatLink(old_title) # get edit summary message wikipedia.setAction(msg_delete[wikipedia.chooselang(wikipedia.mylang,msg_delete)] % old_title) articles = old_cat.articles(recurse = 0) if ...
title = title.strip()
def __init__(self, site, title = None, insite = None, tosite = None): """ Constructor. Normally called with two arguments: Parameters: 1) The wikimedia site on which the page resides 2) The title of the page as a unicode string The argument insite can be specified to help decode the name; it is the wikimedia site wher...
pickle.dump(databases, f, bin=1)
pickle.dump(databases, f, protocol=pickle.HIGHEST_PROTOCOL)
def dump(self, filename = 'category.dump.bz2'): ''' Saves the contents of the dictionaries superclassDB and catContentDB to disk. ''' wikipedia.output(u'Dumping to %s, please wait...' % filename) f = bz2.BZ2File(filename, 'w') databases = { 'catContentDB': self.catContentDB, 'superclassDB': self.superclassDB } # store ...
incode = self._incode)
incode = mylang)
def __init__(self, code, name = None, urlname = None, linkname = None, incode = None): """Constructor. Normally called with two arguments: 1) The language code on which the page resides 2) The name of the page as suitable for a URL """ self._incode = incode self._code = code if linkname is None and urlname is None and ...
colors = colors or [None for char in text]
def output(self, text, colors = None, newline = True): """ If a character can't be displayed in the encoding used by the user's terminal, it will be replaced with a question mark or by a transliteration.
m = re.search("== *%s *==" % hn, self._contents)
m = re.search("=+ *%s *=+" % hn, self._contents)
def get(self, read_only = False, force = False, get_redirect=False, throttle = True): """The wiki-text of the page. This will retrieve the page if it has not been retrieved yet. This can raise the following exceptions that should be caught by the calling code:
return self.lang in site.family.category_on_one_line
return self.lang in self.site().family.category_on_one_line
def category_on_one_line(self): return self.lang in site.family.category_on_one_line
if choice in ['a', 'A']: acceptall = True choice = 'y' if choice in ['y', 'Y']:
if choice in ['a', 'A']: acceptall = True if acceptall or choice in ['y', 'Y']:
def generator(source, replacements, exceptions, regex, textfilename = None, sqlfilename = None, pagenames = None): ''' Generator which will yield PageLinks for pages that might contain text to replace. These pages might be retrieved from a local SQL dump file or a text file, or as a list of pages entered by the user. ...
print "Creating page %s"%title
def findpage(t): try: location = re.search(starttext+"([^\Z]*?)"+endtext,t) if include: page = location.group() else: page = location.group(1) except AttributeError: return try: title = re.search("'''(.*?)'''",page).group(1) pl = wikipedia.PageLink(mysite,title) if pl.exists(): print "Page %s already exists, not adding...
text='\n'.join(text)
text=''.join(text)
def findpage(t): try: location = re.search(starttext+"([^\Z]*?)"+endtext,t) if include: page = location.group() else: page = location.group(1) except AttributeError: return try: title = re.search("'''(.*?)'''",page).group(1) pl = wikipedia.PageLink(mysite,title) if pl.exists(): print "Page %s already exists, not adding...
return x, isWatched
return x
def getPage(site, name, get_edit_page = True, read_only = False, do_quote = True, get_redirect=False, throttle = True): """ Get the contents of page 'name' from the 'site' wiki Do not use this directly; for 99% of the possible ideas you can use the Page object instead. Arguments: site - the wiki site name ...
if len(arg) == 7:
if len(arg) == 6:
def main(): quietMode = False # use -quiet to get less output # if the -file argument is used, page titles are stored in this array. # otherwise it will only contain one page. articles = [] # if -file is not used, this temporary array is used to read the page title. page_title = [] debug = False xmlfilename = None text...
startpage = arg[8:]
startpage = arg[7:]
def main(): quietMode = False # use -quiet to get less output # if the -file argument is used, page titles are stored in this array. # otherwise it will only contain one page. articles = [] # if -file is not used, this temporary array is used to read the page title. page_title = [] debug = False xmlfilename = None text...
'pt': u'Discussão Portal',
'pt': u'Portal Discussão',
def __init__(self): family.Family.__init__(self) self.name = 'wikipedia'
start = int(arg[7:])
start = arg[7:]
def main(): start = '!' sqlfilename = None for arg in sys.argv[1:]: arg = wikipedia.argHandler(arg, logname = 'weblinkchecker.log') if arg: if arg.startswith('-sql'): if len(arg) == 4: sqlfilename = wikipedia.input(u'Please enter the SQL dump\'s filename: ') else: sqlfilename = arg[5:] source = sqlfilename elif arg.sta...
newTable = re.sub("[\r\n]*?<(?i)(table) ([\w\W]*?)>([\w\W]*?)[\r\n ]*", r"\r\n{| \2\r\n\3", newTable) newTable = re.sub("[\r\n]*?<(TABLE|table)>([\w\W]*?)[\r\n ]*", r"\r\n{|\n\2\r\n", newTable) newTable = re.sub("[\r\n]*?<(TABLE|table) ([\w\W]*?)>[\r\n ]*", r"\r\n{| \2\r\n", newTable) newTable = re.sub("[\r\n]*?<(TA...
newTable = re.sub("(?i)[\r\n]*?<table (?P<attr>[\w\W]*?)>(?P<more>[\w\W]*?)[\r\n ]*", r"\r\n{| \g<attr>\r\n\g<more>", newTable) newTable = re.sub("(?i)[\r\n]*?<table>(?P<more>[\w\W]*?)[\r\n ]*", r"\r\n{|\n\g<more>\r\n", newTable) newTable = re.sub("(?i)[\r\n]*?<table (?P<attr>[\w\W]*?)>[\r\n ]*", r"\r\n{| \g<attr>\r\...
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable = re.sub("[\s]*<\/(TABLE|table)>", "\r\n|}", newTable) newTable = re.sub("<(CAPTION|caption) ([\w\W]*?)>([\w\W]*?)<\/caption>", r"\r\n|+\1 | \2", newTable) newTable = re.sub("<(CAPTION|caption)([\w\W]*?)<\/caption>", r"\r\n|+ \1", newTable)
newTable = re.sub("(?i)[\s]*<\/table>", "\r\n|}", newTable) newTable = re.sub("(?i)<caption (?P<attr>[\w\W]*?)>(?P<caption>[\w\W]*?)<\/caption>", r"\r\n|+\g<attr> | \g<caption>", newTable) newTable = re.sub("(?i)<caption>(?P<caption>[\w\W]*?)<\/caption>", r"\r\n|+ \g<caption>", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable = re.sub("[\r\n]+<(TH|th)([^>]*?)>([\w\W]*?)<\/(th|TH)>", r"\r\n!\2 | \3\r\n", newTable)
newTable = re.sub("(?i)[\r\n]+<th(?P<attr>[^>]*?)>(?P<header>[\w\W]*?)<\/th>", r"\r\n!\g<attr> | \g<header>\r\n", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable, n = re.subn("[\r\n]+<(th|TH)>([\w\W]*?)[\r\n]+", r"\r\n! \2\r\n", newTable)
newTable, n = re.subn("(?i)[\r\n]+<th>(?P<header>[\w\W]*?)[\r\n]+", r"\r\n! \g<header>\r\n", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable, n = re.subn("[\r\n]+<(th|TH)([^>]*?)>([\w\W]*?)[\r\n]+", r"\n!\2 | \3\r\n", newTable)
newTable, n = re.subn("(?i)[\r\n]+<th(?P<attr>[^>]*?)>(?P<header>[\w\W]*?)[\r\n]+", r"\n!\g<attr> | \g<header>\r\n", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
warning_messages.append(u'WARNING: found <th> without </th>. (%d occurences\n)' % n)
warning_messages.append(u'WARNING: found <th ...> without </th>. (%d occurences\n)' % n)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable = re.sub("[\r\n]*<(tr|TR)([^>]*?)>[\r\n]*", r"\r\n|-----\2\r\n", newTable) newTable = re.sub("[\r\n]*<(tr|TR)>[\r\n]*",
newTable = re.sub("(?i)[\r\n]*<tr(?P<attr>[^>]*?)>[\r\n]*", r"\r\n|-----\g<attr>\r\n", newTable) newTable = re.sub("(?i)[\r\n]*<tr>[\r\n]*",
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable = re.sub("[\r\n]+<(td|TD)>([\w\W]*?)<\/(TD|td)>", r"\r\n| \2\r\n", newTable)
newTable = re.sub("(?i)[\r\n]+<td>(?P<cell>[\w\W]*?)<\/td>", r"\r\n| \g<cell>\r\n", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable = re.sub("[\r\n]+<(td|TD)([^>]*?)>([\w\W]*?)<\/(TD|td)>", r"\r\n|\2 | \3", newTable)
newTable = re.sub("(?i)[\r\n]+<td(?P<attr>[^>]*?)>(?P<cell>[\w\W]*?)<\/td>", r"\r\n|\g<attr> | \g<cell>", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable, n = re.subn("[\r\n]+<(td|TD)>([^\r\n]*?)<(td|TD)>", r"\r\n| \2\r\n", newTable)
newTable, n = re.subn("(?i)[\r\n]+<td>(?P<cell>[^\r\n]*?)<td>", r"\r\n| \g<cell>\r\n", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
warning_messages.append(u'WARNING: (sorry, bot code unreadable (1). I don\'t know why this warning is given.) (%d occurences)\n' % n)
warning_messages.append(u'<td> used where </td> was expected. (%d occurences)\n' % n)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
warning_messages.append(u'WARNING: found <td><td></tr>, but no </td>. (%d occurences)\n' % n) warnings += n
warning_messages.append(u'WARNING: (sorry, bot code unreadable (1). I don\'t know why this warning is given.) (%d occurences)\n' % n)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable, n = re.subn("<(td|TD)>([^<]*?)[\r\n]+", r"\r\n| \2\r\n", newTable)
newTable, n = re.subn("(?i)<td>(?P<cell>[^<]*?)[\r\n]+", r"\r\n| \g<cell>\r\n", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
warning_messages.append(u'WARNING: found <td> without </td>. (%d occurences)\n' % n) warnings += n
warning_messages.append(u'NOTE: Found <td> without </td>. This shouldn\'t cause problems.\n')
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable, n = re.subn("[\r\n]*<(td|TD)([^>]*?)>([\w\W]*?)[\r\n]+", r"\r\n|\2 | \3\r\n", newTable)
newTable, n = re.subn("(?i)[\r\n]*<td(?P<attr>[^>]*?)>(?P<cell>[\w\W]*?)[\r\n]+", r"\r\n|\g<attr> | \g<cell>\r\n", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable, n = re.subn("<(td|TD)>([\w\W]*?)[\r\n]+", r"\r\n| \2\r\n", newTable) if n>0: warning_messages.append(u'WARNING: (sorry, bot code unreadable (2). I don\'t know why this warning is given.) (%d occurences)\n' % n) warnings += n
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
newTable = re.sub("<td>[\r\n]*<\/tr>", "", newTable) newTable = re.sub("[\r\n]*<\/[Tt][rRdDhH]>", "", newTable)
newTable = re.sub("(?i)<td>[\r\n]*<\/tr>", "", newTable) newTable = re.sub("(?i)[\r\n]*<\/t[rdh]>", "", newTable)
def convertTable(self, table): ''' Converts an HTML table to wiki syntax. If the table already is a wiki table or contains a nested wiki table, tries to beautify it. Returns the converted table, the number of warnings that occured and a list containing these warnings.
def main(): if __name__ == "__main__":
if __name__ == "__main__": try:
def main(): if __name__ == "__main__": action = None sort_by_last_name = False for arg in sys.argv[1:]: arg = wikipedia.argHandler(arg) if arg: if arg == 'add': action = 'add' elif arg == 'remove': action = 'remove' elif arg == 'rename': action = 'rename' elif arg == 'tidy': action = 'tidy' elif arg == 'tree': action =...
try: main() except: wikipedia.stopme() raise wikipedia.stopme()
finally: wikipedia.stopme()
def main(): if __name__ == "__main__": action = None sort_by_last_name = False for arg in sys.argv[1:]: arg = wikipedia.argHandler(arg) if arg: if arg == 'add': action = 'add' elif arg == 'remove': action = 'remove' elif arg == 'rename': action = 'rename' elif arg == 'tidy': action = 'tidy' elif arg == 'tree': action =...
choice = wikipedia.inputChoice(u"File format is not %s but %s. Continue [y/N]? " % (allowed_formats, ext))
choice = wikipedia.inputChoice(u"File format is not one of [%s], but %s. Continue?" % (u' '.join(allowed_formats), ext), ['yes', 'no'], ['y', 'n'], 'N')
def upload_image(self, debug=False): """Gets the image at URL self.url, and uploads it to the target wiki. Returns the filename which was used to upload the image. If the upload fails, the user is asked whether to try again or not. If the user chooses not to retry, returns null. """ # Get file contents if '://' in self...
f=open('ALLNOTFOUND.dat','w') f.write(data) f.close() sys.exit(1)
def run(self): dt=15 while True: try: data = self.getData() except (socket.error, httplib.BadStatusLine, ServerError): # Print the traceback of the caught exception print ''.join(traceback.format_exception(*sys.exc_info())) output(u'DBG> got network error in GetAll.run. Sleeping for %d seconds'%dt) time.sleep(dt) if dt...
output("WARNING: Hashname does not exist: %s" % self)
output("WARNING: Hashname does not exist: %s" % self.linkname())
def get(self, read_only = False): """The wiki-text of the page. This will retrieve the page if it has not been retrieved yet. This can raise the following exceptions that should be caught by the calling code:
output(u""+mediawiki_messages.get('spamprotectiontitle', self.site()))
def putPage(self, text, comment = None, watchArticle = False, minorEdit = True, newPage = False, token = None, gettoken = False, sysop = False): """ Upload 'text' as new contents for this Page by filling out the edit page.
return dh_noConv( value, u'%d' )
return dh_noConvYear( value, u'%d' )
def dh_simpleInt( value ): """decoding helper for a single integer value representing a year with no extra symbols""" return dh_noConv( value, u'%d' )
'nap': lambda v: slh( v, [u"Januari", u"Februari", u"Mac", u"April", u"Mei", u"Jun", u"Julai", u"Ogos", u"September", u"Oktober", u"November", u"Disember"] ), 'nap': lambda v: slh( v, [u"Jennaro", u"Frevaro", u"Màrzo", u"Abbrile", u"Majo", u"Giùgno", u"Luglio", u"Aùsto", u"Settembre", u"Ottovre", u"Nuvembre",...
'nap': lambda v: slh( v, [u"Jennaro", u"Frevaro", u"Màrzo", u"Abbrile", u"Maggio", u"Giùgno", u"Luglio", u"Aùsto", u"Settembre", u"Ottovre", u"Nuvembre", u"Dicembre"] ),
def dh_knYearConverter( value ): if type(value) is int: # Encode an integer value into a textual form. return unicode(value).translate(_knDigitsToLocal) else: # First make sure there are no real digits in the string tmp = value.translate(_knDigitsToLocal) # Test if tmp == value: tmp = value.translate(_knLocalTo...
'af' : dh_simpleInt, 'ar' : dh_simpleInt, 'ast': dh_simpleInt, 'be' : dh_simpleInt, 'bg' : dh_simpleInt, 'bs' : dh_simpleInt, 'ca' : dh_simpleInt, 'cs' : dh_simpleInt, 'csb': dh_simpleInt, 'cv' : dh_simpleInt, 'cy' : dh_simpleInt, 'da' : dh_simpleInt, 'de' : ...
'af' : dh_simpleYearAD, 'ar' : dh_simpleYearAD, 'ast': dh_simpleYearAD, 'be' : dh_simpleYearAD, 'bg' : dh_simpleYearAD, 'bs' : dh_simpleYearAD, 'ca' : dh_simpleYearAD, 'cs' : dh_simpleYearAD, 'csb': dh_simpleYearAD, 'cv' : dh_simpleYearAD, 'cy' : dh_simpleYearAD, '...
def dh_knYearConverter( value ): if type(value) is int: # Encode an integer value into a textual form. return unicode(value).translate(_knDigitsToLocal) else: # First make sure there are no real digits in the string tmp = value.translate(_knDigitsToLocal) # Test if tmp == value: tmp = value.translate(_knLocalTo...
'ko' : lambda v: dh_noConv( v, u'%d년' ), 'ku' : dh_simpleInt, 'kw' : dh_simpleInt, 'la' : dh_simpleInt, 'lb' : dh_simpleInt, 'li' : dh_simpleInt, 'lt' : dh_simpleInt, 'lv' : dh_simpleInt, 'mi' : dh_simpleInt, 'mk' : dh_simpleInt, 'ms' : dh_simpleInt, 'nap': dh...
'ko' : lambda v: dh_noConvYear( v, u'%d년' ), 'ku' : dh_simpleYearAD, 'kw' : dh_simpleYearAD, 'la' : dh_simpleYearAD, 'lb' : dh_simpleYearAD, 'li' : dh_simpleYearAD, 'lt' : dh_simpleYearAD, 'lv' : dh_simpleYearAD, 'mi' : dh_simpleYearAD, 'mk' : dh_simpleYearAD, 'ms' : ...
def dh_knYearConverter( value ): if type(value) is int: # Encode an integer value into a textual form. return unicode(value).translate(_knDigitsToLocal) else: # First make sure there are no real digits in the string tmp = value.translate(_knDigitsToLocal) # Test if tmp == value: tmp = value.translate(_knLocalTo...
'tl' : dh_simpleInt, 'tr' : dh_simpleInt, 'tt' : dh_simpleInt, 'uk' : dh_simpleInt, 'ur' : lambda v: dh_noConv( v, u'%dسبم' ), 'vi' : dh_simpleInt, 'wa' : dh_simpleInt, 'zh' : lambda v: dh_noConv( v, u'%d年' ), 'zh-min-nan' : lambda v: dh_noConv( v, u'%d nî' ),
'tl' : dh_simpleYearAD, 'tr' : dh_simpleYearAD, 'tt' : dh_simpleYearAD, 'uk' : dh_simpleYearAD, 'ur' : lambda v: dh_noConvYear( v, u'%dسبم' ), 'vi' : dh_simpleYearAD, 'wa' : dh_simpleYearAD, 'zh' : lambda v: dh_noConvYear( v, u'%d年' ), 'zh-min-nan' : lambda v: dh_noConvYear( v, ...
def dh_knYearConverter( value ): if type(value) is int: # Encode an integer value into a textual form. return unicode(value).translate(_knDigitsToLocal) else: # First make sure there are no real digits in the string tmp = value.translate(_knDigitsToLocal) # Test if tmp == value: tmp = value.translate(_knLocalTo...
'af' : lambda v: dh_noConv( v, u'%d v.C.' ), 'bg' : lambda v: dh_noConv( v, u'%d г. пр.н.е.' ), 'bs' : lambda v: dh_noConv( v, u'%d p.ne.' ), 'ca' : lambda v: dh_noConv( v, u'%d aC' ), 'da' : lambda v: dh_noConv( v, u'%d f.Kr.' ), 'de' : lambda v: dh_noConv( v, u'%d v. Chr.' ), 'en' : ...
'af' : lambda v: dh_noConvYear( v, u'%d v.C.' ), 'bg' : lambda v: dh_noConvYear( v, u'%d г. пр.н.е.' ), 'bs' : lambda v: dh_noConvYear( v, u'%d p.ne.' ), 'ca' : lambda v: dh_noConvYear( v, u'%d aC' ), 'da' : lambda v: dh_noConvYear( v, u'%d f.Kr.' ), 'de' : lambda v: dh_noConvYear( v, u'%d...
def dh_knYearConverter( value ): if type(value) is int: # Encode an integer value into a textual form. return unicode(value).translate(_knDigitsToLocal) else: # First make sure there are no real digits in the string tmp = value.translate(_knDigitsToLocal) # Test if tmp == value: tmp = value.translate(_knLocalTo...
(lambda x: dh_noConv( x, u'%d-ві' ), lambda x: x == 0 or (x % 100 == 40)), (lambda x: dh_noConv( x, u'%d-ні' ), lambda x: x % 1000 == 0), (lambda x: dh_noConv( x, u'%d-ті' ), lambda x: True)]),
(lambda x: dh_dec( x, u'%d-ві' ), lambda x: x == 0 or (x % 100 == 40)), (lambda x: dh_dec( x, u'%d-ні' ), lambda x: x % 1000 == 0), (lambda x: dh_dec( x, u'%d-ті' ), lambda x: True)]),
def dh_knYearConverter( value ): if type(value) is int: # Encode an integer value into a textual form. return unicode(value).translate(_knDigitsToLocal) else: # First make sure there are no real digits in the string tmp = value.translate(_knDigitsToLocal) # Test if tmp == value: tmp = value.translate(_knLocalTo...
(lambda x: dh_noConv( x, u'%d-ві до Р.Х.' ), lambda x: x == 0 or (x % 100 == 40)), (lambda x: dh_noConv( x, u'%d-ті до Р.Х.' ), lambda x: True)]),
(lambda x: dh_dec( x, u'%d-ві до Р.Х.' ), lambda x: x == 0 or (x % 100 == 40)), (lambda x: dh_dec( x, u'%d-ті до Р.Х.' ), lambda x: True)]), 'zh' : lambda v: dh_dec( v, u'前%d年代' ),
def dh_knYearConverter( value ): if type(value) is int: # Encode an integer value into a textual form. return unicode(value).translate(_knDigitsToLocal) else: # First make sure there are no real digits in the string tmp = value.translate(_knDigitsToLocal) # Test if tmp == value: tmp = value.translate(_knLocalTo...
'en' : lambda v: dh_noConv( v, u'%dth century' ),
'en' : lambda v: multi( v, [ (lambda x: dh_noConv( x, u'%dst century' ), lambda x: x == 1 or (x > 20 and x%10 == 1)), (lambda x: dh_noConv( x, u'%dnd century' ), lambda x: x == 2 or (x > 20 and x%10 == 2)), (lambda x: dh_noConv( x, u'%drd century' ), lambda x: x == 3 or (x > 20 and x%10 == 3)), (lambda x: dh_noCon...
def dh_knYearConverter( value ): if type(value) is int: # Encode an integer value into a textual form. return unicode(value).translate(_knDigitsToLocal) else: # First make sure there are no real digits in the string tmp = value.translate(_knDigitsToLocal) # Test if tmp == value: tmp = value.translate(_knLocalTo...
raise "bug, page not found in list"
print "BUG> bug, page not found in list"
def oneDone(self, title, timestamp, text): #print "DBG>", repr(title), timestamp, len(text) pl = PageLink(self.code, title) for pl2 in self.pages: #print "DBG>", pl, pl2, pl2.hashfreeLinkname() if PageLink(self.code, pl2.hashfreeLinkname()) == pl: if not hasattr(pl2,'_contents') and not hasattr(pl2,'_getexception'): br...
while 1:
while True:
def run(self): dt=15 while 1: try: data = self.getData() except socket.error: # Print the traceback of the caught exception print ''.join(traceback.format_exception(*sys.exc_info())) output(u'DBG> got socket error in GetAll.run. Sleeping for %d seconds'%dt) time.sleep(dt) dt *= 2 else: break handler = WikimediaXmlHandl...
dt *= 2
if dt <= 60: dt += 15 elif dt < 360: dt += 60
def run(self): dt=15 while 1: try: data = self.getData() except socket.error: # Print the traceback of the caught exception print ''.join(traceback.format_exception(*sys.exc_info())) output(u'DBG> got socket error in GetAll.run. Sleeping for %d seconds'%dt) time.sleep(dt) dt *= 2 else: break handler = WikimediaXmlHandl...
print "Dumped invalid XML to sax_parse_bug.dat"
print >>sys.stderr, "Dumped invalid XML to sax_parse_bug.dat"
def run(self): dt=15 while 1: try: data = self.getData() except socket.error: # Print the traceback of the caught exception print ''.join(traceback.format_exception(*sys.exc_info())) output(u'DBG> got socket error in GetAll.run. Sleeping for %d seconds'%dt) time.sleep(dt) dt *= 2 else: break handler = WikimediaXmlHandl...
except NoPage: pass except IsRedirectPage,arg: pass except LockedPage: pass except SectionError:
except (NoPage, IsRedirectPage, LockedPage, SectionError):
def run(self): dt=15 while 1: try: data = self.getData() except socket.error: # Print the traceback of the caught exception print ''.join(traceback.format_exception(*sys.exc_info())) output(u'DBG> got socket error in GetAll.run. Sleeping for %d seconds'%dt) time.sleep(dt) dt *= 2 else: break handler = WikimediaXmlHandl...