Skip to content

Commit

Permalink
Complete crypto auto update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ilagon committed Aug 9, 2021
1 parent 1b97864 commit 8faaf8e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ Queried prices are then used to update custom notion pages to reflect updated pr
## Tech Stack:
- NodeJS
- Express
- Notion
- NotionAPI

## APIs:
- [CoinGecko](https://www.coingecko.com/en/api)
- [FinnHub](https://finnhub.io/docs/api)
- [NotionAPI](https://developers.notion.com)

## TODO:
- Finish up logic of crypto price update
- Integrate node-scheduler for automatic updates
- Start integrating stocks update scheduler
- Integrate node-schedule for automatic updates
- Start integrating stocks update scheduler

## Setup requirements:
- A notion database similar to [this](https://lorenzo-adco.notion.site/a66abb2318a546bd93f20de20c2298f4?v=976b04b7193642559f8767cdaf632105) (Only Active Track, ID and Price properties are actually required)

- Your own notion API key and database keys. Check [here](https://developers.notion.com/docs/getting-started) for instructions on getting your own keys

2 changes: 0 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var cookieParser = require('cookie-parser');
var logger = require('morgan');
require('dotenv').config();

let cryptoRouter = require('./routes/coingecko');
let notionRoute = require('./routes/notion');

var app = express();
Expand All @@ -13,7 +12,6 @@ app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());

app.use('/test', cryptoRouter);
app.use('/v1/notion', notionRoute);

module.exports = app;
19 changes: 18 additions & 1 deletion controller/notionController.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {Client} = require("@notionhq/client");
const cryptoUtils = require("../util/cryptoUtil");
const notion = new Client({auth: process.env.NOTION_INTEGRATION_TOKEN});
let idList = [];


const findTrackingList = async () => {
const dbID = process.env.NOTION_CRYPTO_ID;
Expand All @@ -18,11 +18,28 @@ const findTrackingList = async () => {
}

exports.updateTrackedPrices = async (req,res) => {
let idList = [];
let trackingList = await findTrackingList();

//Retrieve tracked IDs
trackingList.forEach(tracker => {
idList.push(tracker.properties.ID.rich_text[0].text.content);
});
let currentPrices = await cryptoUtils.get_price(idList.join(","));
console.log(currentPrices);

//Updated prices
trackingList.forEach(async tracker => {
const pageId = tracker.id;
const response = await notion.pages.update({
page_id: pageId,
properties: {
'Price':{
number: currentPrices[tracker.properties.ID.rich_text[0].text.content].usd
}
}
});
//console.log(response);
});
res.end();
}

0 comments on commit 8faaf8e

Please sign in to comment.