add languages used in repo

This commit is contained in:
Arya Kiran
2023-02-14 20:51:44 +05:30
parent 8aef883056
commit 270e2d92f9
2 changed files with 16 additions and 7 deletions
+7 -5
View File
@@ -19,7 +19,7 @@ type Repo struct {
Stars string
Forks string
Watchers string
Language string
Language []string
License string
DefaultBranch string
Readme string
@@ -63,9 +63,7 @@ func HandleRepo(c *fiber.Ctx) error {
}
// Scraping
Scrape := Repo{
Language: repo.Get("language").String(),
}
Scrape := Repo{}
UserAgent, ok := os.LookupEnv("GOTHUB_USER_AGENT")
if !ok {
@@ -84,6 +82,11 @@ func HandleRepo(c *fiber.Ctx) error {
sc.OnHTML("div#readme", func(e *colly.HTMLElement) {
Scrape.Readme = e.ChildText("a[href*='#readme']")
})
sc.OnHTML("div.BorderGrid-cell ul.list-style-none", func(e *colly.HTMLElement) {
e.ForEach("li.d-inline .d-inline-flex", func(i int, el *colly.HTMLElement) {
Scrape.Language = append(Scrape.Language, el.ChildText("span.text-bold")+" "+el.ChildText("span:contains('%')"))
})
})
sc.OnHTML("div#repository-container-header", func(e *colly.HTMLElement) {
Scrape.Parent = e.ChildText("span.text-small a")
})
@@ -92,7 +95,6 @@ func HandleRepo(c *fiber.Ctx) error {
})
sc.Visit("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/")
// Add scrape-based info to repoArray
repoArray = append(repoArray, Scrape)
+9 -2
View File
@@ -17,10 +17,17 @@
<p>{{.Description}}</p>
{{ end }}
{{ if .License }}
<p>⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ {{.License}} {{ if .Language }} 🗒️ {{.Language}} {{end}} 🌿 {{.DefaultBranch}}</p>
<p>⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ {{.License}} 🌿 {{.DefaultBranch}}</p>
{{ else }}
<p>⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ No license {{ if .Language }} 🗒️ {{.Language}} {{end}} 🌿 {{.DefaultBranch}}</p>
<p>⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ No license 🌿 {{.DefaultBranch}}</p>
{{ end }}
{{ if .Language }}
<p>🗒️
{{range .Language}}
{{.}}
{{end}}
</p>
{{end}}
</div>
{{end}}
{{ if .files}}