Skip to content
Snippets Groups Projects
Commit 98ddc4c3 authored by Nicolas Pernoud's avatar Nicolas Pernoud
Browse files

feat: working proof of concept

parent 445f8084
Branches master
No related tags found
No related merge requests found
.env 0 → 100644
SPLIT_LINE_PATTERN="Délibération"
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {},
"args": []
}
]
}
1.Délibération XXXXX
A.Pour 2/3 ( 67%)
B.Contre 1/3 ( 33%)
C.Abstention 0/3 ( 0%)
D.NPPV 0/3 ( 0%)
Pas de réponse 0/3 ( 0%)
A B C D
---------------------------------
ÉLU 1 | | X | | |
ÉLU 2 | X | | | |
ÉLU 3 | X | | | |
2.Délibération XXXXX
A.Pour 1/3 ( 33%)
B.Contre 1/3 ( 33%)
C.Abstention 1/3 ( 33%)
D.NPPV 0/3 ( 0%)
Pas de réponse 0/3 ( 0%)
A B C D
---------------------------------
ÉLU 1 | | X | | |
ÉLU 2 | | | X | |
ÉLU 3 | X | | | |
3.Délibération XXXX
A.Pour 1/3 ( 33%)
B.Contre 1/3 ( 33%)
C.Abstention 0/3 ( 0%)
D.NPPV 0/3 ( 0%)
Pas de réponse 1/3 ( 33%)
A B C D
---------------------------------
ÉLU 1 | | X | | |
ÉLU 2 | X | | | |
ÉLU 3 | | | | |
#!/bin/bash
GOOS=windows GOARCH=386 go build -o splitter.exe main.go
main.go 0 → 100644
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"github.com/joho/godotenv"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
// Load .env file
err := godotenv.Load(".env")
if err != nil {
log.Fatalf("Error loading .env file")
}
// Load the PollResult file and scan it
f, err := os.Open("PollResults.txt")
check(err)
scanner := bufio.NewScanner(f)
var fileBuffer string
fileName := ""
writeFile := func() {
sf := []byte(fileBuffer)
err := ioutil.WriteFile(fileName+".txt", sf, 0644)
check(err)
}
// Call Scan in a for-loop.
for scanner.Scan() {
line := scanner.Text()
fmt.Println(line)
// If line contains "SPLIT_LINE_PATTERN", save the previous string into a file (excepted the first time), and start a new buffer
if strings.Contains(line, os.Getenv("SPLIT_LINE_PATTERN")) {
if fileName != "" {
writeFile()
}
fileName = line
fileBuffer = line + "\n"
} else {
fileBuffer += line + "\n"
}
}
// Write the last file
writeFile()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment