added code to store data in airtable

This commit is contained in:
Abby 2020-08-17 23:15:49 +00:00
parent 30f0c90339
commit 58fae3cb44
2 changed files with 20 additions and 12 deletions

View file

@ -14,5 +14,6 @@ It also adds an emoji reaction at every number ending with 69, every 1000, and e
- [moment.js](https://momentjs.com/)
- [node-schedule](https://www.npmjs.com/package/node-schedule)
- [Slack's Bolt API](https://slack.dev/bolt-js/tutorial/getting-started)
- [Airtable](https://airtable.com/api)
\ ゜ o ゜)

21
app.js
View file

@ -4,7 +4,7 @@ const keep_alive = require('./keep_alive.js')
const schedule = require('node-schedule');
const moment = require('moment');
const token = process.env.SLACK_BOT_TOKEN;
const channel = "CDJMS683D"; //'C017W4PHYKS' for debugging, "CDJMS683D" actual
const channel = "CDJMS683D";
const Airtable = require('airtable');
Airtable.configure({
endpointUrl: 'https://api.airtable.com',
@ -116,9 +116,16 @@ async function report() {
latest = await fetchLatest(channel);
let diff = latest - oldest;
speedArr.push(diff);
// base('increase').create({
// "Date":
// })
base('increase').create({
"Date": moment().format("YYYY-MM-DD"),
"increase": diff
}, function(err, record) {
if (err) {
console.error(err);
return;
}
console.log(record.getId());
})
averageSpeed = findMean(speedArr).toFixed(3);
let thousandsGoal = Math.ceil(latest / 1000) * 1000;
let thousandsTime = predictTime(thousandsGoal)
@ -145,9 +152,9 @@ async function report() {
"* \n :fastparrot: KEEP IT GOING GUYS!";
if (pastThousandsGoal > oldest && pastThousandsGoal <= newest) {
let messageWithCelebration = ":tada: YAY! We've went past " + pastThousandsGoal + "! :tada: \n" + message;
publishMessage(channel, messageWithCelebration);
publishMessage(channel, messageWithCelebration); //'C017W4PHYKS' for debugging, channel for actual
} else {
publishMessage(channel,message);
publishMessage('C017W4PHYKS', message); //'C017W4PHYKS' for debugging, channel for actual
}
}
@ -179,7 +186,7 @@ app.event('message', async (body) => {
// Start your app
try {
await app.start(process.env.PORT || 3000);
let j = schedule.scheduleJob('0 0 * * *', report); // */1 * * * * for debugging, 0 0 * * * actual
let j = schedule.scheduleJob('*/1 * * * *', report); // */1 * * * * for debugging, 0 0 * * * actual
publishMessage('C017W4PHYKS', 'running every midnight!')
} catch (error) {
console.error(error);