Added company import
This commit is contained in:
parent
15555f293f
commit
a8c5cafa4e
@ -9,7 +9,7 @@ import (
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
const maxEntries = 12
|
||||
const maxEntries = 24
|
||||
|
||||
// Get renders the companies page.
|
||||
func Get(ctx *aero.Context) string {
|
||||
|
@ -13,6 +13,11 @@ component CompanyPage(company *arn.Company, user *arn.User)
|
||||
if company.Location.Latitude != 0 && company.Location.Longitude != 0
|
||||
iframe.company-location.lazy(data-src="https://www.google.com/maps/embed/v1/place?q=" + toString(company.Location.Latitude) + "," + toString(company.Location.Longitude) + "&key=AIzaSyAsx6fhqRGaMLTixIJMIZBU4Mg6HJmvQf0")
|
||||
|
||||
.company-anime
|
||||
each anime in company.Anime()
|
||||
a.company-anime-item.ajax(href=anime.Link(), title=anime.Title.ByUser(user))
|
||||
img.company-anime-item-image.lazy(data-src=anime.Image("small"), data-webp="true", alt=anime.Title.ByUser(user))
|
||||
|
||||
component CompanyTabs(company *arn.Company, user *arn.User)
|
||||
.tabs
|
||||
Tab("Company", "building", company.Link())
|
||||
|
@ -4,4 +4,13 @@
|
||||
|
||||
.company-location
|
||||
width 100%
|
||||
height 300px
|
||||
height 300px
|
||||
|
||||
.company-anime
|
||||
horizontal-wrap
|
||||
|
||||
.company-anime-item
|
||||
anime-mini-item
|
||||
|
||||
.company-anime-item-image
|
||||
anime-mini-item-image
|
82
patches/import-companies/import-companies.go
Normal file
82
patches/import-companies/import-companies.go
Normal file
@ -0,0 +1,82 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/jikan"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
var jikanDB = arn.Node.Namespace("jikan")
|
||||
var companies = map[string]*arn.Company{}
|
||||
var now = time.Now()
|
||||
|
||||
func main() {
|
||||
defer arn.Node.Close()
|
||||
color.Yellow("Importing companies")
|
||||
|
||||
for anime := range arn.StreamAnime() {
|
||||
malID := anime.GetMapping("myanimelist/anime")
|
||||
|
||||
if malID == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
importCompanies(anime, malID)
|
||||
}
|
||||
|
||||
for name, company := range companies {
|
||||
fmt.Println(name)
|
||||
company.Save()
|
||||
}
|
||||
|
||||
color.Green("Finished importing %d companies", len(companies))
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
|
||||
func importCompanies(anime *arn.Anime, malID string) {
|
||||
obj, err := jikanDB.Get("Anime", malID)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
jikanAnime := obj.(*jikan.Anime)
|
||||
|
||||
for _, studioInfo := range jikanAnime.Studio {
|
||||
studioName := studioInfo[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{},
|
||||
Links: []*arn.Link{},
|
||||
Tags: []string{},
|
||||
Likes: []string{},
|
||||
}
|
||||
|
||||
companies[studioName] = company
|
||||
}
|
||||
|
||||
anime.StudioIDs = append(anime.StudioIDs, company.ID)
|
||||
anime.Save()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user