Last active
March 24, 2021 17:17
-
-
Save nielslange/200a060b599675b28bcd54417289bb25 to your computer and use it in GitHub Desktop.
Get all WordPress.org themes with more than 100.000 active installs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let url = 'https://api.wordpress.org/themes/info/1.2/?action=query_themes&request[search]=%20&request[fields][downloaded]=true&request[fields][active_installs]=true&request[per_page]=-1'; | |
let results = await fetch( url ) | |
.then( response => response.json() ) | |
.then( data => data.info.results ) | |
.catch(err => console.log( err ) ); | |
console.log(results); | |
let max = 1000; | |
let pages = Math.ceil(results / max); | |
console.log(pages); | |
for (let page = 1; page <= pages; page++) { | |
let url = `https://api.wordpress.org/themes/info/1.2/?action=query_themes&request[search]=%20&request[fields][downloaded]=true&request[fields][active_installs]=true&request[per_page]=${max}&request[page]=${page}`; | |
let downloads = 0; | |
let installs = 0; | |
let installed = 100000; | |
let themes_all; | |
let themes_filtered; | |
let theme; | |
fetch( url ) | |
.then( response => response.json() ) | |
.then( data => { | |
themes_all = data['themes']; | |
themes_filtered = themes_all.filter( a => a.active_installs >= installed ); | |
themes_filtered.sort( ( a, b ) => b.active_installs - a.active_installs ); | |
for ( theme of themes_filtered ) { | |
downloads += theme['downloaded']; | |
installs += theme['active_installs']; | |
console.log( theme['name'] + " had been downloaded " + theme['downloaded'].toLocaleString() + " and installed " + theme['active_installs'].toLocaleString() + " times." ); | |
} | |
} ) | |
.catch(err => console.log( err ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment