diff --git a/.fantarc b/.fantarc
index 7f40f99..a2d09fe 100644
--- a/.fantarc
+++ b/.fantarc
@@ -1,6 +1,11 @@
+const path = require('path');
+
module.exports = {
ports: {
test: 1234,
live: 3000
+ },
+ paths: {
+ screenie: path.resolve(__dirname, 'dest', 'screenie.png')
}
}
\ No newline at end of file
diff --git a/assets/fetch.js b/assets/fetch.js
index fc2d64e..67e2569 100644
--- a/assets/fetch.js
+++ b/assets/fetch.js
@@ -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(_=>`${_}`)
- .join('');
+ document.querySelector('x-fanta x-label').innerHTML = data.product
+ .map(_ => _.split(' '))
+ .reduce((a, b) => a.concat(b), [])
+ .map(_ => `${_}`)
+ .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();
diff --git a/bin/make-screenshot.js b/bin/make-screenshot.js
index 9251382..5fa6e60 100755
--- a/bin/make-screenshot.js
+++ b/bin/make-screenshot.js
@@ -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 => {
diff --git a/bin/tweet.js b/bin/tweet.js
index 94091bb..5331fee 100644
--- a/bin/tweet.js
+++ b/bin/tweet.js
@@ -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();
+})();
diff --git a/package-lock.json b/package-lock.json
index aaacc18..e389df4 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -377,6 +377,11 @@
"ms": "2.0.0"
}
},
+ "deep-extend": {
+ "version": "0.5.1",
+ "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.1.tgz",
+ "integrity": "sha512-N8vBdOa+DF7zkRrDCsaOXoCs/E2fJfx9B9MrKnnSiHNh4ws7eSys6YQE4KvT1cecKmOASYQBhbKjeuDD9lT81w=="
+ },
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
@@ -1733,6 +1738,25 @@
"resolved": "https://registry.npmjs.org/twemoji/-/twemoji-2.5.1.tgz",
"integrity": "sha1-KWZHxhY8fwR0WIccKuviXqj/6DQ="
},
+ "twit": {
+ "version": "2.2.9",
+ "resolved": "https://registry.npmjs.org/twit/-/twit-2.2.9.tgz",
+ "integrity": "sha1-ZxBXT4FkHaoDeWobS457eNPXVnY=",
+ "requires": {
+ "bluebird": "3.5.1",
+ "mime": "1.6.0",
+ "request": "2.85.0"
+ }
+ },
+ "twitter": {
+ "version": "1.7.1",
+ "resolved": "https://registry.npmjs.org/twitter/-/twitter-1.7.1.tgz",
+ "integrity": "sha1-B2I3jx3BwFDkj2ZqypBOJLGpYvQ=",
+ "requires": {
+ "deep-extend": "0.5.1",
+ "request": "2.85.0"
+ }
+ },
"type-is": {
"version": "1.6.16",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz",
diff --git a/src/product-maker.js b/src/product-maker.js
index ba019af..54a12bc 100644
--- a/src/product-maker.js
+++ b/src/product-maker.js
@@ -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 {
@@ -36,6 +44,6 @@ const make = async () => {
palette,
product,
};
-}
+};
module.exports = make;