initial commit
This commit is contained in:
commit
7c7ea7f914
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
schedule.xml
|
133
main.go
Normal file
133
main.go
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
// TODO: docstring
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
type frabSchedule struct {
|
||||||
|
Conf conference
|
||||||
|
Days []day
|
||||||
|
}
|
||||||
|
|
||||||
|
type conference struct {
|
||||||
|
Title string
|
||||||
|
Start string // date (yyyy-mm-dd)
|
||||||
|
End string // date (yyyy-mm-dd)
|
||||||
|
Days int
|
||||||
|
}
|
||||||
|
|
||||||
|
type day struct {
|
||||||
|
Index int
|
||||||
|
Date string // date (yyyy-mm-dd)
|
||||||
|
Start string // timedate (RFC3339)
|
||||||
|
End string // timedate (RFC3339)
|
||||||
|
Rooms []room
|
||||||
|
}
|
||||||
|
|
||||||
|
type room struct {
|
||||||
|
Name string
|
||||||
|
Events []event
|
||||||
|
}
|
||||||
|
|
||||||
|
type event struct {
|
||||||
|
ID int
|
||||||
|
GUID string // here: $dayIndex-$eventID
|
||||||
|
|
||||||
|
Room string
|
||||||
|
Title string
|
||||||
|
Date string // timedate (RFC3339)
|
||||||
|
Start string // time (hh:mm)
|
||||||
|
Duration string // time (hh:mm)
|
||||||
|
|
||||||
|
Persons []person
|
||||||
|
}
|
||||||
|
|
||||||
|
type person struct {
|
||||||
|
ID int
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Conference Schedule CSV to Frab (Infobeamer) Converter")
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Data Input
|
||||||
|
*/
|
||||||
|
// read CSV contents
|
||||||
|
csvFile, err := os.Open("schedule.csv")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error opening CSV file:\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
records, err := csv.NewReader(csvFile).ReadAll()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error reading CSV file:\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// omit title row
|
||||||
|
csvRecords := records[1:]
|
||||||
|
|
||||||
|
fmt.Println(csvRecords) // TODO
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Data Conversion
|
||||||
|
*/
|
||||||
|
// new conference
|
||||||
|
conf := conference{"Test Conference", "2018-11-20", "2018-11-24", 4}
|
||||||
|
|
||||||
|
// gather all rooms
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// TODO: make room and day structs
|
||||||
|
|
||||||
|
// sort by room and day into structure
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// assign the conference and days to the schedule
|
||||||
|
day1Room1Event1 := event{123, "1-123", "Room", "Title", "2018-11-20", "10:00", "1:00", nil}
|
||||||
|
day1Room1Event2 := event{123, "1-123", "Room", "Title", "2018-11-20", "10:00", "0:30", nil}
|
||||||
|
day1Room1Events := []event{day1Room1Event1, day1Room1Event2}
|
||||||
|
|
||||||
|
day1Room1 := room{"Room 1", day1Room1Events}
|
||||||
|
day1Rooms := []room{day1Room1}
|
||||||
|
|
||||||
|
day1 := day{1, "2018-11-20", "2018-11-20T08:00", "2018-11-20T20:00", day1Rooms}
|
||||||
|
|
||||||
|
days := []day{day1}
|
||||||
|
sched := frabSchedule{conf, days}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Data Export
|
||||||
|
*/
|
||||||
|
fmt.Println(sched)
|
||||||
|
|
||||||
|
// open output file
|
||||||
|
xmlOutput, err := os.Create("schedule.xml")
|
||||||
|
defer xmlOutput.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error opening XML file for output:\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t := template.New("Frab XML Template")
|
||||||
|
t, err = t.ParseFiles("tmpl/schedule.xml")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error parsing XML template:\n", err)
|
||||||
|
}
|
||||||
|
err = t.ExecuteTemplate(xmlOutput, "schedule.xml", sched)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error executing XML template:\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print Summary
|
||||||
|
*/
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
fmt.Println("done")
|
||||||
|
}
|
3
schedule.csv
Normal file
3
schedule.csv
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Titel, Raum, Von, Bis, Speaker
|
||||||
|
Very good talk, Holzhafen, 19.11.2018 12:00, 19.11.2018 13:00:00,
|
||||||
|
Keynote, Heuckenlock Ebbe, 19.11.2018 12:00, 19.11.2018 13:00:00,
|
|
39
tmpl/schedule.xml
Normal file
39
tmpl/schedule.xml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<schedule>
|
||||||
|
{{with .Conf}}<conference>
|
||||||
|
<title>{{.Title}}</title>
|
||||||
|
<start>{{.Start}}</start>
|
||||||
|
<end>{{.End}}</end>
|
||||||
|
<days>{{.Days}}</days>
|
||||||
|
<timeslot_duration>0:05</timeslot_duration>
|
||||||
|
<acronym></acronym>
|
||||||
|
</conference>{{end}}
|
||||||
|
|
||||||
|
{{range .Days}}
|
||||||
|
<day index="{{.Index}}" date="{{.Date}}" start="{{.Start}}" end="{{.End}}">
|
||||||
|
{{range .Rooms}}
|
||||||
|
<room name="{{.Name}}">
|
||||||
|
{{range .Events}}
|
||||||
|
<event id="{{.ID}}" guid="{{.GUID}}">
|
||||||
|
<room>{{.Room}}</room>
|
||||||
|
<title>{{.Title}}</title>
|
||||||
|
<date>{{.Date}}</date>
|
||||||
|
<start>{{.Start}}</start>
|
||||||
|
<duration>{{.Duration}}</duration>
|
||||||
|
|
||||||
|
<persons>{{range .Persons}}<person id="{{.ID}}">{{.Name}}</person>{{end}}</persons>
|
||||||
|
<abstract></abstract>
|
||||||
|
<description></description>
|
||||||
|
<slug></slug>
|
||||||
|
<type></type>
|
||||||
|
<language></language>
|
||||||
|
<recording><license></license><optout>false</optout></recording>
|
||||||
|
<subtitle></subtitle>
|
||||||
|
<track></track>
|
||||||
|
<links></links>
|
||||||
|
</event>
|
||||||
|
{{end}}
|
||||||
|
</room>
|
||||||
|
{{end}}
|
||||||
|
</day>
|
||||||
|
{{end}}
|
||||||
|
</schedule>
|
Loading…
Reference in a new issue