aboutsummaryrefslogtreecommitdiff
path: root/addons.mozilla.org-fsd/get-data/src/download-custom
blob: b6c5def6b609f2ee5517094cad6ba62f0fb305b3 (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash

#    This file is part of license-reporter
#    Copyright (C) 2017 David Hedlund
#
#    license-reporter is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    license-reporter is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

cd build || exit
mkdir json

cp -a "$RUN_PATH/license-reporter-custom" custom_addons.txt

# Sanitize a copy from empty lines, they use to occur at the end of the file
sed -i '/^\s*$/d' license-reporter-custom


sed -i "s|https://addons.mozilla.org/en-US/firefox/addon/||g; s|/||" custom_addons.txt

rm -fr \
    custom_addons-json-source.txt \
    custom_addons-average_daily_users.txt \
    custom_addons-id.txt custom_addons-slug.txt \
    custom_addons-merged.txt \
    custom_addons-report-expired_links.txt \
    custom_addons-merged-sorted.txt

cd json || exit

lines="1";

while IFS= read -r slug; do


    if [ "$debug" == false ] || ( [ "$debug" == true ] && [ "$lines" -le 3 ] ); then

        wget "https://addons.mozilla.org/api/v3/addons/addon/$slug/" -O "$slug.json";
        [ -s "$slug.json" ] || rm -f "$slug.json" # Delete empty files saved by wget, tis is much faster than using wget options to first validate the links.
        
        # Ignore expired URLs
        if [ -f "$slug.json" ]; then

            id="$(jq ".id" "$slug.json")";
            mv "$slug.json" "$id.json"

            if [ "$(jq ".average_daily_users" "$id.json")" -gt "$minimum_average_daily_users" ]; then
                
                echo -e "$(date +%Y-%m-%d" "%H:%M)\tCustom list\tAlready in the main repository\thttps://addons.mozilla.org/en-US/firefox/addon/$slug/" >> "$RUN_PATH/license-reporter-log"

            else

                jq ".average_daily_users" "$id.json" >> ../custom_addons-average_daily_users.txt

                # We need the JSON source because they are different for search indexed add-ons (they are store in index.html*)
                jq ".id" "$id.json" >> ../custom_addons-id.txt
                echo "$(jq ".id" "$id.json").json" >> ../custom_addons-json-source.txt

                ((lines++))


            fi
            

        else
            
            echo -e "$(date +%Y-%m-%d" "%H:%M)\tCustom list\tLink rot\t\t\thttps://addons.mozilla.org/en-US/firefox/addon/$slug/" >> "$RUN_PATH/license-reporter-log"

        fi

    fi

done < ../custom_addons.txt

# Sort by average_daily_users
paste ../custom_addons-average_daily_users.txt ../custom_addons-id.txt ../custom_addons-json-source.txt > ../custom_addons-merged.txt
sort -k1,1nr ../custom_addons-merged.txt > ../merged-custom.txt