User:BenSbot/Code2
Jump to navigation
Jump to search
Here is the code for the second function I was programmed to do. If you have any questions ask in the discussion page.
import wikipedia import catlib import pagegenerators import re text = "" site = wikipedia.getSite() linkslist = [] errorcount = 0 rea = re.compile('^:\\s*\\W{3,3}Encores?\\W{3,3}.*' , re.I | re.S | re.M) reb = re.compile('^[^#\\n].*$' , re.M) rec = re.compile('\\[\\[[^\\]]*\\]\\]') red = re.compile('^\\*\\s*City:.*$' , re.M) red2 = re.compile('\\*\\s*City:\\s*') ree = re.compile('^\\*\\s*Venue:.*$' , re.M) ree2 = re.compile('\\*\\s*Venue:\\s*') ref = re.compile('^\\*\\s*Date:.*$' , re.M) ref2 = re.compile('\\*\\s*Date:\\s*') reg = re.compile('(19|20)\\d\\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])') showscat = catlib.Category(site,'Category:Shows') showslist = list(pagegenerators.CategorizedPageGenerator(showscat)) for b in showslist: page = b.get() Setlist = reb.sub("",rea.sub("",page)) Encore = "" try: Encore = reb.sub("",rea.search(page).group()) except AttributeError: errorcount = errorcount + 1 City = "Unknown" try: City = red2.sub("",red.search(page).group()) except AttributeError: errorcount = errorcount + 1 Venue = "Unknown" try: Venue = ree2.sub("",ree.search(page).group()) except AttributeError: errorcount = errorcount + 1 Date = "" try: Date = ref2.sub("",ref.search(page).group()) except AttributeError: errorcount = errorcount + 1 Date2 = "" try: Date2 = reg.search(b.aslink()).group() except AttributeError: errorcount = errorcount + 1 setlinks = rec.findall(Setlist) for x in setlinks: Entry = [x,Date2,Date,City,Venue,"No",b.title()] linkslist.append(Entry) try: encorelinks = rec.findall(Encore) for x in encorelinks: Entry = [x,Date2,Date,City,Venue,"Yes",b.title()] linkslist.append(Entry) except NameError: errorcount = errorcount + 1 songscat = catlib.Category(site,'Category:Songs') songslist = list(pagegenerators.CategorizedPageGenerator(songscat)) for a in songslist: tablelist = [] count = 0 for b in linkslist: if a.aslink().lower() == b[0].lower(): tablelist.append(b) count = count + 1 if count != 0: tablelist.sort(lambda x,y: cmp(x[1], y[1])) text = "\"\'\'\'" + str(a.title()) + "\'\'\'\" was played at the following concerts: \n\n" + "{| border=\"1\"\n| \'\'\'Date\'\'\'\n| \'\'\'Location\'\'\'\n| \'\'\'Venue\'\'\'\n| \'\'\'Encore?\'\'\'\n" for b in tablelist: text = text + "|-\n" if str(b[2]) == "": text = text + "| [[" + str(b[6]) + "|" + str(b[1]) + "]]" else: text = text + "| [[" + str(b[6]) + "|" + str(b[2]) + "]]" text = text + "\n| " + str(b[3]) text = text + "\n| " + str(b[4]) text = text + "\n| " + str(b[5]) text = text + "\n" text = text + "|}\n\n[[Category:Show Statistics]]" name = wikipedia.Page(site, (str(a.title()) + "/Concerts")) name.put(text, u"Show Statistics") print "errorcount = " + str(errorcount) print "fin"