TSV and excel instructions
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
Martyn 2020-07-16 18:01:04 +02:00
parent 1477f9bc55
commit 1aa4572f0e
4 changed files with 33 additions and 6 deletions

View File

@ -680,10 +680,17 @@ func CSVHandler(response http.ResponseWriter, request *http.Request) {
topNSongs := calculateTopNSongs(channelData.VideoCache, 10)
topNSingers := calculateTopNSingers(channelData.VideoCache, 10)
var td = TemplateData{channelData.Name, channelData.Command, channelData.ExtraStrings, channelData.JoinTime, channelData.JoinTime.Format(irc.UTCFormat), false, channelData.HasLeft, AugmentSingsVideoStructSliceForCSV(channelData.VideoCache), topNSongs, topNSingers}
if request.URL.Path[0:4] == "/csv" {
response.Header().Add("Content-Disposition", "attachment; filename=\"duets.csv\"")
response.Header().Add("Content-type", "text/csv")
tmpl := template.Must(template.ParseFiles("web/data.csv"))
tmpl.Execute(response, td)
} else {
response.Header().Add("Content-Disposition", "attachment; filename=\"duets.tsv\"")
response.Header().Add("Content-type", "text/tab-separated-values")
tmpl := template.Must(template.ParseFiles("web/data.tsv"))
tmpl.Execute(response, td)
}
}
func HandleHTTP(passedIrcBot *irc.KardBot) {
@ -698,6 +705,7 @@ func HandleHTTP(passedIrcBot *irc.KardBot) {
r.HandleFunc("/cover.css", CSSHandler)
r.HandleFunc("/admin/{channel}/{key}", AdminHandler)
r.HandleFunc("/csv/{channel}/{key}", CSVHandler)
r.HandleFunc("/tsv/{channel}/{key}", CSVHandler)
//r.HandleFunc("/twitchadmin", TwitchAdminHandler)
//r.HandleFunc("/twitchtobackend", TwitchBackendHandler)
r.Path("/twitchtobackend").Queries("access_token", "{access_token}", "scope", "{scope}", "token_type", "{token_type}").HandlerFunc(TwitchBackendHandler)

View File

@ -69,6 +69,12 @@
font-weight: bold;
font-style: italic;
}
#csvpanel td {
padding: 5px;
}
#csvpanel th {
padding: 5px;
}
</style>
</head>
@ -148,7 +154,16 @@
</table>
</div>
<div style="width: 100%; overflow-y: scroll; display: none;" id="csvpanel" class="controlpanel">
<h2>Click <a href="/csv/{{.Channel}}/{{.ChannelKey}}">here</a> to download the data as a CSV</h2>
<h3>Download your data as :</h3>
<center>
<table border="2">
<tr><th>CSV</th><th>TSV</th></tr>
<tr><td><a href="/csv/{{.Channel}}/{{.ChannelKey}}">here</a></td><td><a href="/tsv/{{.Channel}}/{{.ChannelKey}}">here</a></td></tr>
</table>
</center>
<h3>Excel is not very good at handling CSV format it seems...</h3>
<p>It is important to "Import Data" not "Open" the csv in many cases (8 year old discussion of this behaviour here) - from that post the instructions are : </p>
<blockquote>In Excel, DATA tab, in the Get External Data subsection, click "From Text" and import your CSV in the Wizard.</blockquote>
</div>
<div style="width: 100%; overflow-y: scroll; display: none;" id="botpanel" class="controlpanel">
<h2>The bot isn't really ready yet... it just has the old Karaokards facility at the moment. I woudn't bother inviting it yet.</h2>

View File

@ -1,4 +1,4 @@
Published,Who,What,Last sang this song,Last dueted with performer
{{ range .SongData -}}
{{- .NiceDate }},{{ .SongTitle }},{{ .OtherSinger }},{{ .NiceLastSungSong }},{{ .NiceLastSungSinger }}
{{- .NiceDate }},"{{ .SongTitle }}",{{ .OtherSinger }},{{ .NiceLastSungSong }},{{ .NiceLastSungSinger }}
{{ end }}

Can't render this file because it has a wrong number of fields in line 2.

4
web/data.tsv Executable file
View File

@ -0,0 +1,4 @@
Published Who What Last sang this song Last dueted with performer
{{ range .SongData -}}
{{- .NiceDate }} "{{ .SongTitle }}" {{ .OtherSinger }} {{ .NiceLastSungSong }} {{ .NiceLastSungSinger }}
{{ end }}
Can't render this file because it has a wrong number of fields in line 2.