Skip to content

Commit

Permalink
ALL SET
Browse files Browse the repository at this point in the history
  • Loading branch information
Lau Skeeter committed May 20, 2018
1 parent 6d67a50 commit 34f1520
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .fantarc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const path = require('path');

module.exports = {
ports: {
test: 1234,
live: 3000
},
paths: {
screenie: path.resolve(__dirname, 'dest', 'screenie.png')
}
}
41 changes: 25 additions & 16 deletions assets/fetch.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
const fetcher = async () => {
const data = await fetch('/make').then(_=>_.json()).catch(()=>{});
if(!data || !data.product) return fetcher();
else return data
}
const data = await fetch('/make')
.then(_ => _.json())
.catch(() => {});
if (!data || !data.product) return fetcher();
else return data;
};

const go = async () => {
const data = await fetcher();
const rotation = 5 - Math.random()*10;
const rotation = 5 - Math.random() * 10;

document.querySelector('x-fanta x-label').innerHTML =
data.product
.map(_=>_.split(' '))
.reduce((a, b) => a.concat(b), [])
.map(_=>`<span>${_}</span>`)
.join('');
document.querySelector('x-fanta x-label').innerHTML = data.product
.map(_ => _.split(' '))
.reduce((a, b) => a.concat(b), [])
.map(_ => `<span>${_}</span>`)
.join('');
document.querySelector('x-fanta .edible').src = `/emoji/${data.edible}.svg`;
document.querySelector('x-fanta').attributeStyleMap.set('background-color',`rgb(${data.hero._rgb.join()})`);
document.querySelector('x-fanta').attributeStyleMap.set('transform',`rotate(${rotation}deg)`);
document.querySelector('body').attributeStyleMap.set('background-color',`rgb(${data.palette[0]._rgb.join()})`);
document
.querySelector('x-fanta')
.attributeStyleMap.set('background-color', `rgb(${data.hero._rgb.join()})`);
document
.querySelector('x-fanta')
.attributeStyleMap.set('transform', `rotate(${rotation}deg)`);
document
.querySelector('body')
.attributeStyleMap.set(
'background-color',
`rgb(${data.palette[0]._rgb.join()})`
);

console.log(JSON.stringify(data));

}
};
go();
2 changes: 1 addition & 1 deletion bin/make-screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = require('../.fantarc');
const puppeteer = require('puppeteer');
const path = require('path');

const outPath = path.resolve(__dirname, '..', 'dest', 'screenie.png');
const outPath = config.paths.screenie;

const startServer = () =>
new Promise(rt => {
Expand Down
75 changes: 67 additions & 8 deletions bin/tweet.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,69 @@
require('dotenv').config();

const getFanta = require('./make-screenshot');
const config = require('../.fantarc');
const twitter = require('twitter');
const fs = require('fs');
const chalk = require('chalk');
const randomArrKey = items => items[Math.floor(Math.random() * items.length)];

const vocabulary = [
'Beat the heat with $1!',
'Relax with a fresh $1',
'Chill alongside a $1',
'Try the new $1',
'Enjoy some $1',
'Ever tried $1?',
];

const client = new twitter({
consumer_key: process.env.TWITTER_CK,
consumer_secret: process.env.TWITTER_CS,
access_token_key: process.env.TWITTER_TK,
access_token_secret: process.env.TWITTER_TS,
});

(async () => {
try {
const data = await getFanta();

const product = [...data.product, 'fanta']
.join(' ')
.split(' ')
.map(word =>
word
.split('')
.map(
(letter, i) =>
i === 0 ? letter.toUpperCase() : letter.toLowerCase()
)
.join('')
)
.join(' ');

const body = randomArrKey(vocabulary).replace('$1', product);

console.info(chalk.blue(`i Post info:`));
console.info(body, data);

await client
.post('media/upload', { media: fs.readFileSync(config.paths.screenie) })
.then(screenshot =>
client.post('statuses/update', {
media_ids: screenshot.media_id_string,
status: body,
})
)
.then(tweet => {
console.info(chalk.green(`✔ Posted: ${body}`));
console.info(tweet);
return true;
});
} catch (error) {
console.error(chalk.red('✘ Post failed'));
console.error(error);
return;
}

getFanta()
.then(log => {
console.log(log);
process.exit();
})
.catch(err => {
throw err;
});
process.exit();
})();
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 27 additions & 19 deletions src/product-maker.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
const fs = require("fs");
const emojiDict = require("emoji-dictionary");
const twemoji = require("twemoji");
const colors = require('get-image-colors')
const randomArrKey = (items) => items[Math.floor(Math.random()*items.length)];
const fs = require('fs');
const emojiDict = require('emoji-dictionary');
const twemoji = require('twemoji');
const colors = require('get-image-colors');
const randomArrKey = items => items[Math.floor(Math.random() * items.length)];

const edibles = [...fs.readFileSync('./assets/words/edible-emoji.txt', 'utf8')];
const adjs = fs.readFileSync('./assets/words/adjectives.txt', 'utf8').split("\n").filter(_ => _ != '');
const adjs = fs
.readFileSync('./assets/words/adjectives.txt', 'utf8')
.split('\n')
.filter(_ => _ != '');

const fiddle = (color) => {
const fiddle = color => {
const fuzzyness = 100;
[0,1,2].forEach(i=>{
color._rgb[i] = color._rgb[i] - (fuzzyness/2) + Math.random()*fuzzyness
})
[0, 1, 2].forEach(i => {
color._rgb[i] = color._rgb[i] - fuzzyness / 2 + Math.random() * fuzzyness;
});
return color;
}
};

const make = async () => {
const product = [];
const [edible, adj] = [randomArrKey(edibles), randomArrKey(adjs)];
const edibleName = emojiDict.getName(edible).replace(/_/g,' ').replace(/[\d-]/g,'');
const hasAdj = Math.random() > .2;

const point = await new Promise(_=>{
twemoji.parse(edible,(a)=>_(a))
const edibleName = emojiDict
.getName(edible)
.replace(/_/g, ' ')
.replace(/[\d-]/g, '');
const hasAdj = Math.random() > 0.2;

const point = await new Promise(_ => {
twemoji.parse(edible, a => _(a));
});

const palette = await colors(`./node_modules/twemoji/2/svg/${point}.svg`).then(_=>_.map(fiddle));
const palette = await colors(
`./node_modules/twemoji/2/svg/${point}.svg`
).then(_ => _.map(fiddle));

if(hasAdj) product.push(adj);
if (hasAdj) product.push(adj);
product.push(edibleName);

return {
Expand All @@ -36,6 +44,6 @@ const make = async () => {
palette,
product,
};
}
};

module.exports = make;

0 comments on commit 34f1520

Please sign in to comment.