Jump to content

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

→‎{{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 {
tasks// =exclude append(tasks,any match[1])'category' references
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 10th12th January 2020:
<pre>
Total tasks : 12221223
Total authors : 282
 
Line 105 ⟶ 115:
1: 176 Paddy3118
2: 71 Markhobley
3: 5960 Gerard Schildberger
4: 55 Mwn3d
5: 39 NevilleDNZ
6: 3433 Short Circuit
7: 30 Nigel Galloway
8: 25 Thundergnat
Line 119 ⟶ 129:
15: 17 ShinTakezou
15: 17 Ledrug
1715: 1617 Dmitry-kazakov
18: 13 Paulo Jorente
18: 13 Waldorf
18: 13 Abu
18: 13 Waldorf
18: 13 Paulo Jorente
</pre>
 
9,492

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.