day3 and 4
This commit is contained in:
@@ -16,15 +16,24 @@ func GenInputFile(day int) string {
|
||||
}
|
||||
|
||||
pwd, _ := os.Getwd()
|
||||
path := fmt.Sprintf("%s\\day%s\\input.txt", pwd, d)
|
||||
path := fmt.Sprintf("%s/day%s/input.txt", pwd, d)
|
||||
fi, _ := os.Stat(path)
|
||||
if fi != nil {
|
||||
return path
|
||||
}
|
||||
|
||||
fmt.Println("Creating new input file...")
|
||||
f, _ := os.OpenFile(path, os.O_CREATE, 0700)
|
||||
f.WriteString(readHttp(2022, day))
|
||||
fmt.Printf("Creating new input file %v...", path)
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
defer f.Close()
|
||||
data := readHttp(2023, day)
|
||||
_, err := f.WriteString(data)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
@@ -33,7 +42,6 @@ func readHttp(year, day int) string {
|
||||
|
||||
url := fmt.Sprintf("https://adventofcode.com/%d/day/%d/input", year, day)
|
||||
session := os.Getenv("sessionAoC")
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -50,7 +58,6 @@ func readHttp(year, day int) string {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return string(body)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user