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)
check(err)
r := csv.NewReader(strings.NewReader(string(dat)))
_, er := r.Read()
check(er)
_, err = r.Read()
check(err)
for {
record, err := r.Read()
if err == io.EOF {
@ -116,8 +116,9 @@ func parseCsv (file string, c chan MatchedAnime) {
continue
}
go checkResults(a, c)
time.Sleep(10 * time.Millisecond)
time.Sleep(5 * time.Millisecond)
}
fmt.Println("Finished parsing csv")
}
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}`))
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()
var result Result
body, err := ioutil.ReadAll(resp.Body)
check(err)
er := json.NewDecoder(bytes.NewReader(body)).Decode(&result)
if er != nil {
err = json.NewDecoder(bytes.NewReader(body)).Decode(&result)
if err != nil {
fmt.Println(string(body))
return
}
switch anime.Type {
case "TV Series":
@ -275,16 +279,22 @@ func main() {
*/
select {
case m := <- c:
fmt.Println(m)
animes = append(animes, m)
test = 0
default:
time.Sleep(1000 * time.Millisecond)
if (test > 2) {
return
if (test > 5) {
break
}
test = test + 1
}
//break
if (test > 5) {
break
}
}
fmt.Println(animes)
resJson, err := json.MarshalIndent(animes, "", "\t")
check(err)
jsonfile := []byte(resJson)