Lunarpedia talk:Autostub2 test 1

From Lunarpedia
Revision as of 01:13, 2 February 2007 by Jarogers2001 (talk | contribs) (Autostub support)
Jump to: navigation, search

Comments

Please fire away!


Is it possible to expand support for extra information if I add it into the spreadsheet and template? Jarogers2001 01:13, 2 February 2007 (PST)

Source code

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                             #
# Element Autostub Generator  #
#                             #
# Public Domain               #
#                             #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

def dostub(thisentry): 
    """Create stub article from database
    """
    #                                     
    # Set up variables to generate        
    # the element article stub            
    #                                     
    # database: 00 Atomic number          
    #           01 symbol                 
    #           02 name                   
    #           03 atomic mass            
    #           04 previous in group      
    #           05 next in group          
    #           06 importance             
    #           07 availability           
    #           08 group number           
    #                                     
    #           ungrouped by IUPAC are    
    #           given group 19            
    #                                     
    #%#%#%#%#%#%#%#%#%#%#%#%#%#%%#%#%#%#%#
                                         #
    name   = thisentry[2]                # name of element (Iron)      
    symbol = thisentry[1]                # element symbol  (Fe)        
    number = thisentry[0]                # atomic number   (26)        
    mass   = thisentry[3]                # atomic mass     (55.845)    
    gprev  = thisentry[4]                # up one          (none)      
    gnext  = thisentry[5]                # down one        (Ruthenium) 
    imp    = thisentry[6]                # importance      (important) 
    avail  = thisentry[7]                # availability    (ubiquitous)
    group  = thisentry[8]                # in this group   (8)         
                                         #
    #%#%#%#%#%#%#%#%#%#%#%#%#%#%%#%#%#%#%#
    #
    # start generating the article here:
    #
    to_out  = []
    to_out += ["{{Element      "]
    to_out += ["name=" + name]
    to_out += ["symbol=" + symbol]
    to_out += ["available=" + avail]
    to_out += ["need=" + imp]
    to_out += ["number=" + number]
    to_out += ["mass=" + str(float(mass))]
    to_out += ["group=" + group]
    to_out += ["period="]
    to_out += ["phase="]
    to_out += ["series="]
    to_out += ["density="]
    to_out += ["melts="]
    to_out += ["boils="]
    to_out += ["isotopes="]
    to_out += ["prior="+get_element(number,-1)]
    to_out += ["next="+get_element(number,1)]
    to_out += ["above="+get_element(gprev,0)]
    to_out += ["aprior="+get_element(gprev,-1)]
    to_out += ["anext="+get_element(gprev,1)]
    to_out += ["below="+get_element(gnext,0)]
    to_out += ["bprior="+get_element(gnext,-1)]
    to_out += ["bnext="+get_element(gnext,1)]
    
    # Tidily install pipes for the table 
    to_out = tidypipes(to_out)
    
    to_out += ["}}"]

    to_out +=["{{Script Test}}"]    
    
    to_out += ["'''"+name+"''' is a "+"''(type of element)''"+" in the "+"''(series)''"+" series."]
    to_out += ["<BR/><BR/>\n\n"]
    to_out += [""]
    to_out += [""]
    to_out += [""]
    to_out += ["{"+"{Test Autostub}"+"}"]
    # to_out += docategories(typecat) #["[[Category:"+typecat+"]]"]
    to_out += ['<DIV ID="catlinks"><P CLASS="catlinks">[[Special:Categories&article=Lunarpedia%3AAutostub1_test_1|Categories]]: [[:Category:Stubs|Stubs]] | [[:Category:Elements|Elements]]']
    to_out += ["</P></DIV><!-- fake category box -- see commented out text above for actual script output -->"]
    to_out += ["<!-- Generated by a too-early version of Autostub2 -->"]

    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 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
    """
    #if number = "N/A": return "N/A"
    try:
        number = int(number)
    except: return "N/A"
    return "[[Mediawiki:Sandbox|"+str(number+int(shift))+"]]"

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




#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)
for q in What: print q