Difference between revisions of "User:BenSbot/Code2"
Jump to navigation
Jump to search
m (updated code) |
m (woops, missed a colon) |
||
Line 113: | Line 113: | ||
text = text + "|}\n\n[[Category:Show Statistics]]" | text = text + "|}\n\n[[Category:Show Statistics]]" | ||
page = wikipedia.Page(site, (str(a.title()) + "/Concerts")) | page = wikipedia.Page(site, (str(a.title()) + "/Concerts")) | ||
− | if text != page.get() | + | if text != page.get(): |
page.put(text, u"Show Statistics") | page.put(text, u"Show Statistics") | ||
Revision as of 11:02, 10 August 2008
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 = [] rea = re.compile('^:\\s*\\W{3,3}(First\\s*)?Encores?\\W{3,3}.*' , re.I | re.S | re.M) reb = re.compile('^:\\s*\\W{3,3}Encores?\\W{3,3}.*' , re.I | re.S | re.M) rec = re.compile('^:\\s*\\W{3,3}First\\s*Encores?\\W{3,3}.*' , re.I | re.S | re.M) red = re.compile('^:\\s*\\W{3,3}Second\\s*Encores?\\W{3,3}.*' , re.I | re.S | re.M) ree = re.compile('^[^#\\n].*$' , re.M) ref = re.compile('\\[\\[[^\\]]*\\]\\]') reg = re.compile('^\\*\\s*City:.*$' , re.M) reg2 = re.compile('\\*\\s*City:\\s*') reh = re.compile('^\\*\\s*Venue:.*$' , re.M) reh2 = re.compile('\\*\\s*Venue:\\s*') rei = 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 show in showslist: page = show.get() title = show.title() Setlist = ree.sub("",rea.sub("",page)) Encore = "" a = reb.search(page) if a != None: Encore = ree.sub("",red.sub("",a.group())) FirstEncore = "" b = rec.search(page) if b != None: FirstEncore = ree.sub("",red.sub("",b.group())) SecondEncore = "" c = red.search(page) if c != None: SecondEncore = ree.sub("",c.group()) City = "Unknown" d = reg.search(page) if d != None: City = reg2.sub("",d.group()) Venue = "Unknown" e = reh.search(page) if e != None: Venue = reh2.sub("",e.group()) Date = "" g = rei.search(show.aslink()) if g != None: Date = g.group() setlinks = ref.findall(Setlist) for x in setlinks: Entry = [x,Date,City,Venue,"No",title] linkslist.append(Entry) encorelinks = ref.findall(Encore) for x in encorelinks: Entry = [x,Date,City,Venue,"Yes",title] linkslist.append(Entry) firstencorelinks = ref.findall(FirstEncore) for x in firstencorelinks: Entry = [x,Date,City,Venue,"First",title] linkslist.append(Entry) secondencorelinks = ref.findall(SecondEncore) for x in secondencorelinks: Entry = [x,Date,City,Venue,"Second",title] linkslist.append(Entry) 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" text = text + "| [[" + str(b[5]) + "|" + str(b[1]) + "]]" text = text + "\n| " + str(b[2]) text = text + "\n| " + str(b[3]) text = text + "\n| " + str(b[4]) text = text + "\n" text = text + "|}\n\n[[Category:Show Statistics]]" page = wikipedia.Page(site, (str(a.title()) + "/Concerts")) if text != page.get(): page.put(text, u"Show Statistics") print "fin"