示例#1
0
def printPageAsHTML(player, year, templateFileName):
    '''
    This function prints out a main template of our web page in html format. It also
    decides based on user input what type of search to run: get all players in one 
    year, get one specific player, or get the stats for one player over his entire career.
    The parameters are all strings. Player refers to the column for player name, year refers 
    to the nba year and templatheFileName is the html file we are printing to.
    '''
    tableString = ""
    outputText = ""
    # If player and year were entered, get one specific player
    if player and year:
        if testYearInput(year):
            sqlList = sqlPlayerYearQuery(player, year)
            tableString = makeTable.makeTableFromQuery(sqlList)
            if tableString is None:
                tableString = """<p><font color="white">Invalid input or query was not resolved</font></p>"""

        else:
            tableString = """<p><font color="white">Invalid input or query was not resolved</font></p>"""
    
    # Otherwise if only year was entered, get all player data for that year
    elif year != "":
        if testYearInput(year):
            sqlList = sqlYearQuery(year)
            tableString = makeTable.makeTableFromQuery(sqlList)
            if tableString is None:
                tableString = """<p><font color="white">Invalid input or query was not resolved</font></p>"""
        else:
            tableString = """<p><font color="white">Invalid input or query was not resolved</font></p>"""
    
    # If user only entered player, get all data concerning the player
    elif player != "":
        sqlList = sqlPlayerQuery(player)
        tableString = makeTable.makeTableFromQuery(sqlList)
        if tableString is None:
                tableString = """<p><font color="white">Invalid input or query was not resolved</font></p>"""

# Open template file ("results.html")
    try:
        f = open(templateFileName)
        templateText = f.read()
        f.close()
        outputText += templateText % (tableString)
    except Exception, e:
        outputText = 'Cannot read template file "%s".' % (templateFileName)
示例#2
0
def printPageAsHTML(team, year, templateFileName):
    '''
    This function prints out a main template of our web page in html format, taking
    in team and year as strings, and templateFileName as a file. 
    '''
    tableString = ""
    # Check for errors. If the sqlList is empty return an error message.
    if team and year:
        sqlList = sqlQueryGetTeam(team, year)
        tableString = makeTable.makeTableFromQuery(sqlList)
    
    # Print html template along with inserted table to standard output 
    outputText = ''
    try:
        f = open(templateFileName)
        templateText = f.read()
        f.close()
        outputText = templateText % (tableString)
    except Exception, e:
        outputText = 'Cannot read template file "%s".' % (templateFileName)
示例#3
0
def printPageAsHTML(team, year, templateFileName):
    '''
    This function prints out a main template of our web page in html format, taking
    in team and year as strings, and templateFileName as a file.
    '''
    tableString = ""
    # This if/else clause tests to see if the year the user entered is valid 
    if team and year:
        if results.testYearInput(year):
            sqlList = sqlQueryGetTeam(team, year)
            tableString = makeTable.makeTableFromQuery(sqlList)
        else:
            tableString = """<p><font color="white">Invalid input or query was not resolved</font></p>"""

    # Once error catching is done, print out the html to standard output 
    outputText = ''
    try:
        f = open(templateFileName)
        templateText = f.read()
        f.close()
        outputText = templateText % (tableString)
    except Exception, e:
        outputText = 'Cannot read template file "%s".' % (templateFileName)