Created
November 26, 2017 19:55
-
-
Save blachniet/d3a2ffe075a3b9b6d78b1a5cd678d47c to your computer and use it in GitHub Desktop.
Create an HTML report from a Trello board export. Each card contains a QR code linking to the card.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"flag" | |
"html/template" | |
"os" | |
) | |
func main() { | |
var listFilterFlag string | |
flag.StringVar(&listFilterFlag, "list", "", "Only emit cards in a given list") | |
flag.Parse() | |
file, err := os.Open(flag.Arg(0)) | |
if err != nil { | |
panic(err) | |
} | |
defer file.Close() | |
var board teBoard | |
if err := json.NewDecoder(file).Decode(&board); err != nil { | |
panic(err) | |
} | |
// Resolve the list id, if filtering on it | |
idListFilter := "" | |
if listFilterFlag != "" { | |
for _, list := range board.Lists { | |
if listFilterFlag == list.ID || listFilterFlag == list.Name { | |
idListFilter = list.ID | |
break | |
} | |
} | |
} | |
vm := viewModel{[]teCard{}} | |
for _, card := range board.Cards { | |
if card.IDAttachmentCover != "" { | |
for _, atch := range card.Attachments { | |
if card.IDAttachmentCover == atch.ID { | |
card.Cover = &atch | |
break | |
} | |
} | |
} | |
if idListFilter == "" || idListFilter == card.IDList { | |
vm.Cards = append(vm.Cards, card) | |
} | |
} | |
t.Execute(os.Stdout, vm) | |
} | |
type teBoard struct { | |
ID string `json:"id"` | |
Cards []teCard `json:"cards"` | |
Lists []teList `json:"lists"` | |
} | |
type teList struct { | |
ID string `json:"id"` | |
Name string `json:"name"` | |
} | |
type teCard struct { | |
IDShort int `json:"idShort"` | |
Name string `json:"name"` | |
ShortURL string `json:"shortUrl"` | |
IDList string `json:"idList"` | |
IDAttachmentCover string `json:"idAttachmentCover"` | |
Attachments []teAttachment `json:"attachments"` | |
Cover *teAttachment | |
} | |
type teAttachment struct { | |
ID string `json:"id"` | |
Name string `json:"name"` | |
URL string `json:"url"` | |
EdgeColor string `json:"edgeColor"` | |
} | |
type viewModel struct { | |
Cards []teCard | |
} | |
var t = template.Must(template.New("t1").Parse(` | |
<!doctype html> | |
<html lang="en"><body><table cellpadding="10"> | |
{{range .Cards}} | |
<tr> | |
<th valign="middle" scope="row">{{.IDShort}}</th> | |
<td valign="middle"> | |
{{if .Cover}} | |
<a href="{{.ShortURL}}"> | |
<img src="{{.Cover.URL}}" width="75px"> | |
</a> | |
{{end}} | |
</td> | |
<td valign="middle"><a href="{{.ShortURL}}">{{.Name}}</a></td> | |
<td valign="middle" style="text-align:center"> | |
<a href="{{.ShortURL}}"> | |
<img src="https://api.qrserver.com/v1/create-qr-code/?size=100x100&data={{.ShortURL}}"> | |
</a> | |
<div> | |
{{.IDShort}} | |
</div> | |
</td> | |
</tr> | |
{{end}} | |
</table></body></html>`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment