2020-02-18 15:00:36 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Promise = require('bluebird');
|
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const knex = require('../knex');
|
|
|
|
|
|
|
|
async function init() {
|
2020-05-14 02:26:05 +00:00
|
|
|
const sites = await knex('sites')
|
|
|
|
.select('networks.name', 'sites.slug')
|
|
|
|
.join('networks', 'networks.id', 'sites.network_id')
|
|
|
|
.where('networks.slug', 'score');
|
2020-02-18 15:00:36 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
await Promise.map(sites, async (site) => {
|
|
|
|
const url = `https://cdn77.scoreuniverse.com/${site.slug}/images/logo.png`;
|
2020-02-18 15:00:36 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
console.log(url);
|
2020-02-18 15:00:36 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const res = await bhttp.get(url, {
|
|
|
|
responseTimeout: 5000,
|
|
|
|
});
|
2020-02-18 15:00:36 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (res.statusCode === 200) {
|
|
|
|
console.log(`Saving logo for ${site.slug}`);
|
2020-02-18 15:00:36 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
await fs.writeFile(`./score/${site.slug}.png`, res.body);
|
|
|
|
}
|
2020-02-18 15:00:36 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
console.log(`No logo found for ${site.slug}`);
|
|
|
|
}, {
|
|
|
|
concurrency: 10,
|
|
|
|
});
|
2020-02-18 15:00:36 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
knex.destroy();
|
2020-02-18 15:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init();
|