Added EU fire stats tweets
This commit is contained in:
parent
452f6baf45
commit
1eb6e45dfe
5 changed files with 80 additions and 21 deletions
|
|
@ -8,7 +8,9 @@ import countFires from './countFires';
|
|||
const autonomies = tbuffer(JSON.parse(getPrivateFile('data/es-atlas-autonomies.json')), 0);
|
||||
const portugal = tbuffer(JSON.parse(getPrivateFile('data/pt-atlas.json')), 0);
|
||||
|
||||
const stringsToRemove = [
|
||||
const europe = tbuffer(JSON.parse(getPrivateFile('data/europe-atlas.json')), 0);
|
||||
|
||||
const stringsToRemoveIberia = [
|
||||
['Ciudad Autónoma de', ''],
|
||||
['País Vasco/', ''],
|
||||
['Pais Vasco', 'Euskadi'],
|
||||
|
|
@ -28,7 +30,27 @@ const stringsToRemove = [
|
|||
[' ', '']
|
||||
];
|
||||
|
||||
const composeTweet = (num, stats) => {
|
||||
const composeEuropeTweet = (num, stats) => {
|
||||
if (num <= 0) {
|
||||
return '';
|
||||
}
|
||||
const keys = Object.keys(stats);
|
||||
const numZones = keys.length;
|
||||
let text = '';
|
||||
keys.map((key, index) => { // , index
|
||||
const zoneFires = stats[key];
|
||||
const zoneFiresText = zoneFires > 1 ? index === 0 ? zoneFires : `${zoneFires}` : index === 0 ? 'One' : '1';
|
||||
const what = index > 0 ? ' ' : zoneFires > 1 ? ' active #wildfires ' : ' active #wildfire ';
|
||||
const subText = `${zoneFiresText}${what}in #${key}`;
|
||||
const delimiter = index === numZones - 1 ? ' and' : ',';
|
||||
const subTexts = index === 0 ? subText : `${delimiter} ${subText}`;
|
||||
text += subTexts;
|
||||
return '';
|
||||
});
|
||||
return `${text}`;
|
||||
};
|
||||
|
||||
const composeIberiaTweet = (num, stats) => {
|
||||
if (num <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
|
@ -38,7 +60,7 @@ const composeTweet = (num, stats) => {
|
|||
keys.map((key, index) => { // , index
|
||||
const zoneFires = stats[key];
|
||||
const zoneFiresText = zoneFires > 1 ? index === 0 ? zoneFires : `otros ${zoneFires}` : index === 0 ? 'Un' : 'otro';
|
||||
const what = index > 0 ? ' ' : zoneFires > 1 ? ' fuegos activos ' : ' fuego activo ';
|
||||
const what = index > 0 ? ' ' : zoneFires > 1 ? ' #fuegos activos ' : ' #fuego activo ';
|
||||
const subText = `${zoneFiresText}${what}en #${key}`;
|
||||
const delimiter = index === numZones - 1 ? ' y' : ',';
|
||||
const subTexts = index === 0 ? subText : `${delimiter} ${subText}`;
|
||||
|
|
@ -51,16 +73,30 @@ const composeTweet = (num, stats) => {
|
|||
const tweetHeaders = ['🔥'];
|
||||
const tweetFooters = ['Más info en: https://fuegos.comunes.org/fires'];
|
||||
|
||||
const tweetFires = () => {
|
||||
const resultEs = countFires(autonomies, stringsToRemove);
|
||||
const resultPt = countFires(portugal, stringsToRemove);
|
||||
const tweetEuropeFires = () => {
|
||||
const resultEu = countFires(europe, [[' ', '']]);
|
||||
|
||||
if (resultEu.total > 0) {
|
||||
const tweetText = `${tweetHeaders[0].trim()} ${composeEuropeTweet(resultEu.total, resultEu.fires)}. More info: https://fires.comunes.org/fires`;
|
||||
if (Meteor.isDevelopment) {
|
||||
console.log(tweetText);
|
||||
} else {
|
||||
tweet(tweetText, 'en');
|
||||
}
|
||||
return tweetText;
|
||||
}
|
||||
};
|
||||
|
||||
const tweetIberiaFires = () => {
|
||||
const resultEs = countFires(autonomies, stringsToRemoveIberia);
|
||||
const resultPt = countFires(portugal, stringsToRemoveIberia);
|
||||
|
||||
const fires = Object.assign(resultEs.fires, resultPt.fires);
|
||||
const total = resultEs.total + resultPt.total;
|
||||
|
||||
// console.log(`Total fires ${total}, ${JSON.stringify(fires)}`);
|
||||
if (total > 0) {
|
||||
const tweetText = `${tweetHeaders[0].trim()} ${composeTweet(total, fires)}. ${tweetFooters[0]}`;
|
||||
const tweetText = `${tweetHeaders[0].trim()} ${composeIberiaTweet(total, fires)}. ${tweetFooters[0]}`;
|
||||
if (Meteor.isDevelopment) {
|
||||
console.log(tweetText);
|
||||
} else {
|
||||
|
|
@ -72,7 +108,8 @@ const tweetFires = () => {
|
|||
};
|
||||
|
||||
if (Meteor.isDevelopment) {
|
||||
tweetFires();
|
||||
tweetIberiaFires();
|
||||
tweetEuropeFires();
|
||||
}
|
||||
|
||||
export { composeTweet, tweetHeaders, tweetFooters, tweetFires };
|
||||
export { composeIberiaTweet, tweetHeaders, tweetFooters, tweetIberiaFires, tweetEuropeFires };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue