added code to store data in airtable
This commit is contained in:
parent
30f0c90339
commit
58fae3cb44
2 changed files with 20 additions and 12 deletions
|
@ -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/)
|
- [moment.js](https://momentjs.com/)
|
||||||
- [node-schedule](https://www.npmjs.com/package/node-schedule)
|
- [node-schedule](https://www.npmjs.com/package/node-schedule)
|
||||||
- [Slack's Bolt API](https://slack.dev/bolt-js/tutorial/getting-started)
|
- [Slack's Bolt API](https://slack.dev/bolt-js/tutorial/getting-started)
|
||||||
|
- [Airtable](https://airtable.com/api)
|
||||||
|
|
||||||
\ ゜ o ゜)ノ
|
\ ゜ o ゜)ノ
|
||||||
|
|
21
app.js
21
app.js
|
@ -4,7 +4,7 @@ const keep_alive = require('./keep_alive.js')
|
||||||
const schedule = require('node-schedule');
|
const schedule = require('node-schedule');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const token = process.env.SLACK_BOT_TOKEN;
|
const token = process.env.SLACK_BOT_TOKEN;
|
||||||
const channel = "CDJMS683D"; //'C017W4PHYKS' for debugging, "CDJMS683D" actual
|
const channel = "CDJMS683D";
|
||||||
const Airtable = require('airtable');
|
const Airtable = require('airtable');
|
||||||
Airtable.configure({
|
Airtable.configure({
|
||||||
endpointUrl: 'https://api.airtable.com',
|
endpointUrl: 'https://api.airtable.com',
|
||||||
|
@ -116,9 +116,16 @@ async function report() {
|
||||||
latest = await fetchLatest(channel);
|
latest = await fetchLatest(channel);
|
||||||
let diff = latest - oldest;
|
let diff = latest - oldest;
|
||||||
speedArr.push(diff);
|
speedArr.push(diff);
|
||||||
// base('increase').create({
|
base('increase').create({
|
||||||
// "Date":
|
"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);
|
averageSpeed = findMean(speedArr).toFixed(3);
|
||||||
let thousandsGoal = Math.ceil(latest / 1000) * 1000;
|
let thousandsGoal = Math.ceil(latest / 1000) * 1000;
|
||||||
let thousandsTime = predictTime(thousandsGoal)
|
let thousandsTime = predictTime(thousandsGoal)
|
||||||
|
@ -145,9 +152,9 @@ async function report() {
|
||||||
"* \n :fastparrot: KEEP IT GOING GUYS!";
|
"* \n :fastparrot: KEEP IT GOING GUYS!";
|
||||||
if (pastThousandsGoal > oldest && pastThousandsGoal <= newest) {
|
if (pastThousandsGoal > oldest && pastThousandsGoal <= newest) {
|
||||||
let messageWithCelebration = ":tada: YAY! We've went past " + pastThousandsGoal + "! :tada: \n" + message;
|
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 {
|
} 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
|
// Start your app
|
||||||
try {
|
try {
|
||||||
await app.start(process.env.PORT || 3000);
|
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!')
|
publishMessage('C017W4PHYKS', 'running every midnight!')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
Loading…
Reference in a new issue