#!/usr/bin/python
import os, time
from flask import Flask, render_template, Markup

app = Flask(__name__)

## --------------------------

@app.route("/")
def main():

   return generateContent('index')

## --------------------------

@app.route("/ece5641")
def showECE5698():

   return generateContent('ece5641')

## --------------------------

@app.route("/cs5770")
def showCS5770():

   return generateContent('cs5770')

## --------------------------

@app.route("/cschallenges")
def showChallenges():

   return generateContent('challenges')

## --------------------------

@app.route("/ecechallenges")
def showECEChallenges():

   return generateContent('ecechallenges')

## --------------------------

@app.route("/hallfame")
def showHallOfFame():

   return generateContent('hallfame')

## --------------------------

@app.route("/ecestandings")
def showECEStandings():

   file = open('misc/standings2.txt','r')
   data = file.read()

   return render_template("ecestandings.html", standings=Markup(data), modified=getLastModified('misc/standings2.txt'))

## --------------------------

@app.route("/csstandings")
def showStandings():

   file = open('misc/standings.txt','r')
   data = file.read()

   return render_template("standings.html", standings=Markup(data), modified=getLastModified('misc/standings.txt'))

## --------------------------

@app.route("/cspoints")
def showPoints():

   file = open('misc/points.txt','r')
   data = file.read()

   #return render_template("totalpoints.html", totalpoints=Markup(data), modified=getLastModified('misc/points.txt'))
   return render_template("totalpoints.html", totalpoints=Markup(data), modified=getLastModified('misc/points.txt'))


## --------------------------

@app.route("/ecelabenvironment")
def showeceEnvironment():

   return generateContent('ecelab_environment')

## --------------------------

@app.route("/labenvironment")
def showEnvironment():

   return generateContent('lab_environment')


## --------------------------

## Function to generate HTML from template.
def generateContent(content):

   try:
      return render_template(content+'.html', modified=getLastModified('templates/'+content+'.html'))

   except Exception as e:
      return render_template(content+'.html', modified="NA")

## --------------------------

def getLastModified(fileName):

   timeZone = time.strftime("%Z")
   timeStamp = time.ctime(os.path.getmtime(fileName))
   return str(timeStamp)+" "+timeZone

## --------------------------

if __name__ == "__main__":
   app.run() 
