Created
January 5, 2020 17:57
-
-
Save lemoncmd/c967f248a79d3a208bfd457a2379dc8c to your computer and use it in GitHub Desktop.
Revisions
-
lemoncmd created this gist
Jan 5, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ import ( net.http json math ) const ( disp_len = 100 ) struct Data { stargazers_count int } fn get_stargazer(name string) ?Data { resp := http.get('https://api.github.com/repos/$name') or { return error('Cannot fetch GitHub repository `$name`') } if resp.status_code != 200 { return error('Cannot fetch GitHub repository `$name`') } text := resp.text data := json.decode(Data, text) or { return error('Cannot parse json from fetched data') } return data } fn main() { v := get_stargazer('vlang/v')? crystal := get_stargazer('crystal-lang/crystal')? ruby := get_stargazer('ruby/ruby')? diff := ruby.stargazers_count - crystal.stargazers_count prog := math.max(f64(0), ruby.stargazers_count - v.stargazers_count) / diff done := '|'.repeat(int((f64(1) - prog) * disp_len)) notdone := '-'.repeat(int(prog * disp_len)) println('crystal|$done\(v)$notdone|ruby') }