ran gofmt and cleaned up code
This commit is contained in:
parent
292f6cc4dc
commit
c7176ea47e
71
main.go
71
main.go
@ -5,7 +5,7 @@ import (
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
//"gopkg.in/cheggaaa/pb.v1"
|
||||
"github.com/agext/levenshtein"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@ -13,7 +13,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"github.com/agext/levenshtein"
|
||||
)
|
||||
|
||||
//Anime is AniDB structure
|
||||
@ -25,11 +24,13 @@ type Anime struct {
|
||||
StartDate time.Time
|
||||
EndDate time.Time
|
||||
}
|
||||
|
||||
//Result contains the results from the meikan search
|
||||
type Result struct {
|
||||
Total int `json:"total"`
|
||||
Anime []AnimeRes `json:"data"`
|
||||
}
|
||||
|
||||
//AnimeRes is how the search results from meikan are built up in the JSON
|
||||
type AnimeRes struct {
|
||||
EndDate string `json:"end_date"`
|
||||
@ -48,6 +49,7 @@ type CompareAni struct {
|
||||
AnidbID int
|
||||
MeikanID int
|
||||
}
|
||||
|
||||
//Animes is a collection of animes
|
||||
type Animes []MatchedAnime
|
||||
|
||||
@ -112,17 +114,17 @@ func parseCsv (file string, c chan MatchedAnime) {
|
||||
Episodes: eps,
|
||||
Title: strings.Replace(record[3], "Anime: ", "", 1),
|
||||
}
|
||||
if a.Title == "ERROR" {
|
||||
if a.Title == "ERROR" || a.Title == "?" {
|
||||
continue
|
||||
}
|
||||
go checkResults(a, c)
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
fmt.Println("Finished parsing csv")
|
||||
}
|
||||
|
||||
func lessType (Type string) (string) {
|
||||
switch (Type) {
|
||||
func lessType(Type string) string {
|
||||
switch Type {
|
||||
case "TV", "ONA":
|
||||
return "Shows"
|
||||
case "OVA", "Specials":
|
||||
@ -133,7 +135,6 @@ func lessType (Type string) (string) {
|
||||
|
||||
func checkResults(anime Anime, c chan MatchedAnime) {
|
||||
var highest int
|
||||
//var re = regexp.MustCompile(`\s\(\d*\)`)
|
||||
var err error
|
||||
anime.Title = strings.Replace(strings.Replace(anime.Title, `\`, `\\`, -1), `"`, `\"`, -1)
|
||||
|
||||
@ -149,6 +150,7 @@ func checkResults(anime Anime, c chan MatchedAnime) {
|
||||
err = json.NewDecoder(bytes.NewReader(body)).Decode(&result)
|
||||
if err != nil {
|
||||
fmt.Println(string(body))
|
||||
fmt.Println(anime.Title)
|
||||
return
|
||||
}
|
||||
switch anime.Type {
|
||||
@ -190,7 +192,6 @@ func checkResults(anime Anime, c chan MatchedAnime) {
|
||||
}
|
||||
}
|
||||
score := levenshtein.Match(meikan.Title, anime.Title, nil)
|
||||
//fmt.Print(score)
|
||||
if score > 0.95 {
|
||||
total += 50
|
||||
}
|
||||
@ -216,7 +217,6 @@ func checkResults(anime Anime, c chan MatchedAnime) {
|
||||
if diff <= 2190*time.Hour {
|
||||
total += 50
|
||||
}
|
||||
//total += 50
|
||||
}
|
||||
if total > highest {
|
||||
highest = total
|
||||
@ -236,62 +236,17 @@ func checkResults(anime Anime, c chan MatchedAnime) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.DefaultTransport = &http.Transport{MaxIdleConnsPerHost: 50, MaxIdleConns: 50}
|
||||
c := make(chan MatchedAnime)
|
||||
//var resultCompare resAnimes
|
||||
var animes Animes
|
||||
parseCsv("/home/trac/coding/compareID/1.-Main-data.csv", c)
|
||||
//count := len(animes)
|
||||
//bar := pb.StartNew(count - 1)
|
||||
test := 0
|
||||
MainLoop:
|
||||
for {
|
||||
/*anime := animes[i]
|
||||
highest, hI := <-c, <-c
|
||||
//highest, hI := checkResults(result, anime, 0)
|
||||
if highest < 100 {
|
||||
check(err)
|
||||
if len(result.Anime) > 0 {
|
||||
fmt.Printf("Found no match for %s (Best result: %s)\n", anime.Title, result.Anime[hI].Title)
|
||||
//fmt.Println(highest)
|
||||
//fmt.Printf("Title: %s, Episodes: %d, Type: %s, ID: %d, StartDate: %s, EndDate: %s\n", anime.Title, anime.Episodes, anime.Type, anime.ID, anime.StartDate, anime.EndDate)
|
||||
//fmt.Printf("Title: %s, Episodes: %d, Type: %s, ID: %d, StartDate: %s, EndDate: %s\n", result.Anime[hI].Title, result.Anime[hI].Episodes, result.Anime[hI].Type, result.Anime[hI].ID, result.Anime[hI].StartDate, result.Anime[hI].EndDate)
|
||||
} else {
|
||||
fmt.Printf("Found no match for %s\n", anime.Title)
|
||||
fmt.Println("No search results returned")
|
||||
}
|
||||
notMatched++
|
||||
|
||||
} else {
|
||||
check(err)
|
||||
/*fmt.Println(highest, hI)
|
||||
fmt.Printf("Matched %s -> %s\n", anime.Title, result.Anime[hI].Title)
|
||||
//fmt.Printf("Title: %s, Episodes: %d, Type: %s, ID: %d, StartDate: %s, EndDate: %s\n", result.Anime[hI].Title, result.Anime[hI].Episodes, result.Anime[hI].Type, result.Anime[hI].ID, result.Anime[hI].StartDate, result.Anime[hI].EndDate)
|
||||
a := CompareAni{
|
||||
AnidbTitle: anime.Title,
|
||||
MeikanTitle: result.Anime[hI].Title,
|
||||
AnidbID: anime.ID,
|
||||
MeikanID: result.Anime[hI].ID,
|
||||
}
|
||||
matched++
|
||||
resultCompare = append(resultCompare, a)
|
||||
}
|
||||
bar.Increment()
|
||||
//fmt.Printf("ID: %d, Type: %s, Episodes: %d, Title: %s\n", a.Id, a.Type, a.Episodes, a.Title)
|
||||
*/
|
||||
select {
|
||||
case m := <-c:
|
||||
fmt.Println(m)
|
||||
animes = append(animes, m)
|
||||
test = 0
|
||||
default:
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
if (test > 5) {
|
||||
break
|
||||
}
|
||||
test = test + 1
|
||||
}
|
||||
//break
|
||||
if (test > 5) {
|
||||
break
|
||||
case <-time.After(2 * time.Second):
|
||||
break MainLoop
|
||||
}
|
||||
}
|
||||
fmt.Println(animes)
|
||||
|
Loading…
Reference in New Issue
Block a user