Rosetta Code/List authors of task descriptions: Difference between revisions
Rosetta Code/List authors of task descriptions (view source)
Revision as of 16:43, 12 January 2020
, 4 years ago→{{header|Go}}: Fixed bug, added some program comments and re-ran.
(Added Go) |
(→{{header|Go}}: Fixed bug, added some program comments and re-ran.) |
||
Line 51:
resp, _ := http.Get(url)
body, _ := ioutil.ReadAll(resp.Body)
// find all tasks
matches := re1.FindAllStringSubmatch(string(body), -1)
resp.Body.Close()
for _, match := range matches {
if !strings.HasPrefix(match[1], "Category:") {
tasks = append(tasks, match[1])
}
}
}
authors := make(map[string]int)
for _, task := range tasks {
// check the last or only history page for each task
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)
// find all the users in that page
matches := re2.FindAllStringSubmatch(string(body), -1)
resp.Body.Close()
// the task author should be the final user on that page
author := matches[len(matches)-1][2]
author = strings.ReplaceAll(author, "_", " ")
// add this task to the author's count
authors[author]++
}
// sort the authors in descending order by number of tasks created
authorNumbers := make([]authorNumber, 0, len(authors))
for k, v := range authors {
Line 74 ⟶ 83:
sort.Slice(authorNumbers, func(i, j int) bool {
return authorNumbers[i].number > authorNumbers[j].number
})
// print the top twenty say
fmt.Println("Total tasks :", len(tasks))
fmt.Println("Total authors :", len(authors))
Line 94 ⟶ 104:
{{out}}
As of
<pre>
Total tasks :
Total authors : 282
Line 105 ⟶ 115:
1: 176 Paddy3118
2: 71 Markhobley
3:
4: 55 Mwn3d
5: 39 NevilleDNZ
6:
7: 30 Nigel Galloway
8: 25 Thundergnat
Line 119 ⟶ 129:
15: 17 ShinTakezou
15: 17 Ledrug
18: 13 Paulo Jorente▼
18: 13 Waldorf▼
18: 13 Abu
▲18: 13 Waldorf
▲18: 13 Paulo Jorente
</pre>
|