#!/usr/bin/python3# Convert the [[List_of_Internet_phenomena]] page into a navbox# the source code for that page should be saved as list.txtimportrelines=open("list.txt","r").read()r1=re.compile(r"(\* ?('''.*?''')|==(.*?)==)")r2=re.compile(r"\[\[.*?\]\]")matches=r1.findall(lines)# use list instead of dict to preserve orderinggroups=[]fortot,m1,m2inmatches:iflen(m1)==0:curgroup=m2.strip()groups.append((curgroup,[]))else:groups[-1][1].append(m1.strip())# remove non-linksgroups=[(k,list(filter(lambdax:"[["inx,v)))for(k,v)ingroups]# remove empty groupsgroups=[(k,v)for(k,v)ingroupsiflen(v)>0]print("""{{Navbox| name = Navbox/Memes| title = [[Internet Meme|Internet Memes]]| listclass = hlist""")i=1forname,elsingroups:print("| group{0} = {1}\n| list{0} = ".format(i,name))i+=1forelinels:ex=r2.findall(el)[0]print("*{0}".format(ex))print("}}")