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