cleanup the code a bit more

This commit is contained in:
Arya Kiran
2023-02-07 21:12:18 +05:30
parent 4db2d1188e
commit 207fd7f527
+12 -15
View File
@@ -100,16 +100,26 @@ func HandleUser(c *fiber.Ctx) error {
}
}
// scraping
var Scrape User
var OrgOrUser string
Scrape := User{
Link: link,
Type: user.Get("type").String(),
EwTwitter: user.Get("twitter_username").String(),
Readme: string(readmeOutput),
}
sc1 := colly.NewCollector(colly.AllowedDomains("github.com"))
sc1.OnHTML("div[itemtype]", func(e *colly.HTMLElement) {
OrgOrUser = e.Attr("itemtype")
})
sc1.Visit("https://github.com/" + c.Params("user") + "/")
sc := colly.NewCollector(
colly.AllowedDomains("github.com"),
)
if OrgOrUser == "http://schema.org/Person" {
// Bio
sc.OnHTML("div[data-bio-text]", func(e *colly.HTMLElement) {
@@ -144,20 +154,7 @@ func HandleUser(c *fiber.Ctx) error {
log.Println("Bio and Location routes cannot be scraped for organizations")
}
sc.Visit("https://github.com/" + c.Params("user") + "/")
userArray = append(userArray, User{
Login: Scrape.Login,
Name: Scrape.Name,
Bio: Scrape.Bio,
AvatarUrl: Scrape.AvatarUrl,
Location: Scrape.Location,
Following: Scrape.Following,
Followers: Scrape.Followers,
Link: link,
Company: Scrape.Company,
Type: user.Get("type").String(),
EwTwitter: user.Get("twitter_username").String(),
Readme: string(readmeOutput),
})
userArray = append(userArray, scrape)
fmt.Println(userArray)