aboutsummaryrefslogtreecommitdiff
path: root/subprojects/freeamo/src/search-pages~
blob: 3ffa9dd72e77f309d2b6692fb8ee9e9c2f99fa14 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
#    This file is part of FreeAMO
#    Copyright (C) 2017 David Hedlund
#
#    FreeAMO 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.
#
#    FreeAMO 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 "$run_path/build/json/search-pages" || exit

function search-pages--download() {

    echo "$debug"
    
    echo -e "\\nDownloading search pages:"

    echo "This file is used to describe the settings that were used to generate the files.

build/json/search-pages/
$wget_uri" > "$run_path/build/declared_settings.txt"
    # indicate that the page page variable are the page files
    sed -i "s|page=1|page=\$page|g" "$run_path/build/declared_settings.txt"



    #####################################################

    function wget_page {
        
        base_uri="https://addons.mozilla.org/api/v3/addons/search/?platform=linux&sort=users&type=extension&app=firefox&appversion=$latest_trisquel_icecat_version&page_size=50&page=";
        # sort=users. sort=name not working yet - https://github.com/mozilla/addons-server/issues/7600
        # page_size=50 -- this is the maximum accepted number, it makes the download much faster: 20 seconds for 10 x page_size=50, 35 seconds for 20 x page_size=25 (default)
        # page. Add this dynamic variable as the last variable to make it easy to read
        wget_uri="$base_uri$page";

        wget -q "$wget_uri" --no-verbose -O "$page.json"

        average_daily_users="$(jq ".results[].average_daily_users" "$page.json" | tail -n 1)"
        
    }
    
    page="1";
    wget_page

    page_count="$(jq ".page_count" "$page.json")";
    pv__size="$page_count"
    source "$run_path/src/main_functions"
    
    
    if [ "$debug" = true ]; then

        pv__size="2";

    else

        pv__size="$page_count"

    fi

    
    while [ "$page" -lt "$page_count" ]; do

        ((++page))
        
        if ( [ "$debug" = true ] && [ "$page" -le "3" ] || [ "$debug" = false ] ) && ( [ "$average_daily_users" -ge "$minimum_average_daily_users" ] ); then

            echo "$page"
            wget_page

        else

            exit 0
            
        fi
        
        echo "foo" # Must be here to work with pv
    done | progress
    
}

function search-pages--filter() {

 
    echo -e "\\nFilter search pages:"

    #    source "$run_path/src/main_functions"
    #    amo_variables
    echo "
build/index-search-pages.txt
has_eula=false
nativeMessaging__pass=true
minimum_average_daily_users=$minimum_average_daily_users" >> "$run_path/build/declared_settings.txt"

    pv__size=$(ls . | wc -l)
    output_file="$output_file_1";
    source "$run_path/src/main_functions"
    
    rm -f $output_file_1
    
    # Sort by file modification time stamp for the downloaded JSON files
    find . -type f  | sort -n | while read -r file; do

        
        filename="$(echo $(basename "$file"))";

        entry="0"; # Should not be 1

        for id in $(jq ".results[].average_daily_users" "$file"); do

            source "$run_path/src/main_functions"
            amo_variables
            
            essential_addon
            if [ "$essential_addon" = true ]; then
                
                echo -e "$filename\\t$entry" >> "$output_file_1"
                
            fi
            
            ((++entry))

        done

        echo "$filename"


        echo "foo" # Must be here to work with pv
    done | progress

}