Rosetta Code/List authors of task descriptions: Difference between revisions

Content added Content deleted
(Phix)
(Added Go)
Line 21: Line 21:
Please '''DO NOT''' add a full output for ''each'' programming language; just show a representative sample. For an full listing, see [[Rosetta_Code/List_authors_of_task_descriptions/Full_list]].
Please '''DO NOT''' add a full output for ''each'' programming language; just show a representative sample. For an full listing, see [[Rosetta_Code/List_authors_of_task_descriptions/Full_list]].



=={{header|Go}}==
<lang go>package main

import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
"sort"
"strings"
)

type authorNumber struct {
author string
number int
}

func main() {
ex1 := `<li><a href="/wiki/(.*?)"`
ex2 := `a href="/(wiki/User:|mw/index\.php\?title=User:|wiki/Special:Contributions/)([^"&]+)`
re1 := regexp.MustCompile(ex1)
re2 := regexp.MustCompile(ex2)
url1 := "http://rosettacode.org/wiki/Category:Programming_Tasks"
url2 := "http://rosettacode.org/wiki/Category:Draft_Programming_Tasks"
urls := []string{url1, url2}
var tasks []string
for _, url := range urls {
resp, _ := http.Get(url)
body, _ := ioutil.ReadAll(resp.Body)
matches := re1.FindAllStringSubmatch(string(body), -1)
resp.Body.Close()
for _, match := range matches {
tasks = append(tasks, match[1])
}
}
authors := make(map[string]int)
for _, task := range tasks {
page := fmt.Sprintf("http://rosettacode.org/mw/index.php?title=%s&dir=prev&action=history", task)
resp, _ := http.Get(page)
body, _ := ioutil.ReadAll(resp.Body)
matches := re2.FindAllStringSubmatch(string(body), -1)
resp.Body.Close()
author := matches[len(matches)-1][2]
author = strings.ReplaceAll(author, "_", " ")
authors[author]++
}
authorNumbers := make([]authorNumber, 0, len(authors))
for k, v := range authors {
authorNumbers = append(authorNumbers, authorNumber{k, v})
}
sort.Slice(authorNumbers, func(i, j int) bool {
return authorNumbers[i].number > authorNumbers[j].number
})
fmt.Println("Total tasks :", len(tasks))
fmt.Println("Total authors :", len(authors))
fmt.Println("\nThe top 20 authors by number of tasks created are:\n")
fmt.Println("Pos Tasks Author")
fmt.Println("=== ===== ======")
lastNumber, lastIndex := 0, -1
for i, authorNumber := range authorNumbers[0:20] {
j := i
if authorNumber.number == lastNumber {
j = lastIndex
} else {
lastIndex = i
lastNumber = authorNumber.number
}
fmt.Printf("%2d: %3d %s\n", j+1, authorNumber.number, authorNumber.author)
}
}</lang>

{{out}}
As of 10th January 2020:
<pre>
Total tasks : 1222
Total authors : 282

The top 20 authors by number of tasks created are:

Pos Tasks Author
=== ===== ======
1: 176 Paddy3118
2: 71 Markhobley
3: 59 Gerard Schildberger
4: 55 Mwn3d
5: 39 NevilleDNZ
6: 34 Short Circuit
7: 30 Nigel Galloway
8: 25 Thundergnat
9: 23 Grondilu
10: 21 Dkf
11: 20 Blue Prawn
11: 20 Fwend
13: 19 CalmoSoft
14: 18 Kernigh
15: 17 ShinTakezou
15: 17 Ledrug
17: 16 Dmitry-kazakov
18: 13 Paulo Jorente
18: 13 Waldorf
18: 13 Abu
</pre>


=={{header|Perl 6}}==
=={{header|Perl 6}}==