export for future cache
ci/woodpecker/push/goreleaser Pipeline was successful
Details
ci/woodpecker/push/goreleaser Pipeline was successful
Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>main
parent
b30e898d82
commit
480035417b
44
trending.go
44
trending.go
|
@ -8,45 +8,45 @@ import (
|
|||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
func trendingLang(lang string, timeframes []string) (language, error) {
|
||||
l := language{
|
||||
repositories: make([]repository, 0),
|
||||
func trendingLang(lang string, timeframes []string) (Language, error) {
|
||||
l := Language{
|
||||
Repositories: make([]Repository, 0),
|
||||
}
|
||||
repoMap := make(map[repository]struct{})
|
||||
repoMap := make(map[Repository]struct{})
|
||||
for _, timeframe := range timeframes {
|
||||
la, err := trendingRepos(lang, timeframe)
|
||||
if err != nil {
|
||||
return la, err
|
||||
}
|
||||
l.color = la.color
|
||||
for _, r := range la.repositories {
|
||||
l.Color = la.Color
|
||||
for _, r := range la.Repositories {
|
||||
repoMap[r] = struct{}{}
|
||||
}
|
||||
}
|
||||
for repo := range repoMap {
|
||||
l.repositories = append(l.repositories, repo)
|
||||
l.Repositories = append(l.Repositories, repo)
|
||||
}
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func trendingRepos(lang, timeframe string) (language, error) {
|
||||
func trendingRepos(lang, timeframe string) (Language, error) {
|
||||
u := fmt.Sprintf("https://github.com/trending/%s?since=%s", lang, timeframe)
|
||||
res, err := http.Get(u)
|
||||
if err != nil {
|
||||
return language{}, err
|
||||
return Language{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||
if err != nil {
|
||||
return language{}, err
|
||||
return Language{}, err
|
||||
}
|
||||
|
||||
var l language
|
||||
var l Language
|
||||
doc.Find(".Box-row").Each(func(_ int, s *goquery.Selection) {
|
||||
if l.color == "" {
|
||||
if l.Color == "" {
|
||||
rlcStyle, _ := s.Find(".repo-language-color").Attr("style")
|
||||
l.color = strings.Fields(rlcStyle)[1]
|
||||
l.Color = strings.Fields(rlcStyle)[1]
|
||||
}
|
||||
|
||||
e := s.Find("h1 a")
|
||||
|
@ -54,21 +54,21 @@ func trendingRepos(lang, timeframe string) (language, error) {
|
|||
|
||||
d := strings.TrimSpace(s.Find("p").Text())
|
||||
|
||||
l.repositories = append(l.repositories, repository{name: repo, description: d})
|
||||
l.Repositories = append(l.Repositories, Repository{Name: repo, Description: d})
|
||||
})
|
||||
return l, nil
|
||||
}
|
||||
|
||||
type language struct {
|
||||
color string
|
||||
repositories []repository
|
||||
type Language struct {
|
||||
Color string `json:"color"`
|
||||
Repositories []Repository `json:"repositories"`
|
||||
}
|
||||
|
||||
type repository struct {
|
||||
name string
|
||||
description string
|
||||
type Repository struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func (r repository) link() string {
|
||||
return fmt.Sprintf("https://github.com/%s", r.name)
|
||||
func (r Repository) link() string {
|
||||
return fmt.Sprintf("https://github.com/%s", r.Name)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue