Skip to content

Commit

Permalink
timezone input
Browse files Browse the repository at this point in the history
  • Loading branch information
austenstone committed Dec 20, 2021
1 parent f8e442f commit edd250e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ jobs:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GIST_ID: "40b6a7b4e19c1526619df8f99fbd522a"
PRODUCT_ID: "BTC-USD"
TIME_ZONE: "BTC-USD"
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { GistBox } = require('gist-box')
const fetch = require('node-fetch');
const fetch = require('node-fetch')

const gistId = process.env.GIST_ID
const ghToken = process.env.GH_TOKEN
const productId = process.env.PRODUCT_ID || 'BTC-USD'
const timeZone = process.env.TIME_ZONE || 'America/New_York'

const updateGist = async (content) => {
const box = new GistBox({ id: gistId, token: ghToken })
Expand All @@ -16,7 +17,7 @@ const updateGist = async (content) => {

const run = async () => {
let stats;
stats = await fetch(`https://api.pro.coinbase.com/products/${productId}/stats`).then(r => r.json());
stats = await fetch(`https://api.pro.coinbase.com/products/${productId}/stats`).then(r => r.json())
console.log('Got coinbase API stats ✅')

let percentChange = (stats.last - stats.open) / (stats.open * 100) * 10000
Expand All @@ -25,14 +26,12 @@ const run = async () => {
let content = `\
1₿ = $${stats.low}
${percentChange > 0 ? 'Up' : 'Down'} ${percentChange}% today
Updated at ${new Date().toLocaleTimeString('en-US', { hour: 'numeric', minute: 'numeric', timeZone: 'America/New_York' })} (EST)`
Updated at ${new Date().toLocaleTimeString('en-US', { hour: 'numeric', minute: 'numeric', timeZone })} (EST)`
console.log(`\n${content}\n`)

await updateGist(content)

console.log('Updated gist successfully ✅')
}

run().catch((err) => {
console.error('Failure ❌', err)
})
run().catch((err) => console.error('Failure ❌', err))

0 comments on commit edd250e

Please sign in to comment.