Improved company import
This commit is contained in:
@ -34,7 +34,6 @@ func main() {
|
||||
}
|
||||
|
||||
color.Green("Finished importing %d companies", len(companies))
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
|
||||
func importCompanies(anime *arn.Anime, malID string) {
|
||||
@ -47,36 +46,70 @@ func importCompanies(anime *arn.Anime, malID string) {
|
||||
|
||||
jikanAnime := obj.(*jikan.Anime)
|
||||
|
||||
for _, studioInfo := range jikanAnime.Studio {
|
||||
studioName := studioInfo[1]
|
||||
htmlPos := strings.Index(studioName, "<")
|
||||
for _, info := range jikanAnime.Studio {
|
||||
importByName(anime, "studio", info)
|
||||
}
|
||||
|
||||
if htmlPos != -1 {
|
||||
studioName = studioName[:htmlPos]
|
||||
}
|
||||
for _, info := range jikanAnime.Producer {
|
||||
importByName(anime, "producer", info)
|
||||
}
|
||||
|
||||
company, exists := companies[studioName]
|
||||
|
||||
if !exists {
|
||||
now = now.Add(-time.Second)
|
||||
|
||||
company = &arn.Company{
|
||||
ID: arn.GenerateID("Company"),
|
||||
Name: arn.CompanyName{
|
||||
English: studioName,
|
||||
},
|
||||
Created: now.UTC().Format(time.RFC3339),
|
||||
CreatedBy: "",
|
||||
Mappings: []*arn.Mapping{},
|
||||
Links: []*arn.Link{},
|
||||
Tags: []string{},
|
||||
Likes: []string{},
|
||||
}
|
||||
|
||||
companies[studioName] = company
|
||||
}
|
||||
|
||||
anime.StudioIDs = append(anime.StudioIDs, company.ID)
|
||||
anime.Save()
|
||||
for _, info := range jikanAnime.Licensor {
|
||||
importByName(anime, "licensor", info)
|
||||
}
|
||||
}
|
||||
|
||||
func importByName(anime *arn.Anime, companyType string, info []string) {
|
||||
studioMALID := info[0]
|
||||
slashPos := strings.Index(studioMALID, "/")
|
||||
|
||||
if slashPos != -1 {
|
||||
studioMALID = studioMALID[:slashPos]
|
||||
}
|
||||
|
||||
studioName := info[1]
|
||||
htmlPos := strings.Index(studioName, "<")
|
||||
|
||||
if htmlPos != -1 {
|
||||
studioName = studioName[:htmlPos]
|
||||
}
|
||||
|
||||
company, exists := companies[studioName]
|
||||
|
||||
if !exists {
|
||||
now = now.Add(-time.Second)
|
||||
|
||||
company = &arn.Company{
|
||||
ID: arn.GenerateID("Company"),
|
||||
Name: arn.CompanyName{
|
||||
English: studioName,
|
||||
},
|
||||
Created: now.UTC().Format(time.RFC3339),
|
||||
CreatedBy: "",
|
||||
Mappings: []*arn.Mapping{
|
||||
&arn.Mapping{
|
||||
Service: "myanimelist/producer",
|
||||
ServiceID: studioMALID,
|
||||
Created: arn.DateTimeUTC(),
|
||||
CreatedBy: "",
|
||||
},
|
||||
},
|
||||
Links: []*arn.Link{},
|
||||
Tags: []string{},
|
||||
Likes: []string{},
|
||||
}
|
||||
|
||||
companies[studioName] = company
|
||||
}
|
||||
|
||||
switch companyType {
|
||||
case "studio":
|
||||
anime.StudioIDs = append(anime.StudioIDs, company.ID)
|
||||
case "producer":
|
||||
anime.ProducerIDs = append(anime.ProducerIDs, company.ID)
|
||||
case "licensor":
|
||||
anime.LicensorIDs = append(anime.LicensorIDs, company.ID)
|
||||
}
|
||||
|
||||
anime.Save()
|
||||
}
|
||||
|
Reference in New Issue
Block a user