-
Notifications
You must be signed in to change notification settings - Fork 11
/
rebuild-popular-crates.sh
executable file
·57 lines (48 loc) · 1.52 KB
/
rebuild-popular-crates.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# This script rebuilds the popular-crates.txt file from lib.rs
# In theory we could use the crates.io db dump.
# See https://github.com/cargo-bins/cargo-quickinstall/issues/268#issuecomment-2329308074
#
# get-popular-crates.sh also seems to re-implement the functionality of this script.
#
# pup can be installed via: go get github.com/ericchiang/pup
# uq can be installed using cargo-quickinstall
set -euo pipefail
which pup || (
echo "pup can be installed via: go get github.com/ericchiang/pup"
exit 1
)
which uq || (
echo "uq can be installed using cargo-quickinstall"
exit 1
)
function get_top() {
curl --fail "https://lib.rs/$1" |
pup ':parent-of(:parent-of(:parent-of(.bin))) json{}' |
jq -r '.[] |
(.children[1].children|map(select(.class == "downloads").title)[0]// "0 ")
+ ":" +
(.children[0].children[0].text)' |
sort -gr |
grep -v / |
grep -v ^0 |
head -n 100 |
tee /dev/fd/2 | # debugging goes to stderr
sed s/^.*://
echo "done with $1" 1>&2
}
function get_top_both() {
(
get_top command-line-utilities
get_top development-tools/cargo-plugins
) | sort
}
function get_new_file_contents() {
(
grep -B10000 '####################################' popular-crates.txt
get_top_both
) | uq
}
get_new_file_contents >popular-crates.txt.new
mv popular-crates.txt.new popular-crates.txt
echo "popular-crates.txt has been rebuilt. Please check the changes into git"