first version
This commit is contained in:
commit
e9c41ae4fd
64
peaq_tasks.go
Normal file
64
peaq_tasks.go
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user