-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lau Skeeter
committed
May 20, 2018
1 parent
6d67a50
commit 34f1520
Showing
6 changed files
with
149 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters