Skip to content

Instantly share code, notes, and snippets.

@nenadom
Last active November 27, 2023 09:28
Show Gist options
  • Save nenadom/788b5d62f851c274f40801a3d8c6764e to your computer and use it in GitHub Desktop.
Save nenadom/788b5d62f851c274f40801a3d8c6764e to your computer and use it in GitHub Desktop.
Download Google Play Store badges
const fs = require('fs')
const request = require('request-promise-native')
const URI = 'https://play.google.com/intl/en_us/badges/images/generic'
const DEFAULT_BADGE_DIR = 'google-play-store-badges'
const ISO_CODES = [
'en', 'de', 'tr', 'es', 'pt', 'fr',
'it', 'ru', 'zh', 'pl', 'gr', 'hr',
'sr', 'da', 'hu', 'nl', 'sv', 'id',
'el', 'zh-cn'
]
const download = (baseUri, isoCode, callback) => {
const uri = `${baseUri}/${isoCode}_badge_web_generic.png`
const badgeFilename = `google-play-badge-${isoCode}.png`
request.head(uri)
.then(res => {
if (res.statusCode !== 404) {
request(uri)
.pipe(fs.createWriteStream(`${DEFAULT_BADGE_DIR}/google-play-badge-${isoCode}.png`))
}
})
.catch(err => console.error(err.options.uri))
}
const downloadPlayStoreBadges = () => {
if (!fs.existsSync(DEFAULT_BADGE_DIR)) fs.mkdirSync(DEFAULT_BADGE_DIR)
ISO_CODES.forEach(iso => {
download(URI, iso)
})
}
downloadPlayStoreBadges()
{
"name": "download-play-store-badges",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dl-badges": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"request": "^2.81.0",
"request-promise-native": "^1.0.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment