Created
July 12, 2023 19:09
-
-
Save pentekostos/3b52da0868bcc28a824c4eba1d9169a0 to your computer and use it in GitHub Desktop.
val.town get airtable record stats.
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
const airtable_get_data = (async () => { | |
const today = new Date(); | |
today.setHours(0, 0, 0, 0); | |
const yesterday = new Date(today); | |
yesterday.setDate(yesterday.getDate() - 1); | |
const data = await @stevekrouse.fetchJSON( | |
"https://api.airtable.com/v0/<TASK_ID>/Tasks", | |
{ | |
headers: { | |
"Authorization": `Bearer ${@me.secrets.airtable_api_key}`, | |
}, | |
}, | |
); | |
let todayCount = 0; | |
let yesterdayCount = 0; | |
for (let record of data.records) { | |
const recordDate = new Date(record.fields.Created); | |
recordDate.setHours(0, 0, 0, 0); | |
if (+recordDate === +today) { | |
todayCount++; | |
} | |
else if (+recordDate === +yesterday) { | |
yesterdayCount++; | |
} | |
} | |
const message = | |
`You have completed ${todayCount} tasks today, compared to ${yesterdayCount} yesterday.`; | |
// Send a POST request to the Pushover API | |
await fetch("https://api.pushover.net/1/messages.json", { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify({ | |
token: @me.secrets.pushover_app_key, | |
user: @me.secrets.pushover_user, | |
message: message, | |
}), | |
}); | |
return message; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment