from django.shortcuts import render
from django.http import HttpResponse
from .academics import *

def processAcads(filename):
    htmlstr = '<table border=1>\n'
    acadfile = open(filename)

    for line in acadfile:
        if line == '\n':    # new semester
            #print(gethtml())
            htmlstr = htmlstr + gethtml()
            htmlstr = htmlstr + "<tr><td colspan=3>This Sem CGPA:" + \
                      str(cgpa()) + "</td></tr>\n"
        else:
            cc, cr, ea = line.split()
            add(cc, int(cr), int(ea))

    acadfile.close()
    htmlstr = htmlstr + '</table><br>\n'
    return htmlstr

def index(request):
    htmlstr = processAcads("/home/hp/service/external/books/aicte-python/code/unit5/mydjango/acads/academics.txt")
    
    return HttpResponse(htmlstr)

