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 benchmarks
targets/* targets/*
results/*

View file

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

View file

@ -1,4 +1,4 @@
{{range $id, $participant := .Participants -}} {{range $id, $participant := .Participants -}}
{{- $username := $participant.FiscalCode -}} {{- $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}} {{end}}