# -*- coding: utf-8 -*-

import os
from os import listdir
from os.path import isfile, join

mypath = os.getcwd() + '/aulas'


#mypathAulas = mypath + '/aulas'
#mypathListas = mypath + '/listas'
#mypathTrabs = mypath + '/trabalhos'

onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

onlyfiles.sort()

link = 'https://thiagoalvesifce.github.io/disciplinas/2016-2/fup/aulas/'

#print link

#print onlyfiles

listRows = []

for name in onlyfiles:
	if name[-3:] == 'pdf' and name[:-1] != '~':
		row = '<tr><td align="center"><a href="' + link + name + '" target="_blank">' + name[:-4] + '</a></td></tr>'
		listRows.append(row)

#print listRows

arq = open('fup.html','w')

header = '<HTML><HEAD><TITLE>Fundamentos de Programação</TITLE>\n'
header = header + '<META content="text/html; charset=utf-8" http-equiv=Content-Type>\n'
header = header + '<META content="MSHTML 5.00.2314.1000" name=GENERATOR></HEAD>\n'
header = header + '<body bgcolor="white" text="#000000" link="#0000A0" vlink="#A000A0" alink="#00A000">\n'
header = header + '<h1>Fundamentos de Programação</h1>\n'
header = header + '<h2>Aulas</h2>\n' + '<table border="1">\n'# + '<tr><th>Aula</th></tr>\n'

arq.write(header)

for row in listRows:
	arq.write(row + '\n')

arq.write('</table>\n')


arq.write('<h2>Listas</h2>\n<ul>\n')

mypath = os.getcwd() + '/listas'

onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

onlyfiles.sort()

link = 'https://thiagoalvesifce.github.io/disciplinas/2016-2/fup/listas/'

listRows = []

for name in onlyfiles:
	if name[-3:] == 'pdf' and name[:-1] != '~':
		row = '<li><a href="' + link + name + '" target="_blank">' + name[:-4] + '</a></li>'
		listRows.append(row)


for row in listRows:
	arq.write(row + '\n')

arq.write('</ul>\n')

arq.write('<h2>Trabalhos</h2>\n<ul>\n')

mypath = os.getcwd() + '/trabalhos'

onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

onlyfiles.sort()

link = 'https://thiagoalvesifce.github.io/disciplinas/2016-2/fup/trabalhos/'

listRows = []

for name in onlyfiles:
	if (name[-3:] == 'zip' or name[-3:] == 'pdf') and name[:-1] != '~':
		row = '<li><a href="' + link + name + '" target="_blank">' + name[:-4] + '</a></li>'
		listRows.append(row)


for row in listRows:
	arq.write(row + '\n')

arq.write('</ul>\n')

arq.write('<h2>Entrega de Trabalhos</h2>\n')
#arq.write('<ul>\n<li><a href="https://www.dropbox.com/request/F8pYOWwO2TKfAF7yR9P8" target="_blank">Entrega do Trabalho 01</a></li>\n</ul>\n')

auxiliar = '<h2>Material Auxiliar</h2>\n<ul>\n<li><a href="http://www.greenteapress.com/thinkpython/" target="_blank">Bibliografia Principal</a></li>\n<li><a href="https://www.urionlinejudge.com.br" target="_blank">URI Online Judge</a></li>\n<li><a href="http://www.pythontutor.com/" target="_blank">Python Tutor</a></li>\n</ul>\n<hr>'

arq.write(auxiliar)

arq.write('<h2>Notas</h2>\n')

arq.write('<ul>\n<li><a href="https://docs.google.com/spreadsheets/d/1AVSTz17ecZFeVxCwUL_ANCvJFkGUGnlqbxxlq3lg4Nk/edit?usp=sharing" target="_blank">Planilha de Notas</a></li></ul>')

#trabsPassados = '<ul>\n<li><a href="logicompstudents.html">Trabalhos Passados</a></li>\n</ul>\n<hr>'

#arq.write(trabsPassados)

arq.write('</body>\n</html>')

arq.close()
