From 207fd7f52743f1e4aaa8d2fe677429595b559db0 Mon Sep 17 00:00:00 2001 From: Arya Kiran Date: Tue, 7 Feb 2023 21:12:18 +0530 Subject: [PATCH] cleanup the code a bit more --- pages/user.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/pages/user.go b/pages/user.go index 9d73f8a..d71efe9 100644 --- a/pages/user.go +++ b/pages/user.go @@ -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)