From 24cefa1afaeddcf8f965cac27a81c702a9cc9256 Mon Sep 17 00:00:00 2001 From: Arya Kiran Date: Wed, 8 Feb 2023 18:57:45 +0530 Subject: [PATCH] User contributions --- pages/user.go | 29 +++++++++++++++++------------ views/user.html | 5 +++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pages/user.go b/pages/user.go index d2aa65e..cad1318 100644 --- a/pages/user.go +++ b/pages/user.go @@ -16,18 +16,19 @@ import ( ) type User struct { - Login string - Name string - Bio string - AvatarUrl string - Location string - Following int64 - Followers int64 - Link string - Company string - Type string - EwTwitter string - Readme string + Login string + Name string + Bio string + AvatarUrl string + Location string + Following int64 + Followers int64 + Link string + Company string + Type string + EwTwitter string + Contributions string + Readme string } type Ratelimit struct { @@ -152,6 +153,10 @@ func HandleUser(c *fiber.Ctx) error { Scrape.Login = e.ChildText("span[itemprop*='additionalName']") Scrape.Name = e.ChildText("span[itemprop*='name']") }) + // Contributions + sc.OnHTML("div.js-yearly-contributions", func(e *colly.HTMLElement) { + Scrape.Contributions = e.ChildText("h2") + }) } else { sc.OnHTML("img[alt*='@"+c.Params("user")+"' i]", func(e *colly.HTMLElement) { Scrape.AvatarUrl = e.Attr("src") diff --git a/views/user.html b/views/user.html index ddcb207..6f007ef 100644 --- a/views/user.html +++ b/views/user.html @@ -20,6 +20,8 @@ {{ if .Location }}

🌍 {{.Location}}

{{ end }} + {{ if .Timezone }} +

🕑️ {{.Timezone}}

{{ if .Link }}

🔗 {{.Link}}

{{ end }} @@ -29,6 +31,9 @@ {{ if .EwTwitter }}

🐦 {{.EwTwitter}}

{{ end }} + {{ if eq .Type "http://schema.org/Person" }} +

✏️ {{ if .Name }} {{.Name}} {{ else }} {{.Login}} {{ end }} has made {{.Contributions}}

+ {{ end }} {{ if .Bio }}