def run(self): # Set up database access try: self.db = querier.querier(host="nlwiki.labsdb") except Exception, error: wikipedia.output(u'Could not connect to database: %s.' % error, toStdout=False)
def run(self): # Set up database access try: self.db = querier.querier(host="sql-s2") except Exception, error: wikipedia.output(u'Could not connect to database: %s.' % error, toStdout = False)
#! /home/valhallasw/bin/python # $Id$ import cgi import cgitb; cgitb.enable() import sys, os sys.path.append('/home/valhallasw/libs/python') #viewable through http://tools.wikimedia.de/~valhallasw/libs/python import querier, sqlfunctions, cgifunctions counter = 0 Q = querier.querier() pagesOK = Q.do("select pl_title page_title from nlwiki_p.pagelinks join nlwiki_p.page on page_id=pl_from where page_title=\"Te_verwijderen_pagina's\" and page_namespace=4 and pl_namespace=0") pages = Q.do("select page_title from nlwiki_p.page join nlwiki_p.categorylinks on page_id =cl_from where cl_to='Wikipedia:Weg' and page_namespace=0") print "Content-type: text/html; charset=UTF-8\n\n<html><body>"; print "<pre>$Id$</pre>" print "%i te verwijderen, %i verwijdersjabloon <p><ul>" % (len(pagesOK),len(pages)) for page in pages: if page not in pagesOK: counter = counter + 1 print "<li><a href='http://nl.wikipedia.org/wiki/%s'>%s</a></li>" % (page['page_title'], page['page_title']) print "</ul><br>%s not OK</body></html>" % counter
now = datetime.datetime(*time.localtime()[0:5]) site = u"nl" namespacepage = wikipedia.Page( wikipedia.getSite(site), wikipedia.input("Please give the namespace name:").rstrip(":") + ":" ) namespacetalkpage = namespacepage.switchTalkPage() namespace = namespacepage.namespace() namespacetalk = namespacetalkpage.namespace() nsname = namespacepage.title() nstname = namespacetalkpage.title() nsuname = wikipedia.Page(wikipedia.getSite(site), "User:"******"nl"), u"Wikipedia:OrphanOverleg/" + nsname.rstrip(":")) Q = querier.querier(verbose=True) statistiek = {} output = u"=Orphan-overlegpagina's " + nsname + unicode(now.strftime("(%Y%m%d, %H%M)=\n")) print "Ophalen orphanpagina's..." results = Q.do( "select p2.page_title, p2.page_id, p2.page_len from nlwiki_p.page as p1 right join nlwiki_p.page as p2 on p1.page_title = p2.page_title and p1.page_namespace=" + str(namespace) + " where p2.page_namespace=" + str(namespacetalk) + " and p1.page_title IS NULL;" ) print str(len(results)) + " items;" output += str(len(results)) + "items;"
showMissed(); } else { cd = setTimeout("redo()",1000); } } function init() { cd(); } window.onload = init; var count=0; var found=new Array(); var states=new Array(""" Q = querier.querier() n = u"" for nick in Q.do("select user_name from nlwiki_p.user right join nlwiki_p.user_groups on user_id=ug_user where ug_group = 'sysop'"): n += u'"'+nick['user_name'].decode('utf-8')+'",' n = n.rstrip(",") print n.encode('utf-8'); print """); function checkStates(fld){ if(fld.value.length>1){ for(var i=0;i<states.length;i++){ if(fld.value.toLowerCase()==states[i].toLowerCase()){ found[found.length]=states[i]; found.sort(); states.splice(i,1); fld.value=""; count++;
# # (C) Erwin (nl.wikipedia.org), 2010 # # Distributed under the terms of the CC-BY-SA 3.0 licence. # from __future__ import generators import sys, os # Import pywikipedia and database wrapper sys.path.append(os.environ['HOME'] + "/trunk") import re, querier import wikipedia, config #DB Info db = querier.querier(host='nlwiki.labsdb') #same as MySQLdb.connect attributes def main(): page = wikipedia.Page(wikipedia.getSite(), 'Wikipedia:Links_naar_doorverwijspagina\'s/Artikelen') try: # Load the page's text from the wiki. original_text = page.get() if not page.canBeEdited(): wikipedia.output(u"Page %s is locked; skipping." % page.aslink()) return #No page, so ignore except wikipedia.NoPage: wikipedia.output(u"Page %s does not exist; skipping." % page.aslink()) return except wikipedia.IsRedirectPage:
# # (C) Erwin (nl.wikipedia.org), 2010 # # Distributed under the terms of the CC-BY-SA 3.0 licence. # from __future__ import generators import sys, os # Import pywikipedia and database wrapper sys.path.append(os.environ['HOME'] + "/trunk") import re, querier import wikipedia, config #DB Info db = querier.querier(host='nlwiki.labsdb') #same as MySQLdb.connect attributes def main(): page = wikipedia.Page( wikipedia.getSite(), 'Wikipedia:Links_naar_doorverwijspagina\'s/Artikelen') try: # Load the page's text from the wiki. original_text = page.get() if not page.canBeEdited(): wikipedia.output(u"Page %s is locked; skipping." % page.aslink()) return #No page, so ignore except wikipedia.NoPage:
site = u'nl' namespacepage = wikipedia.Page( wikipedia.getSite(site), wikipedia.input("Please give the namespace name:").rstrip(':') + ':') namespacetalkpage = namespacepage.switchTalkPage() namespace = namespacepage.namespace() namespacetalk = namespacetalkpage.namespace() nsname = namespacepage.title() nstname = namespacetalkpage.title() nsuname = wikipedia.Page(wikipedia.getSite(site), "User:"******"Wikipedia:OrphanOverleg/" + nsname.rstrip(':')) Q = querier.querier(verbose=True) statistiek = {} output = u"=Orphan-overlegpagina's " + nsname + unicode( now.strftime("(%Y%m%d, %H%M)=\n")) print "Ophalen orphanpagina's..." results = Q.do( "select p2.page_title, p2.page_id, p2.page_len from nlwiki_p.page as p1 right join nlwiki_p.page as p2 on p1.page_title = p2.page_title and p1.page_namespace=" + str(namespace) + " where p2.page_namespace=" + str(namespacetalk) + " and p1.page_title IS NULL;") print str(len(results)) + ' items;' output += str(len(results)) + 'items;' ok = wikipedia.input("Ctrl-c if not OK") workwith = list(results)
def mainloop (site, namespace): now = datetime.datetime(*time.localtime()[0:5]) #site = u'nl' #namespacepage = wikipedia.Page(wikipedia.getSite(site), wikipedia.input("Please give the namespace name:").rstrip(':') + ':'); namespacepage = wikipedia.Page(wikipedia.getSite(site), namespace.rstrip(":")+':'); namespacetalkpage = namespacepage.toggleTalkPage() namespace = namespacepage.namespace(); namespacetalk = namespacetalkpage.namespace(); nsname = namespacepage.title() nstname = namespacetalkpage.title() nsuname = wikipedia.Page(wikipedia.getSite(site), "User:"******"Wikipedia:OrphanOverleg/"+nsname.rstrip(':')) Q = querier.querier(verbose=True) statistiek = {} output = u"=Orphan-overlegpagina's "+nsname+unicode(now.strftime("(%Y%m%d, %H%M)=\n")) print "Ophalen orphanpagina's..." results = Q.do("select p2.page_title, p2.page_id, p2.page_len from nlwiki_p.page as p1 right join nlwiki_p.page as p2 on p1.page_title = p2.page_title and p1.page_namespace="+str(namespace)+" where p2.page_namespace="+str(namespacetalk)+" and p1.page_title IS NULL;") print str(len(results)) + ' items;' output += str(len(results)) + 'items;' #ok = wikipedia.input("Ctrl-c if not OK") workwith = list(results) metslash = "" for page in workwith: if (page['page_title'].rfind('/') > -1): if (len(metslash) != 0): metslash += " or cl_from=" metslash += str(page['page_id']) heeftcat = {}; if len(metslash) > 0: heeftcat = Q.do("select cl_from from nlwiki_p.categorylinks where cl_from=" + metslash + " and cl_to='Wikipedia:Archief';", transpose=True) if len(heeftcat) == 0: heeftcat = {'cl_from': []}; for page in workwith: if page['page_id'] in heeftcat['cl_from']: workwith.remove(page) geendeletes = []; print str(len(workwith)) + " pagina's om te verwerken" output += str(len(workwith)) + u" pagina's om te verwerken; " output += str(len(results)-len(workwith)) + u" pagina's genegeerd.\n" output += u'{| class = "prettytable"\n' output += u'|-\n' output += u'! rowspan=2 | Pagina\n' output += u'! colspan=4 | Hoofdpagina\n' output += u'|-\n' output += u'! Datum || Actie || Gebruiker || Reden\n' output += u'|-\n' for page in workwith: #retrieve deletion history delhist = Q.do("select log_timestamp, log_action, user_name, log_comment from nlwiki_p.logging inner join nlwiki_p.user_ids on log_user=user_id where log_namespace=0 and log_title=%s and log_type='delete' order by log_timestamp desc limit 1",page['page_title'], mediawiki=True); print page['page_title'] + " ("+str(len(delhist))+" deletes)" page = Q.doutf8(page) if len(delhist) == 0: geendeletes.append(page) continue output += u'| rowspan=' + str(len(delhist)) + u' | [['+nstname + page['page_title'].replace('_',' ') + u']]</br>(' + str(page['page_len']) + u' bytes)\n' for histitem in delhist: tstamp = time.strftime("%d %b %y, %H:%m", time.strptime(histitem['log_timestamp'],"%Y%m%d%H%M%S")) output += u'| ' + tstamp + u' || ' + histitem['log_action'] + u' || [[' + nsuname + histitem['user_name'] + u'|]] || <nowiki>' + histitem['log_comment'] + u'</nowiki>\n|-\n' if histitem['user_name'] in statistiek: statistiek.update({histitem['user_name']: statistiek[histitem['user_name']]+1}) else: statistiek.update({histitem['user_name']: 1}) output += u'|}\n\n' output += u"== Pagina's zonder deletion history ==\n" for page in geendeletes: output += u'* [[' + nstname + page['page_title'] + u']]\n' totaalover = len(workwith) - len(geendeletes) output += u'\n\n==Statistiek==\n' for pair in sorted(statistiek.iteritems(), key=lambda x: x[1], reverse=True): output += u'* [['+nsuname+pair[0]+u']] ('+str(pair[1])+u' pages (' + str(round((0.0+pair[1])*100/totaalover,1)) + u'%))\n'; P.put(output)
This bot tags uncategorized pages with a template. """ # # (C) Erwin (nl.wikipedia.org), 2007 # # Distributed under the terms of the CC-BY-SA 2.5 licence. # from __future__ import generators import sys sys.path.append("/home/erwin85/libs/python") sys.path.append("/home/erwin85/libs/pywikipedia") import re, querier import wikipedia, erwin85bot, pagegenerators db = querier.querier(host="sql-s2") def main(): wikipedia.handleArgs() wikipedia.setAction('Erwin85Bot: [[Sjabloon:nocat|nocat]] toegevoegd ([[:Categorie:Wikipedia:Nog te categoriseren]]).') noCatR = re.compile(r'\{\{([Xx]n|[Nn])ocat(\|[^\}]*?|)\}\}') excludeR = re.compile(r'\{\{(x{0,1}wiu|x{0,1}weg|nuweg|artikelweg|auteur|ne|reclame|wb|wiu2)(|\|[^\}]*?)\}\}', re.IGNORECASE) #List of page_titles which are treated titlelist = [] wikipedia.output(u'Getting a list of uncategorized articles.') sql = """ SELECT page_title FROM nlwiki_p.page
def main(): argv_length = len(sys.argv) if argv_length == 5: init() TIME = timeman.timeConvertor(sys.argv[1]) try: FROM = stations.getStationCode(sys.argv[2])['station_code'] except: print "出发站点不存在!" exit(1) try: TO = stations.getStationCode(sys.argv[3])['station_code'] except: print "目的站点不存在!" exit(1) print "查询中..." CDN = sys.argv[4] session = requests.Session() session.headers = { "Host": "kyfw.12306.cn", "Connection": "keep-alive", "Cache-Control": "max-age=0", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Encoding": "gzip, deflate, sdch, br", "Accept-Language": "zh-CN,zh;q=0.8,en;q=0.6", } queryResult = querier.querier(TIME, FROM, TO, "ADULT", session, CDN) length = queryResult.length for i in range(length): print "=" * 36 train_no = queryResult.getTrainNo(i) from_station_no = queryResult.getFromStationNo(i) to_station_no = queryResult.getToStationNo(i) seat_types = queryResult.getSeatTypes(i) train_date = TIME print "座位类型 :",seat_types priceResult = price.price(train_no, from_station_no, to_station_no, seat_types, train_date, session, CDN) qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" if tools.checkStringChars(seat_types, "OOMP"): qita_price = "--" wuzuo_price = priceResult.getPrice("WZ") yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = priceResult.getPrice("O") yidengzuo_price = priceResult.getPrice("M") tedengzuo_price = priceResult.getPrice("P") shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "OMP"): qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = priceResult.getPrice("O") yidengzuo_price = priceResult.getPrice("M") tedengzuo_price = priceResult.getPrice("P") shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "O9OMP"): qita_price = "--" wuzuo_price = priceResult.getPrice("WZ") yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = priceResult.getPrice("O") yidengzuo_price = priceResult.getPrice("M") tedengzuo_price = priceResult.getPrice("P") shangwuzuo_price = "A9" elif tools.checkStringChars(seat_types, "O9MP"): qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = priceResult.getPrice("O") yidengzuo_price = priceResult.getPrice("M") tedengzuo_price = priceResult.getPrice("P") shangwuzuo_price = priceResult.getPrice("A9") elif tools.checkStringChars(seat_types, "O9OM"): qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = priceResult.getPrice("O") yidengzuo_price = priceResult.getPrice("M") tedengzuo_price = "--" shangwuzuo_price = "A9" elif tools.checkStringChars(seat_types, "1413"): qita_price = "--" wuzuo_price = priceResult.getPrice("WZ") yingzuo_price = priceResult.getPrice("A1") yingwo_price = priceResult.getPrice("A3") ruanzuo_price = "--" ruanwo_price = priceResult.getPrice("A4") gaojiruanwo_price = "--" erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "OM9"): qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = priceResult.getPrice("O") yidengzuo_price = priceResult.getPrice("M") tedengzuo_price = "--" shangwuzuo_price = priceResult.getPrice("A9") elif tools.checkStringChars(seat_types, "OMO"): qita_price = "--" wuzuo_price = priceResult.getPrice("WZ") yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = priceResult.getPrice("O") yidengzuo_price = priceResult.getPrice("M") tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "14136"): qita_price = "--" wuzuo_price = priceResult.getPrice("WZ") yingzuo_price = priceResult.getPrice("A1") yingwo_price = priceResult.getPrice("A3") ruanzuo_price = "--" ruanwo_price = priceResult.getPrice("A4") gaojiruanwo_price = priceResult.getPrice("A6") erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "113"): qita_price = "--" wuzuo_price = priceResult.getPrice("WZ") yingzuo_price = priceResult.getPrice("A1") yingwo_price = priceResult.getPrice("A3") ruanzuo_price = "--" ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "O4"): qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = priceResult.getPrice("A4") gaojiruanwo_price = "--" erdengzuo_price = priceResult.getPrice("O") yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "24"): qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = priceResult.getPrice("A2") ruanwo_price = priceResult.getPrice("A4") gaojiruanwo_price = "--" erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "4"): qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = priceResult.getPrice("A4") gaojiruanwo_price = "--" erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "112"): qita_price = "--" wuzuo_price = priceResult.getPrice("WZ") yingzuo_price = priceResult.getPrice("A1") yingwo_price = "--" ruanzuo_price = priceResult.getPrice("A2") ruanwo_price = "--" gaojiruanwo_price = "--" erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "1416H3"): qita_price = priceResult.getPrice("OT")[0] wuzuo_price = priceResult.getPrice("WZ") yingzuo_price = priceResult.getPrice("A1") yingwo_price = priceResult.getPrice("A3") ruanzuo_price = "--" ruanwo_price = priceResult.getPrice("A4") gaojiruanwo_price = priceResult.getPrice("A6") erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "43"): qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = priceResult.getPrice("A3") ruanzuo_price = "--" ruanwo_price = priceResult.getPrice("A4") gaojiruanwo_price = "--" erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" elif tools.checkStringChars(seat_types, "46"): qita_price = "--" wuzuo_price = "--" yingzuo_price = "--" yingwo_price = "--" ruanzuo_price = "--" ruanwo_price = priceResult.getPrice("A4") gaojiruanwo_price = priceResult.getPrice("A6") erdengzuo_price = "--" yidengzuo_price = "--" tedengzuo_price = "--" shangwuzuo_price = "--" else: print "座位类型无法解析!" print "列车号 : ", queryResult.getStationTrainCode(i) print "列车编号 : ", queryResult.getTrainNo(i) print "是否可凭身份证进出站 : ", queryResult.getIsSupportCard(i) print "首发站 : ", queryResult.getStartStationName(i) print "终点站 : ", queryResult.getEndStationName(i) print "起始站 : ", queryResult.getFromStationName(i) print "到达站 : ", queryResult.getToStationName(i) print "出发时间 : ", queryResult.getStartTime(i) print "到达时间 : ", queryResult.getArriveTime(i) print "历时 : ", queryResult.getLishi(i) print "其他 [", qita_price, "] :", queryResult.getQitaNumber(i) print "无座 [", wuzuo_price, "] :", queryResult.getWuzuoNumber(i) print "硬座 [", yingzuo_price, "] :", queryResult.getYingzuoNumber(i) print "硬卧 [", yingwo_price, "] :", queryResult.getYingwoNumber(i) print "软座 [", ruanzuo_price, "] :", queryResult.getRuanzuoNumber(i) print "软卧 [", ruanwo_price, "] :", queryResult.getRuanwoNumber(i) print "高级软卧 [", gaojiruanwo_price, "] :", queryResult.getGaojiruanwoNumber(i) print "二等座 [", erdengzuo_price, "] :", queryResult.getErdengzuoNumber(i) print "一等座 [", yidengzuo_price, "] :", queryResult.getYidengzuoNumber(i) print "特等座 [", tedengzuo_price, "] :", queryResult.getTengdengzuoNumber(i) print "商务座 [", shangwuzuo_price, "] :", queryResult.getShangwuzuoNumber(i) else: print "命令 :" print " python %s [TIME] [FROM] [TO] [CDN]" % (sys.argv[0]) print "参数 : " print " [TIME] : 出发的日期 (今天|明天|后天|7天后|2017-02-26)" print " [FROM] : 出发地的中文名 , 支持模糊查询" print " [TO] : 目的地的中文名 , 支持模糊查询" print " [CDN] : 使用何地的CDN服务器(即网站的IP地址 , 可以通过 ping kyfw.12306.cn 获得)(123.123.123.123|kyfw.12306.cn)(如果使用本地CDN不能查询到票 , 可以对别的地域进行查询)"
""" # # (C) Erwin (nl.wikipedia.org), 2007 # # Distributed under the terms of the CC-BY-SA 2.5 licence. # from __future__ import generators import sys sys.path.append("/home/erwin85/libs/python") sys.path.append("/home/erwin85/libs/pywikipedia") import re, querier import wikipedia, erwin85bot, pagegenerators db = querier.querier(host="sql-s2") def main(): wikipedia.handleArgs() wikipedia.setAction( 'Erwin85Bot: [[Sjabloon:nocat|nocat]] toegevoegd ([[:Categorie:Wikipedia:Nog te categoriseren]]).' ) noCatR = re.compile(r'\{\{([Xx]n|[Nn])ocat(\|[^\}]*?|)\}\}') excludeR = re.compile( r'\{\{(x{0,1}wiu|x{0,1}weg|nuweg|artikelweg|auteur|ne|reclame|wb|wiu2)(|\|[^\}]*?)\}\}', re.IGNORECASE) #List of page_titles which are treated titlelist = []