Fix targets generator

This commit is contained in:
Andrea Fazzi 2020-01-31 08:18:38 +01:00
parent 6087e6f4b6
commit 29af400745
3 changed files with 16 additions and 9 deletions

View file

@ -1,2 +1,3 @@
benchmarks
targets/*
results/*

View file

@ -7,9 +7,11 @@ import (
"log"
"os"
"path"
"path/filepath"
"strings"
"text/template"
"git.andreafazzi.eu/andrea/oef/client"
"git.andreafazzi.eu/andrea/oef/orm"
"github.com/gocarina/gocsv"
)
@ -44,22 +46,26 @@ func genResponseTargets(targetName string) error {
log.Println("Obtaining tokens for each participants...")
data.Tokens = make(map[string]string, 0)
// for _, participant := range data.Participants {
// token, err := client.GetToken(url, participant.FiscalCode, participant.Password)
// if err != nil {
// return err
// }
// data.Tokens[participant.FiscalCode] = token
// }
for _, participant := range data.Participants {
token, err := client.GetToken(url, participant.FiscalCode, participant.Password)
if err != nil {
return err
}
data.Tokens[participant.FiscalCode] = token
}
tmplPath := path.Join(templateDir, targetName+".tpl")
log.Printf("Parse %s template", tmplPath)
tmpl, err := template.New(tmplPath).Funcs(template.FuncMap{"incr": incr}).ParseFiles(tmplPath)
tmpl, err := template.New(filepath.Base(tmplPath)).Funcs(template.FuncMap{"incr": incr}).ParseFiles(tmplPath)
if err != nil {
return err
}
err = os.Mkdir("targets", 0777)
if errors.Is(err, &os.PathError{}) {
return err
}
output, err := os.Create("./targets/response_targets.txt")
if err != nil {
return err

View file

@ -1,4 +1,4 @@
{{range $id, $participant := .Participants -}}
{{- $username := $participant.FiscalCode -}}
GET https://test.olimpiadi-economiaefinanza.it/responses/{{$id|incr}}?format=html&tpl_content=responses_show&tpl_layout=base&login_session={{index $.Tokens $username}}
GET https://test.olimpiadi-economiaefinanza.it/responses/{{$id|incr}}/update?format=html&tpl_content=responses_add_update&tpl_layout=base&update=true&login_session={{index $.Tokens $username}}
{{end}}