User talk:AutostubLP2

From LPedia
Jump to navigation Jump to search

Source Code

The script as displayed may contain errors. To use, please copy from the wiki source. This runs in Python 2.6 or so. It might run in 2.5 or 2.4 in a pinch.

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                                               #
# Autostub LP2                                  #
#                                               #
# Reads from counties CSV file and generates    #
# XML to import into lpedia.org                 #
#                                               #
# By James Gholston                             #
#                                               #
# Uses source code from Autostub2, LP1, et c.   #
#                                               #
# Released to the public domain                 #
#                                               #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

import sys     # file I/O
import csv     # parsing csv data
import difflib # hueristics for checking name and title data in HISTORY to guess at needed formatting

BR = "<BR/>"

def Stringify(listish):
    stringish = "" 
    for q in listish:
        if type(q) == type('str'):
           stringish += q
           #print "str"
        elif type(q) == type([]):
           stringish += Stringify(q)
           #print "list"
        else: 
             print type(q)
             print q
             raise TypeError, "non-string non-list!!!"
    return stringish   


def ParseName(stringy, dofor):
    if dofor == "infobox":
       #if single item
       if stringy.count(";") == 0: return ParseNome(stringy) # + "\n"
       #else
       listy = stringy.split(";")
       output = []
       for q in listy:
           output += [ParseNome(q) + BR + "\n"]
       return Stringify(output)[:-12]
    #if single item
    if stringy.count(";") == 0: return ParseNome(stringy) + ", ''" +  dofor + "''" + BR #\n"
    #else
    listy = stringy.split(";")
    output = []
    for q in listy:
        output += [ParseNome(q) + ", ''" +  dofor + "''" + BR + "\n"]
    return Stringify(output)[:-1]

def ParseCommittee(stringy):
    listy = stringy.split(";")
    output = []
    for q in listy:
        qq = q.split(",")
        title = qq.pop()
        # q[:-(len(title)+1)] -- removing rightmost comma and the title entry
        output += [ParseName(q[:-(len(title)+1)], title)+"\n"]
        #output += ["<BR/>"]
    return Stringify(output)

def ParseDistricts(stringy):
    return "ParseDistricts() output"

def ParseAmbiguous(stringy):
    if stringy == "":     return ""
    # if len(stringy) == 1: print "** 1 character intput to ParseAmbiguous **"
    # print stringy
    listy = stringy.split(",")
    if len(listy) < 2: return "[[" + Stringify(listy) + "]]" + BR # fail-safe attempt
    IsItNameIn2 = difflib.SequenceMatcher(a=listy[0].upper(), b=listy[1].upper()).ratio()
    if IsItNameIn2 >= 0.5:
       if len(listy) == 2: return "[[" + listy[0] + "|" + listy[1] + "]]" + BR # fail-safe attempt
       PersonAndTitles = "[[" + listy[0] + "|" + listy[1] + "]], ''"
       for q in listy[2:]:
           PersonAndTitles += q + ", "
       return PersonAndTitles[:-2] + "''" + BR
    else:
       PersonAndTitles = "[[" + listy[0] + "]], ''"
       for q in listy[1:]:
           PersonAndTitles += q + ", "
       return PersonAndTitles[:-2] + "''" + BR

def ParseNome(stringy):
    if stringy == "": return ""
    if stringy.count(",") == 0: return "[[" + stringy + "]]"
    #assume it's two part here.  Don't send anything that isn't 1 or 2 parts.
    listy = stringy.split(",")
    return "[[" + listy[0] + "|" + listy[1] + "]]"
    
def FindTheName(stringy):
    "find the name in the string; kind of specialized to this specific application"
    if stringy.count(" ") == 0: return [stringy]
    listy = stringy.split(" ")
    outp = ""
    for q in listy:
        if q.upper() == "AT":           continue
        if q.upper() == "IN":           continue
        if q.upper() == "WITH":         continue
        if q.upper() == "A":            continue
        if q.upper() == "AN":           continue
        if q.upper() == "THE":          continue
        if q.upper() == "LIBERTARIAN":  continue
        if q.upper() == "PARTY":        continue
        if q.upper() == "OF":           continue
        if q.upper() == "LIBERTARIANS": continue
        outp += q + " "
    return outp[:-1]

def DePluralize(wordish):
    #print wordish
    wordish=wordish.strip()
    #print "WORDISH=", wordish
    #print "TRUNC=", wordish[:-2], wordish[:-1]
    if   wordish[-2:] == "es": return wordish[:-2]
    elif wordish[-1:] ==  "s": return wordish[:-1]
    return wordish
    #elif 1: raise TypeError, "No plural???"
    

def GrabYear(date):
    """"" Tries to grab a four digit year out of string called date
    """""
    def trynow(ddate):
        # trying last four
        try: 
            year = int(ddate[-4:])
            return year
        except ValueError: return None
    #trying backwards to find a good four numerals
    while len(date) >= 4:
          tryit = trynow(date)
          if tryit: return tryit
          date = date[:-1]
    return 0

def XMLproof(textish):
    outp = ""
    for q in textish:
        if   q == "<": outp += "<"
        elif q == ">": outp += ">"
        elif q == "&": outp += "&"
        elif q == '"': outp += """
        elif q == ":": outp += "%3A"
        else: outp += q
    return outp

def XMLproof2(textish):
    "Works ONLY on stray ampersands.  Hopefully."
    outp = ""
    qq = -1
    for q in textish:
        qq += 1
        if q == "&":
           if    textish[qq:qq+4] == "<":   outp += q
           elif  textish[qq:qq+4] == ">":   outp += q
           elif  textish[qq:qq+5] == "&":  outp += q
           elif  textish[qq:qq+6] == """: outp += q
           else: outp += "&"
        else: outp += q
    return outp
        
        
def ShellBRK(shell):
    # parse into chunks
    shells = shell.split(" ")
    
    # escape if only one chunk
    if len(shells) == 1: return shell
    
    # reassemble with breaks
    last = "0"
    outp = ""
    for q in shells:
        if last == "0": outp = q+" "; last=q[0]
        else:
             if q[0] == last: outp += q+" "; last = q[0]     #; print "nobreak"
             else: outp += "<BR/>"+q+" "; last = q[0]  #; print last, q[0]
    return outp        
                
def IsoParse(entry):
    # parse into chunks
    entries = entry.split(" ")
    
    # one isotope handling
    if len(entries) == 1:
       entry = entry.strip() 
       if entry == "none": return "This element has no stable isotopes.  "
       else: return "This element has a stable isotope of "+entry
        
    # two isotope handling
    if len(entries) == 2: return "This element has two stable isotopes: "+entries[0]+" and "+entries[1]+".  "

    # multiple isotopes
    outp = "This element has "+str(len(entries))+" stable isotopes: "
    last = entries.pop()
    for q in entries:
        outp += q+", " 
    return outp+"and "+last+".  "
                

def TmpBRK(stringish):
    # parse into chunks
    textish = stringish.split(" ")
    
    # escape if only one chunk
    if len(textish) == 1: return stringish
    
    # reassemble with breaks
    last = "0"
    outp = ""
    for q in textish:
        if last == "0": outp = q; last = q
        else:
             outp += "<BR/>"+q
    return outp        


def linebrk(listish):
    newlist = []
    for q in listish:
        #
        if type(q) == type(str()):
           newlist += [q+"\n"]
        else: 
             print q
             raise Exception
    return newlist 

def dostub(thisentry): 
    """Create stub article from database
    """
    #                                     
    # Set up variables to generate        
    # the county party article stub       
    #                                     
    # database: 00 A State name
    #           01 B County name
    #           02 C State Party Name
    #           03 D County Party Name
    #           04 E Website URL
    #           05 F Bylaws URL
    #           06 G Chair
    #           07 H Vice Chair
    #           08 I Treasurer
    #           09 J Secretary
    #           10 K Additional Committee Members
    #           11 L Districts
    #           12 M Logo name
    #           13 N Address
    #           14 O Is this information Current? Y if Yes
    #           15 P History
    #           16 Q Is this something other than a county?
    #           17 
    #           18 
    #                                     
    #%#%#%#%#%#%#%#%#%#%#%#%#%#%%#%#%#%#%#%#%#                             
                                             #                         
    COUNTY       =  "County"                 # What this polity is called -- usually county
                                             #
    STATE        =  thisentry["STATE"]       # short name of president (Grover Cleveland)
    COUNTYNAME   =  thisentry["COUNTYNAME"]  # name of county
    STATEPARTY   =  thisentry["STATEPARTY"]  # state party name
    COUNTYPARTY  =  thisentry["COUNTYPARTY"] # county party name
    COUNTYLINK   =  thisentry["COUNTYLINK"]  # county party URL
    BYLINK       =  thisentry["BYLINK"]      # county bylaws URL
    CHAIRNAME    =  thisentry["CHAIRNAME"]   # county chair name
    VICENAME     =  thisentry["VICENAME"]    # vice chair name(s)
    TREASNAME    =  thisentry["TREASNAME"]   # treasurer name
    SECNAME      =  thisentry["SECNAME"]     # secretary name
    COMMITTEE    =  thisentry["COMMITTEE"]   # additioenal committee members and titles
    DISTRICTS    =  thisentry["DISTRICTS"]   # in California, the region number
    LOGONAME     =  thisentry["LOGONAME"]    # name of logo
    ADDRESS      =  thisentry["ADDRESS"]     # county party address
    CURRENT      =  thisentry["CURRENT"]     # is this current? Y if yes
    HISTORY      =  thisentry["HISTORY"]     # county party history
    NONCOUNTY    =  thisentry["NONCOUNTY"]   # Is this something other than a county?
    OTHERLINKS   =  thisentry["OTHERLINKS"]  # other county links
    INSTITUTION  =  thisentry["INSTITUTION"] # is this part of an institution?  Which?
    ADDRESS      =  thisentry["ADDRESS"]     # snail address
                                             #                             
                                             #                             
    #%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%%#%#%#%#%#                             
    #                                     
    # start generating the article here:  
    #                                     

    print COUNTYNAME
    
    if NONCOUNTY: COUNTY = NONCOUNTY
    
    NAMELIST = []
    if COUNTYPARTY.count(","):
       NAMELIST   = COUNTYPARTY.split(",")
       COUNTYPARTY = NAMELIST[0]
    
    to_out = []

    # original, non-template infobox
    #    to_out += ["{"+"| style=\"align: right; float: right; border: 1px #AFAFAF solid\""]
    #    to_out += ["|" + "+ <DIV width=\"100%\" style=\"background-color:#CCCCFF\"><BIG>'''" + COUNTYNAME + " LP'''</BIG></DIV>"]
    #    to_out += ["| '''Chair'''            || [[" + CHAIRNAME + "]]"]
    #    to_out += ["|-"]
    #    to_out += ["| '''Vice Chair'''       || [[" + VICENAME + "]]"]
    #    to_out += ["|-"]
    #    to_out += ["| '''Treasurer'''        || [[" + TREASNAME + "]]"]
    #    to_out += ["|-"]
    #    to_out += ["| '''Secretary'''        || [[" + SECNAME + "]]"]
    #    to_out += ["|- width=\"100%\" bgcolor=\"#CCCCFF\""]
    #    to_out += ["! colspan=\"2\" | <BIG>'''Logo'''</BIG>"]
    #    to_out += ["|-"]
    #    to_out += ["! colspan=\"2\" | [[Image:" + LOGONAME + "|120px]]"]
    #    to_out += ["|- width=\"100%\" bgcolor=\"#CCCCFF\" "]
    #    to_out += ["! colspan=\"2\" | <BIG>'''Districts'''</BIG>"]
    #    to_out += ["|-"]
    #    to_out += ["| colspan=\"2\" | [[:Category:Counties in " + STATE + " " + BODY + " District " + DISTNO + "|" + DISTNUM + STATE + BODY + "]]"]
    #    to_out += ["|-"]
    #    to_out += ["| colspan=\"2\" | [[:Category:Counties in " + STATE + " US Congressional District " + DISTNO + "|" + DISTNUM + " US Congress]]"]
    #    to_out += ["|" + "}"]

    if STATE == "California":
       if LOGONAME: to_out += ["{{Infobox_California_County"]
       else:        to_out += ["{{Infobox_California_County_Nologo"]

    else:
         if LOGONAME: to_out += ["{{Infobox_County"]
         else:        to_out += ["{{Infobox_County_Nologo"]

    # Is this a single county party?
    numbercounties = 1
    if COUNTYNAME.count(",") > 0: 
       COUNTYNAMES = COUNTYNAME.split(",")
       numbercounties = len(COUNTYNAMES)

    if COUNTY.upper() == "County":
       if numbercounties == 1:       to_out += ["| COUNTY     = " + COUNTYNAME + " " + COUNTY + " LP"]
       else:                         to_out += ["| COUNTY     = " + FindTheName(COUNTYPARTY) + " " + COUNTY + " LP"]
    elif COUNTY.upper() == "CAMPUS": to_out += ["| COUNTY     = " + COUNTYPARTY]
    else:                            to_out += ["| COUNTY     = " + FindTheName(COUNTYPARTY) + " " + COUNTY + " LP"]

    to_out += ["| CHAIR      = " + ParseName(CHAIRNAME, "infobox")]
    to_out += ["| VICE_CHAIR = " + ParseName(VICENAME,  "infobox")]
    to_out += ["| TREASURER  = " + ParseName(TREASNAME, "infobox")]
    to_out += ["| SECRETARY  = " + ParseName(SECNAME,   "infobox")]
    
    if LOGONAME: to_out += ["| LOGO       = [[Image:" + LOGONAME + "|120px]]"]
    
    if STATE == "California": to_out += ["| REGION = " + DISTRICTS]
    # Giving up on districts -- I can't find the data in a sufficiantly usable form
    # to_out += ["| DISTRICTS  = " + ParseDistricts(DISTRICTS)]
    to_out += ["}}"]

    to_out += [""]

    if CURRENT != "Y":
       to_out += ["{{Possibly Obsolete}}"]
       
       to_out += [""]
       
    if STATE == "California":
       to_out += ["The '''" + COUNTYPARTY + "''' is a " + COUNTY.lower() + " affiliate of the [[" + STATEPARTY + "]]."]
    else:
         to_out += ["The '''" + COUNTYPARTY + "''' is an affiliate of the [[" + STATEPARTY + "]].  "]
    to_out += [""]
    
    if NAMELIST:
       if len(NAMELIST) == 2:
          to_out += ["It has also been known as '''"+NAMELIST[1]+"'''.  "]
       else:
            alsoknown = "It has also been known as '''"
            for qq in range(len(NAMELIST)-1):
                if qq == len(NAMELIST)-3:
                   alsoknown += NAMELIST[qq+1] + ", and "
                else: alsoknown += NAMELIST[qq+1] + ", "
            to_out += [alsoknown[:-2]+"'''.  "]
       to_out += [""]
       
    if INSTITUTION:
       if COUNTY.upper() == "CAMPUS":
          to_out += ["It is a "+INSTITUTION+" student organization.  "]
       else:
            to_out += ["It is connected to "+INSTITUTION+".  "]
       to_out += [""]
       
    if numbercounties > 1:
       if numbercounties == 2:
          partylist = COUNTYNAMES[0] + " and " + COUNTYNAMES[1]
       else:
            partylist = ""
            lastcounty = len(COUNTYNAMES)
            for qq in range(lastcounty):
                partylist += COUNTYNAMES[qq] + ", "
                if qq == lastcounty-2: partylist += "and "
            partylist = partylist[:-2]
       to_out += ["It includes " + partylist + " counties.  "]
       to_out += [""]
           
    if numbercounties == 1 and (COUNTY == "Regional" or 
                                COUNTY == "Affiliate" or 
                                COUNTY == "Campus"): # and STATE == "California":
       to_out += ["It is located in " + COUNTYNAME + " County.  "]
       to_out += [""]
#    to_out += [""]
#    to_out += [""]

    to_out += ["==Executive Committee=="]
    if CHAIRNAME: to_out += [ParseName(CHAIRNAME, "chair")]
    if VICENAME:  to_out += [ParseName(VICENAME,  "vice chair")]
    if TREASNAME: to_out += [ParseName(TREASNAME, "treasurer")]
    if SECNAME:   to_out += [ParseName(SECNAME,   "secretary")]
    # to_out += [""]

    # need a loop here to cycle through the rest of the committee
    if COMMITTEE: 
       to_out += [ParseCommittee(COMMITTEE)]
    to_out += [""]

    
    to_out += [""]

    to_out += ["==Past Officials, Staff, and Other Contacts=="]
    if HISTORY:
       # print "We have HISTORY"
       for q in HISTORY.split(";"):
           # print q
           to_out += [ParseAmbiguous(q)]
    else:
         to_out += ["There is no historical information for this county party. You can improve LPedia.org by listing past members."]

    to_out += [""]
    to_out += [""]

    # make an external links header?
    Numberoflinks = 0
    if COUNTYLINK: Numberoflinks += 1
    if BYLINK:     Numberoflinks += 1
    if OTHERLINKS: Numberoflinks += len(OTHERLINKS.split(";"))
    if Numberoflinks:
       if Numberoflinks == 1: to_out += ["==External Link== "]
       else:                  to_out += ["==External Links== "]
       if COUNTYLINK:         to_out += ["* [" + COUNTYLINK + " " + COUNTYPARTY + "]"]
       if BYLINK:             to_out += ["* [" + BYLINK + " " + COUNTYPARTY  + " bylaws]"]
       if OTHERLINKS:
          otherlinks = OTHERLINKS.split(";")
          for q in otherlinks:
              qq = q.split(",")
              # print "qq == ",qq
              if len(qq) == 1: qq += ["** UNDEFINED **"]
              to_out += ["* [" + qq[0] + " " + qq[1] + "]"]
       
    to_out += [""]

    if ADDRESS:
       to_out += ["==Address=="]
       to_out += [ADDRESS]

    to_out += [""]
    to_out += [""]
    
    if   COUNTY == "Parish":  COUNTIES = "Parishes"
    elif COUNTY == "Burough": COUNTIES = "Boroughs" 
    else:                     COUNTIES = "Counties"

    if COUNTY.upper() == "CAMPUS":
       to_out += ["{{" + STATE + "_" + "Campus_Organizations}}"]
    else:
         to_out += ["{{" + STATE + "_" + COUNTIES + "}}"]
    to_out += [""]
    to_out += [""]
            
    to_out += ["{"+"{Autostub}"+"} <!-- {{Proofed Autostub}} replace autostub tag with this one if you're sure there are no automatically caused errors.  Thank you. -->"]
    to_out += [""]


    to_out += ["{{Public Domain}}"]
    to_out += [""]
    
    # to_out += ["[[Category:Testing|" + COUNTYNAME + "]]"]
    SORTNAME = COUNTYNAME
    if numbercounties != 1: SORTNAME = FindTheName(COUNTYPARTY)
    if COUNTYPARTY.upper().count(COUNTYNAME.upper()) == 0: SORTNAME = FindTheName(COUNTYPARTY)
    
    if COUNTY.upper() == "CAMPUS":
       to_out += ["[[Category:" + STATE + " Campus Organizations|" + SORTNAME + "]]"]
    elif STATE == "California":
         to_out += ["[[Category:California County and Regional Parties|" + SORTNAME + "]]"]
    elif STATE == "Colorado":
         to_out += ["[[Category:Colorado County and Affiliate Parties|" + SORTNAME + "]]"]
    else:
         to_out += ["[[Category:" + STATE + " " + COUNTY + " Parties|" + SORTNAME + "]]"]
    
    # Insert district categorizations here

    to_out += [""]
    #to_out += ["<!-- This article was originally generated by AutostubLP1, an article creation script based on Lunarpedia.org's Autostub2 -->"]
    to_out += ["<!-- This article was generated by AutostubLP2 -->"]

    to_out = linebrk(to_out)
    to_out = XMLproof(to_out)

    return to_out
    
    

# def main():
#     # load database
#     didxml = templatetop()
#     for q in database: didxml += dostub(q) + templatemid(); print ".",
#     didxml += templatefin()
#     # save didxml


def tidypipes(table):
    """takes a list oy strings, finds the longest one, and tidily adds pipes to the right of each line.

    maxlen: maximum length
    table:  input list of strings
    table2: output list of strings
    """
    maxlen = 0
    for q in table:
        if len(q)>maxlen: maxlen = len(q)
    table2 = []
    for q in table:
        qq = q
        while (len(qq)<maxlen):
              qq += " "
        table2 += [qq+" |"]
    return table2

def LtBlau(textish):
    return "<FONT color="#7F7FFF">"+textish+"</FONT>"

def replacer(stringie, old, new):
    """
    """
    name2=""
    for q in stringie:
        if q == old: name2 += new
        else: name2 += q
    return name2

def refbreak(ref):
    """
    """
    return replacer(ref,";",";<BR/>")


def get_element(number,shift):
    """if a number is a number, return the element symbol corresponding to number+shift
    """
    global DB
    #if number = "N/A": return "N/A"
    #print number, shift
    try:
        number = int(number)
    except: return "<SMALL><FONT color="#7F7F7F">N/A</FONT></SMALL>"
    if number+shift>118: return "<SMALL><FONT color="#7F7F7F">N/A</FONT></SMALL>" #; print ">=118"
    if number+shift<1: return "<SMALL><FONT color="#7F7F7F">N/A</FONT></SMALL>" #; print "<=1"
    #print "no special cases"
    #print "[[Mediawiki:Sandbox|"+str(DB[number+int(shift)][1])+"]]"
    return "[["+str(DB[number+int(shift)][2])+"|"+LtBlau(str(DB[number+int(shift)][1]))+"]]"

##def ():
##    """
##    """
##    return "() not implemented"


def StartXML():
    out  = [['<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">\n']]
    out +=  ['    <siteinfo>\n']
    out +=  ['        <sitename>LPedia</sitename>\n']
    out +=  ['    </siteinfo>\n']
    return out

def EndXML():
    out  = [['</mediawiki>\n']]
    return out

def ArtXML(title, contrib, date, text):
    '''XML markup for article in file
    title --   title of article
    contrib -- name of script (ie Autostub2)
    text --    the article
    '''
    out  = [['    <page>\n']]
    if title.count(",") == 0:
       out +=  ['        <title>'+title+'</title>\n']
    else:
         # Special handling for multiple names -- always make the first the current one 
         out +=  ['        <title>'+title.split(",")[0]+'</title>\n']
    out +=  ['        <revision>\n']
    out +=  ['            <timestamp>'+date+'</timestamp>']
    out +=  ['            <contributor>\n']
    out +=  ['                <username>'+contrib+'</username>\n']
    out +=  ['            </contributor>\n']
    #out += ['            <text xml:space="preserve">'+text+'</text>']
    out +=  ['            <text xml:space="preserve">']
    #print text
    out +=  text
    out +=  ['</text>\n']
    out +=  ['        </revision>\n']
    out +=  ['    </page>\n']
    return out

# TSV sorter
# Public Domain

def TSVinput(filename):
    """tab separated database parser
    """
    # Open filename
    tsv=open(filename)
    # Convert to list
    ## get list of lines
    biglist = tsv.readlines()
    #for q in tsv:
    #    biglist += q
    tsv.close()
    ## parse lines
    #for q in biglist: print q
    newlist = []
    for q in biglist:
        newlist += [q.split("\t")]
        # print max(max(newlist))
    # return list
    return newlist


#Item = ["28","Ni","Nickel","58.6934000000","N/A","46","","","10"]
#Item = ["26","Fe","Iron","55.8450000000","N/A","44","important","ubiquietous","8"]
#Atomic number, symbol, name, atomic mass, previous in group, next in group, importance, availahbility, group number


#What=dostub(Item)


#Get 1-116 and 118 from the dataset into 'getit'

#DB=TSVinput("/home/Luna/Elements_H211_0039.csv")

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                                               #
# INSERT NAME OF CSV DATA FILE HERE:            #
#                                               #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

DB = csv.DictReader(open("/home/strangelv/work/LPedia/LPCO_L904_FINAL.csv")) 

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                                               #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

#"/home/strangelv/work/LPedia/CALP_Counties_Test_L817_1.csv"))
#getit = []

#for q in range(117):
#    if q > 0: getit += [DB[q]]
doDB = []
for q in DB:
    doDB += [q]

print len(doDB)

#getit = []
#for q in doDB:
#     if q["redirects"]:
#      getit += [q]
getit = doDB #[doDB[17]]

# print ArtXML(getit[2],"Autostub2","2007-02-11T00:00:00Z",dostub(getit))

#getit = DB[0]
#print "don't do ", getit[2] #don't do "Name"

gotit =  StartXML()
#print DB[26][2]
#print DB[6][2]

# print "*****", getit

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                                               #
# SET TIME FOR DOCUMENTS CREATION HERE:         #
#                                               #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

ARTICLETIME = "2011-09-04T20:15:00Z"

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                                               #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

for q in getit:
    #print "*", q[2], q[9]
    gotit += ArtXML(q["COUNTYPARTY"],"AutostubLP2",ARTICLETIME,dostub(q))
gotit += EndXML()


     

outdone = XMLproof2(Stringify(gotit))

print "** DONE **"
#print outdone

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                                               #
# SET NAME OF OUTPUT FILE HERE:                 #
#                                               #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

DESTINATION = '/home/strangelv/work/LPedia/autostubLP2_L904_2015.xml'

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                                               #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

do_xml=open(DESTINATION, 'w')
do_xml.write(outdone)
do_xml.close()

print "Saved to ", DESTINATION

Example CSV

The script as displayed may contain errors. To use, please copy from the wiki source.

This is a test CSV that should work with AutostubLP2. Please don't import its output to LPedia.org. Uncomment the 'print outdone' line at the end of AutostubLP2 to display the output XML to your console. Please save as as CSV file, such as "example.csv" -- and save to a path you can enter in the indicated part of the source code above if you wish to test it. It might go faster to let James do that part, though.

Listings usually go 'name to link as', ['name to display as' -- people only],title1,title2,... and with semocolons between people.

The NONCOUNTY column is where you indicate that it's a city party or a parish party or a regional party or a borough party or similar. With this we could theoretically run Guam or similar though it The DISTRICT column was for an idea I couldn't find the data to make work and ambushed it for regions numbers. HISTORY only includes people, not a text description. CURRENT is if the information is reasonably confident that it's not showing obsolete information as current -- this also includes no committee for parties known to be inoperative and for regions, counties, et c. that no longer exist.

If a needed column isn't found, PLEASE REQUEST IT and suggest a name for it. It can be easily added to AutostubLP2. The hard part is the data gathering.

"STATE","COUNTYNAME","STATEPARTY","COUNTYPARTY","COUNTYLINK","BYLINK","CHAIRNAME","VICENAME","TREASNAME","SECNAME","COMMITTEE","DISTRICTS","LOGONAME","ADDRESS","CURRENT","HISTORY","NONCOUNTY","OTHERLINKS","INSTITUTION","EMAILS"
"Arizona","Coconino","Arizona Libertarian Party","Coconino County Libertarian Party ","http://www.coconinolpaz.org/",,"George Squyres",,,,,,,,,,,,,
"Arizona","Maricopa","Arizona Libertarian Party","Maricopa County Libertarian Party","http://www.lpmaricopa.org/",,"Jim Iannuzo","Bill Barker;Michael Kielsky","Joe Cobb","Nick Coons","Sean Shepherd,Assistant Treasurer;Chris Will,Assistant Secretary",,,"Maricopa County Libertarian Party;P.O. Box 55282;Phoenix, AZ 85078-5282","Y",,,,,
"California","Amador,Calaveras,Tuolumne","Libertarian Party of California","Gold Country Libertarians","http://www.fredtyg.freeservers.com/Goldcountry.html",,"Al Segalla ",,,,,3,,,,"J. C. Anderson,vice chair (c. 1995);Lynn Badler,secretary (c. 1995);Steve Green,chair (c. 1995);Betsy Hayward,treasurer (c. 1995);Al Segalla,chair (2001?-)","Regional",,,"alsegalla@mindspring.com"
"California","Nevada","Libertarian Party of California","Nevada County Libertarian Party",,,,,,,,29,"nclp-banner-hack.png",,,"Lance Brown,chair (c. 2001);Gary A. Dusseljee,chair (c. 1995);Bob Glassco,vice chair (c. 2001);Sue Glassco,vice chair (c. 2001);Nancy Peirce,treasurer (c. 2001),secretary (c. 2001)",,"http://web.archive.org/web/20030518191711/http://www.nclp.org/photos.htm,photos;http://web.archive.org/web/20021004200332/http://www.nclp.org/posters/index.htm,posters",,
"California","Orange","Libertarian Party of California","Libertarian Party of Orange County","http://www.lpoc.org/",,"Tom Hanson",,"Bob Booth","Chad Jackson","Don Sutton,northern district chair;Brian Squires,Southern District Chair;Tim Thein,technology officer",30,,,"Y","Geoff Braun,chair (c. 1995);Vic Wagner,vice chair (c. 1995); Tom Reimer,secretary (c. 1995);Paul Studier,treasurer (c. 1995)",,,,"***** http://www.lpoc.org/contact"
"California","Fresno,Madera,Tulare,Kings, Mariposa","Libertarian Party of California","Valley Libertarians","http://web.archive.org/web/19980224061943/http://www.valleylibertarians.org/",,"N/A","N/A","N/A","N/A",,10,"vllogo1.jpg","P.O. Box 15246 Fresno, CA 93702 (presumed defunct)","Y","Pamela Pescosolido,chair (?-1997?);Rodney Austin,editor (c. 1997),chair pro tem (1996?-?),membership chair (c. 1996);Jonathan Richter,chair (c. 1994);Joseph Peacock,Joseph Peacock II, activities chair (c. 1996);Gina Miller,membership director (c. 1996);Delores Comstock,vp (c. 1996);Dan Tiffin,outreach director (c. 1996);Jon Flo,treasurer (c. 1996)","Regional","http://web.archive.org/web/19970620105157/http://www.valleylibertarians.org/newsletters.htm,newsletters",,
"Colorado","Adams","Libertarian Party of Colorado","Adams State College Libertarians",,,,,,,,,,,"Y","Cate Varhely,chair? (1998?-2000)","Campus",,"Adams State College",
"Colorado","Larimer","Libertarian Party of Colorado","Libertarian Party at Colorado State University,CSU Campus Libertarians","http://web.archive.org/web/*/http://www.lpcsu.org/","http://web.archive.org/web/20070123235326/http://www.lpcsu.org/documents/LPCSUConst-Bylaws.pdf","Kristian Morey",,,,"Eric Skousen,unknown",,,"Lory Student Center    Student Org. Box 317    Colorado State University    Fort Collins, CO 80523","Y","Seth Anthony, chair (2006?-2007),treasurer (c. 2007);Ian Bezek,co-chair (c. 2007);Seth Dilday,chair (c. 2005);Bruce Lockhart,chair? (CSU Campus Libertarians, 1998?-2000);Ben Prytherch,treasurer (2006?-2007),co-chair (c. 2007);Samantha Sly,treasurer (c. 2005)","Campus",,"Colorado State University",
"Colorado","Fremont","Libertarian Party of Colorado","Fremont County",,,,,,,,,,,,"Philip Freytag,chair (c. 1995)",,,,
"Florida","Escambia","Libertarian Party of Florida","Escambia County Libertarian Party","http://www.escambialp.org/",," Christopher M. Barra,Christopher Barra",,"Ross Calloway",,,5,,,,,,"http://libertarian.meetup.com/437/,Meetup group",,