first version

This commit is contained in:
shoopea 2025-02-23 18:11:05 +01:00
commit e9c41ae4fd
2 changed files with 67 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.siteop.biz/shoopea/peaq.tasks
go 1.23.2

64
peaq_tasks.go Normal file
View File

@ -0,0 +1,64 @@
package main
import (
"encoding/csv"
"log"
"os"
"path/filepath"
)
type User struct {
EVM string `json:"evm"`
Email string `json:"email"`
}
var (
users map[string]*User
lines int
)
func main() {
users = make(map[string]*User)
// Get the current working directory
cwd, err := os.Getwd()
if err != nil {
log.Fatalf("failed to get current directory: %w", err)
}
// Read files in the directory
files, err := os.ReadDir(cwd)
if err != nil {
log.Fatalf("failed to read directory: %w", err)
}
// Loop through files and open CSVs
for _, file := range files {
if !file.IsDir() && filepath.Ext(file.Name()) == ".csv" {
log.Printf("Opening: %s\n", file.Name())
f, err := os.Open(file.Name())
if err != nil {
log.Fatalf("failed to open file %s: %w", file.Name(), err)
}
defer f.Close()
reader := csv.NewReader(f)
records, err := reader.ReadAll()
if err != nil {
log.Fatalf("failed to read CSV %s: %w", file.Name(), err)
}
log.Printf("Read %d records from %s\n", len(records), file.Name())
lines += len(records)
for _, record := range records[1:] {
u := &User{
EVM: record[0],
Email: record[1],
}
users[u.EVM+`+`+u.Email] = u
}
}
}
log.Printf("Found %d unique records from %d lines", len(users), lines)
return
}