-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 38cca2e
Showing
6 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
out.html | ||
test.sh | ||
testh.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# ac-profile | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module ac-profile | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/PuerkitoBio/goquery v1.8.0 // indirect | ||
github.com/andybalholm/cascadia v1.3.1 // indirect | ||
github.com/fatih/color v1.14.1 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
golang.org/x/net v0.6.0 // indirect | ||
golang.org/x/sys v0.5.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U= | ||
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI= | ||
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c= | ||
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= | ||
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w= | ||
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg= | ||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= | ||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= | ||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= | ||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= | ||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= | ||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= | ||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= | ||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
//"os" | ||
"flag" | ||
"strconv" | ||
"strings" | ||
"github.com/PuerkitoBio/goquery" | ||
"regexp" | ||
"unicode/utf8" | ||
//"image" | ||
) | ||
|
||
func ratingColor(rating int,s string) string { | ||
if rating>=2800{ | ||
return "\033[38;5;196m"+s+"\033[m" | ||
} else if rating>=2400{ | ||
return "\033[38;5;208m"+s+"\033[m" | ||
} else if rating>=2000{ | ||
return "\033[38;5;226m"+s+"\033[m" | ||
} else if rating>=1600{ | ||
return "\033[38;5;27m"+s+"\033[m" | ||
} else if rating>=1200{ | ||
return "\033[38;5;123m"+s+"\033[m" | ||
} else if rating>=800{ | ||
return "\033[38;5;76m"+s+"\033[m" | ||
} else if rating>=400{ | ||
return "\033[38;5;94m"+s+"\033[m" | ||
} else{ | ||
return "\033[38;5;248m"+s+"\033[m" | ||
} | ||
} | ||
|
||
func max(x int,y int) int { | ||
if x>y{ | ||
return x | ||
} else{ | ||
return y | ||
} | ||
} | ||
|
||
func paddingSpace(s string,n int) string{ | ||
return s+strings.Repeat(" ",n-utf8.RuneCountInString(s)) | ||
} | ||
|
||
func main(){ | ||
var( | ||
//u=flag.String("u","tourist","user name flag") | ||
t=flag.String("t","a","rating type flag") | ||
) | ||
flag.Parse() | ||
if len(flag.Args())==0{ | ||
fmt.Println("fatal error : no input user name") | ||
return | ||
} | ||
webPage:="https://atcoder.jp/users/"+flag.Arg(0) | ||
if *t=="h"{ | ||
webPage+="?contestType=heuristic" | ||
} | ||
resp,err:=http.Get(webPage) | ||
if err!=nil{ | ||
fmt.Println("failed to get html") | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != 200{ | ||
fmt.Println("failed to fetch data") | ||
return | ||
} | ||
|
||
doc,err:=goquery.NewDocumentFromReader(resp.Body) | ||
if err!=nil{ | ||
log.Printf("failed to load html:%s",err) | ||
} | ||
|
||
user:=flag.Arg(0) | ||
country:="" | ||
birth:="" | ||
twitter:="" | ||
affiliation:="" | ||
rank:="" | ||
rating:="" | ||
|
||
/* | ||
imgUrl,exists:=doc.Find(".avatar").Attr("src") | ||
if exists{ | ||
if imgUrl=="//img.atcoder.jp/assets/icon/avatar.png"{imgUrl="https:"+imgUrl} | ||
//fmt.Println(imgUrl) | ||
imgResp,err:=http.Get(imgUrl) | ||
if err!=nil{ | ||
fmt.Println("failed to get icon-img") | ||
} | ||
defer imgResp.Body.Close() | ||
} | ||
*/ | ||
maxLen:=0 | ||
doc.Find("div .dl-table tr").Each(func(i int,s *goquery.Selection){ | ||
title:=s.Find("th").Text() | ||
item:=strings.TrimSpace(s.Find("td").Text()) | ||
item=strings.Replace(item,"\t","",-1) | ||
item=strings.Replace(item,"\n","",-1) | ||
if title=="Country/Region"{ | ||
country=item | ||
maxLen=max(maxLen,utf8.RuneCountInString(title)) | ||
} else if title=="Birth Year"{ | ||
birth=item | ||
maxLen=max(maxLen,utf8.RuneCountInString(title)) | ||
} else if title=="Twitter ID"{ | ||
twitter=item | ||
maxLen=max(maxLen,utf8.RuneCountInString(title)) | ||
} else if title=="Affiliation"{ | ||
affiliation=item | ||
maxLen=max(maxLen,utf8.RuneCountInString(title)) | ||
} else if title=="Rank"{ | ||
rank=item | ||
maxLen=max(maxLen,utf8.RuneCountInString(title)) | ||
} else if title=="Rating"{ | ||
rex:=regexp.MustCompile("[0-9]+") | ||
item=rex.FindString(item) | ||
rating=item | ||
maxLen=max(maxLen,utf8.RuneCountInString(title)) | ||
} | ||
}) | ||
if *t=="a"{ | ||
fmt.Println("[Algorithm]") | ||
} else{ | ||
fmt.Println("[Heuristic]") | ||
} | ||
if rating!=""{ | ||
rate,err:=strconv.Atoi(rating) | ||
if err!=nil{ | ||
log.Fatalf("failed to string to int:%s",err) | ||
} | ||
fmt.Println(paddingSpace("User",maxLen)+" : "+ratingColor(rate,user)) | ||
} else{ | ||
fmt.Println(paddingSpace("User",maxLen)+" : "+user) | ||
} | ||
if country!=""{ | ||
fmt.Println(paddingSpace("Country/Region",maxLen)+" : "+country) | ||
} | ||
if birth!=""{ | ||
fmt.Println(paddingSpace("Birth Year",maxLen)+" : "+birth) | ||
} | ||
if twitter!=""{ | ||
fmt.Println(paddingSpace("Twitter ID",maxLen)+" : "+twitter) | ||
} | ||
if affiliation!=""{ | ||
fmt.Println(paddingSpace("Affiliation",maxLen)+" : "+affiliation) | ||
} | ||
if rank!=""{ | ||
fmt.Println(paddingSpace("Rank",maxLen)+" : "+rank) | ||
} | ||
if rating!=""{ | ||
rate,err:=strconv.Atoi(rating) | ||
if err!=nil{ | ||
log.Fatalf("failed to string to int:%s",err) | ||
} | ||
fmt.Println(paddingSpace("Rating",maxLen)+" : "+ratingColor(rate,rating)) | ||
} | ||
} |