require 'csv'
require 'date'

csv_path_base = "./theses-"
prof = ["mtk","mmz"]

date,row = {}

header = "<html>
<head>
  <link rel=\"stylesheet\" type=\"text/css\" href=\"/softeng.css\">
  <link rel=\"icon\" type=\"image/png\" href=\"/pics/icon.png\">
  <title>Software Engineering Research Group</title>
</head>
<body onload=\"update()\">
<!--#include virtual=\"/header.html\" -->
<h1> Students who did their MASTER theses in SoftEng </h1>
"

footer = "</body></html>"

theses = Hash.new

File.open("./theses_history.html","w") do |f|
	
	f.write "#{header}"

	prof.each do |p|

		csv_path_in = "#{csv_path_base}#{p}-filtered.csv"

		CSV.foreach(csv_path_in) do |row|

			#Date._strptime(row[4], "%d/%m/%Y")
			
			id = row[0].to_s.to_i
			line = "<p><font color=\"#f26d20\"> #{row[1]} #{row[2]}, </font> <b> #{row[3]} </b> <i>(#{row[4]})</i><p>"

			theses[id] = line unless id == 0
			
		end
	end


	theses.sort.reverse.each do |id,line|
		f.write "#{line}"
	end

	f.write "#{footer}"
end
