Ejemplo n.º 1
0
func main() {

	// // Ask user for verification code
	// fmt.Print("Enter code: ")
	// var code string
	// // NOTE: This does not work with gopherjs
	// fmt.Scanln(&code)
	//
	// framework.SetSchool("amstelveencollege")
	//
	// token := framework.GetToken(code)
	// framework.GetError()
	//
	// fmt.Println(token)

	framework.SetSchool("amstelveencollege")
	framework.SetToken("rdnn2ng1c8t2ok3jd4ss3977v9")
	framework.SetTimeDiff(1)

	framework.RequestUserData()
	framework.GetError()
	fmt.Println(framework.GetName())
	fmt.Println(framework.GetId())

	framework.RequestScheduleData(1448918611)
	framework.GetError()
	classCount := framework.GetClassCount()
	fmt.Println(classCount)
	for i := 0; i < classCount; i++ {
		fmt.Println(framework.GetClassName(i) + " " + framework.GetClassStartTime(i) + " - " + framework.GetClassEndTime(i) + " " + framework.GetClassTeacher(i) + " " + framework.GetClassRoom(i) + " " + strconv.Itoa(framework.GetClassStatus(i)))

	}
}
Ejemplo n.º 2
0
// TODO: Add error checking
func showSchedule() {

	fmt.Println(token)

	framework.RequestScheduleData(time.Now().Unix(), user)
	// framework.RequestScheduleData(1454948725, strconv.Itoa(108890))

	count := framework.GetClassCount()
	var classes = Classes{}

	for i := 0; i < count; i++ {

		class := classInfo{}

		class.name = framework.GetClassName(i)
		class.start = framework.GetClassStartTime(i)
		class.end = framework.GetClassEndTime(i)
		class.teacher = framework.GetClassTeacher(i)
		class.status = framework.GetClassStatus(i)
		class.unixStart = framework.GetClassStartUnix(i)
		class.timeSlot = framework.GetClassTimeSlot(i)

		classes = append(classes, class)
	}

	sort.Sort(classes)

	endOfDay := false
	for i := 0; i < count; i++ {

		free := 0

		if i == 0 || endOfDay {

			free = classes[i].timeSlot - 1

			for j := 0; j < free; j++ {

				empty := classInfo{}
				empty.status = framework.STATUS_FREE
				empty.unixStart = classes[i].unixStart - int64(j+1)
				empty.timeSlot = classes[i].timeSlot - j - 1

				classes = append(classes, empty)
			}
		}

		if i+1 < count {

			free = classes[i+1].timeSlot - classes[i].timeSlot - 1
			endOfDay = (classes[i+1].unixStart - classes[i].unixStart) > 10*3600
		} else {

			free = 0
			endOfDay = false
		}

		for j := 0; j < free; j++ {

			empty := classInfo{}
			empty.status = framework.STATUS_FREE
			empty.unixStart = classes[i].unixStart + int64(j+1)
			empty.timeSlot = classes[i].timeSlot + j + 1

			classes = append(classes, empty)
		}
	}

	for i := 0; i < 5; i++ {

		day := classInfo{}

		day.name = days[i] + " " + strconv.Itoa(framework.GetDayNumber(i)) + " " + months[framework.GetDayMonth(i)-1]
		day.status = framework.STATUS_DATE
		day.unixStart = int64(framework.FirstDayOfISOWeek() + i*24*3600)

		classes = append(classes, day)
	}

	sort.Sort(classes)

	// Actually output to the page
	d := dom.GetWindow().Document()
	schedule := d.GetElementByID("schedule").(*dom.HTMLDivElement)
	schedule.SetClass("mdl-grid")

	day := d.CreateElement("div").(*dom.HTMLDivElement)

	for _, v := range classes {

		if v.status == framework.STATUS_DATE {

			schedule.AppendChild(day)
			day = d.CreateElement("div").(*dom.HTMLDivElement)
		}

		container := d.CreateElement("div").(*dom.HTMLDivElement)

		if v.status == framework.STATUS_DATE {

			date := d.CreateElement("h4").(*dom.HTMLHeadingElement)
			date.SetTextContent(v.name)
			date.SetClass("date")

			container.AppendChild(date)
		} else {

			class := d.CreateElement("div").(*dom.HTMLDivElement)
			class.SetClass("class-card mdl-card mdl-shadow--4dp " + getColor(v.status))

			information := d.CreateElement("div").(*dom.HTMLDivElement)
			information.SetClass("mdl-card__supporting-text")

			name := d.CreateElement("div").(*dom.HTMLDivElement)
			name.SetClass("class-name")
			name.SetTextContent(v.name)
			information.AppendChild(name)

			start := d.CreateElement("div").(*dom.HTMLDivElement)
			start.SetClass("class-start")
			start.SetTextContent(v.start)
			information.AppendChild(start)

			end := d.CreateElement("div").(*dom.HTMLDivElement)
			end.SetClass("class-end")
			end.SetTextContent(v.end)
			information.AppendChild(end)

			teacher := d.CreateElement("div").(*dom.HTMLDivElement)
			teacher.SetClass("class-teacher")
			teacher.SetTextContent(v.teacher)
			information.AppendChild(teacher)

			class.AppendChild(information)
			container.AppendChild(class)
		}
		day.AppendChild(container)
	}
	schedule.AppendChild(day)
}