This commit is contained in:
David Alasow 2018-01-20 10:57:38 +01:00
parent 2fabb65996
commit 292f6cc4dc

26
main.go
View File

@ -72,8 +72,8 @@ func parseCsv (file string, c chan MatchedAnime) {
dat, err := ioutil.ReadFile(file) dat, err := ioutil.ReadFile(file)
check(err) check(err)
r := csv.NewReader(strings.NewReader(string(dat))) r := csv.NewReader(strings.NewReader(string(dat)))
_, er := r.Read() _, err = r.Read()
check(er) check(err)
for { for {
record, err := r.Read() record, err := r.Read()
if err == io.EOF { if err == io.EOF {
@ -116,8 +116,9 @@ func parseCsv (file string, c chan MatchedAnime) {
continue continue
} }
go checkResults(a, c) go checkResults(a, c)
time.Sleep(10 * time.Millisecond) time.Sleep(5 * time.Millisecond)
} }
fmt.Println("Finished parsing csv")
} }
func lessType (Type string) (string) { func lessType (Type string) (string) {
@ -138,14 +139,17 @@ func checkResults(anime Anime, c chan MatchedAnime) {
var search = bytes.NewBuffer([]byte(`{"title":"` + anime.Title + `", "show_r18": true}`)) var search = bytes.NewBuffer([]byte(`{"title":"` + anime.Title + `", "show_r18": true}`))
resp, err := http.Post("https://api.meikan.moe/v1/anime?incl=start_date,end_date", "application/json", search) resp, err := http.Post("https://api.meikan.moe/v1/anime?incl=start_date,end_date", "application/json", search)
check(err) if err != nil {
return
}
defer resp.Body.Close() defer resp.Body.Close()
var result Result var result Result
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
check(err) check(err)
er := json.NewDecoder(bytes.NewReader(body)).Decode(&result) err = json.NewDecoder(bytes.NewReader(body)).Decode(&result)
if er != nil { if err != nil {
fmt.Println(string(body)) fmt.Println(string(body))
return
} }
switch anime.Type { switch anime.Type {
case "TV Series": case "TV Series":
@ -275,16 +279,22 @@ func main() {
*/ */
select { select {
case m := <- c: case m := <- c:
fmt.Println(m)
animes = append(animes, m) animes = append(animes, m)
test = 0 test = 0
default: default:
time.Sleep(1000 * time.Millisecond) time.Sleep(1000 * time.Millisecond)
if (test > 2) { if (test > 5) {
return break
} }
test = test + 1 test = test + 1
} }
//break
if (test > 5) {
break
}
} }
fmt.Println(animes)
resJson, err := json.MarshalIndent(animes, "", "\t") resJson, err := json.MarshalIndent(animes, "", "\t")
check(err) check(err)
jsonfile := []byte(resJson) jsonfile := []byte(resJson)