Improved company import
This commit is contained in:
parent
a8c5cafa4e
commit
3147477a44
@ -227,5 +227,20 @@ component AnimeInformation(anime *arn.Anime)
|
||||
td.anime-info-value
|
||||
a.ajax(href=company.Link())= company.Name.English
|
||||
|
||||
//- section.anime-section.mountable
|
||||
//- h3.anime-section-name Companies
|
||||
//- table.anime-info-table
|
||||
//- each company in anime.Producers()
|
||||
//- tr.mountable(data-mountable-type="info")
|
||||
//- td.anime-info-key Producer:
|
||||
//- td.anime-info-value
|
||||
//- a.ajax(href=company.Link())= company.Name.English
|
||||
|
||||
//- each company in anime.Licensors()
|
||||
//- tr.mountable(data-mountable-type="info")
|
||||
//- td.anime-info-key Licensor:
|
||||
//- td.anime-info-value
|
||||
//- a.ajax(href=company.Link())= company.Name.English
|
||||
|
||||
component FriendEntry(friend *arn.User, listItems map[*arn.User]*arn.AnimeListItem)
|
||||
CustomAvatar(friend, listItems[friend].Link(friend.Nick), friend.Nick + " => " + listItems[friend].Status + " | " + toString(listItems[friend].Episodes) + " eps | " + fmt.Sprintf("%.1f", listItems[friend].Rating.Overall) + " rating")
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user