remove wip file

This commit is contained in:
Arya Kiran
2023-04-24 15:02:01 +05:30
parent 1346ec94f9
commit d3a4f02809
-102
View File
@@ -1,102 +0,0 @@
package pages
import (
"bytes"
"context"
"log"
"net/http"
"os"
"strings"
"codeberg.org/gothub/gothub/utils"
"github.com/gocolly/colly"
"github.com/gofiber/fiber/v2"
"github.com/sirupsen/logrus"
)
type TopicMeta struct {
Name string
Desc string
ImageLink string
CreatedBy string
Released string
Followers string
Company string
Links []string
Related []string
Language []string
Sort string
}
type TopicStuff struct {
FullName string
Desc string
Stars string
Language string
OtherTags []string
LastUpdate []string
ImageLink string
}
func HandleTopics(c *fiber.Ctx) error {
var topicMetaArray []TopicMeta
var topicStuffArray []TopicStuff
// Scraping
UserAgent, ok := os.LookupEnv("GOTHUB_USER_AGENT")
if !ok {
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
}
sc := colly.NewCollector(colly.AllowedDomains("github.com"), colly.UserAgent(UserAgent))
sc.OnHTML("div.border h1", func(e *colly.HTMLElement) {
topicMetaArray.FullName = e.Text
}
sc.OnHTML("div.p-4.mb-5", func(e *colly.HTMLElement) {
topicMetaArray.Desc = e.ChildText("div.markdown-body p")
topicMetaArray.Image = strings.TrimPrefix(e.ChildAttr("div.ml-sm-4 img", "src"), "https://raw.githubusercontent.com/")
})
sc.OnHTML("div.col-md-4", func(e *colly.HTMLElement) {
e.ForEach("p", func(i int, el *colly.HTMLElement) {
if e.ChildText("span") == "Created by" {
topicMetaArray.CreatedBy = strings.TrimPrefix(e.Text, "Created by")
} else if e.ChildText("span") == "Released" {
topicMetaArray.Released = strings.TrimPrefix(e.Text, "Released")
}
})
e.ForEach("dl dd", func(i int, el *colly.HTMLElement) {
if e.ChildAttr("svg", "aria-label") == "Topic followers" {
topicMetaArray.Followers = e.Text
} else if e.ChildText("svg.octicon-organization") {
topicMetaArray.Company = e.ChildText("span")
} else if e.ChildText("svg.octicon-link") {
topicMetaArray.Link = append(topicMetaArray.Link, el.ChildAttr("a", "href"))
}
})
e.ForEach("a.topic-tag", func(i int, el *colly.HTMLElement) {
topicMetaArray.Related = append(topicMetaArray.Related, e.Text)
})
})
sc.OnHTML("div.js-details-container div.Details-content--hidden-not-important", func(e *colly.HTMLElement) {
e.ForEach("div.js-navigation-item", func(i int, el *colly.HTMLElement) {
var FileType string
if el.ChildAttr("div.flex-shrink-0 svg", "aria-label") == "Directory" {
FileType = "dir"
} else {
FileType = "file"
}
repoFilesArray = append(repoFilesArray, RepoFiles{
Name: el.ChildText("div.flex-auto span.d-block a.js-navigation-open"),
Path: el.ChildText("div.flex-auto span.d-block a.js-navigation-open"),
Type: FileType,
Fullname: topicMetaArray.Fullname,
DefaultBranch: topicMetaArray.DefaultBranch,
})
})
})
sc.Visit("https://github.com/topics/" + c.Params("topic"))
return c.Render("repo", fiber.Map{
"title": "Topic " + topicMetaArray.Name,
"topicMeta": topicMetaArray,
"topicStuff": topicStuffArray,
})
}