diff --git a/.env.example b/.env.example index de627f0a..9ba8efba 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ NOTION_API_TOKEN= NOTION_READER_DATABASE_ID= NOTION_FEEDS_DATABASE_ID= +RUN_FREQUENCY=86400 # in seconds diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 96c75e12..bec83c4f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: Get Feed on: schedule: - - cron: "30 12 * * *" # 6pm IST + - cron: '30 12 * * *' # 6pm IST workflow_dispatch: jobs: @@ -12,6 +12,7 @@ jobs: NOTION_API_TOKEN: ${{ secrets.NOTION_API_TOKEN }} NOTION_READER_DATABASE_ID: ${{ secrets.NOTION_READER_DATABASE_ID }} NOTION_FEEDS_DATABASE_ID: ${{ secrets.NOTION_FEEDS_DATABASE_ID }} + RUN_FREQUENCY: 86400 # in seconds steps: - name: Setup Node uses: actions/setup-node@v2 diff --git a/README.md b/README.md index e4e04066..bc4696cc 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,19 @@ Notion Feeder - Convert Notion to a Feed Reader | Product Hunt -# Notion Feeder +--- -A Node.js app for creating a Feed Reader in [Notion](https://notion.so). +If you love this product and value my time, consider [sending some love](https://paypal.me/ravgeetdhillon) to me. This will enable me to work on more projects like these in the future. -![](/screenshots/working.gif) +[![PayPal Donate Button](https://images.squarespace-cdn.com/content/v1/55f62c4ce4b02545cc6ee94f/1558204823259-CQ0YNKZEHP7W5LO64PBU/paypal-donate-button-1.PNG?format=300w)](https://paypal.me/ravgeetdhillon) -*** +--- -If you loved this product and value my time, consider [sending some love](https://paypal.me/ravgeetdhillon) to me. This will enable me to work on more projects like these in the future. +# Notion Feeder -[![PayPal Donate Button](https://images.squarespace-cdn.com/content/v1/55f62c4ce4b02545cc6ee94f/1558204823259-CQ0YNKZEHP7W5LO64PBU/paypal-donate-button-1.PNG?format=300w)](https://paypal.me/ravgeetdhillon) +A Node.js app for creating a Feed Reader in [Notion](https://notion.so). -*** +![](/screenshots/working.gif) ## Features @@ -46,7 +46,7 @@ Different views of accessing Unread, Starred feed items. 2. Duplicate this [template](https://ravsamhq.notion.site/Feeder-fa2aa54827fa42c2af1eb25c7a45a408) to your Notion workspace. -3. Once the template is available on your Notion Workspace, open the **Reader** database. Click the three-button page menu in the top right corner **...** *> Add connections* and search the Notion integration you created in Step 1 and Click **Invite**. Do the same for the **Feeds** database. +3. Once the template is available on your Notion Workspace, open the **Reader** database. Click the three-button page menu in the top right corner **...** _> Add connections_ and search the Notion integration you created in Step 1 and Click **Invite**. Do the same for the **Feeds** database. 4. Fork this GitHub repository and once forking is complete, go to your forked GitHub repository. @@ -54,17 +54,21 @@ Different views of accessing Unread, Starred feed items. 6. Click on the **Get Feed** action in the left panel and then click "Enable workflow". -7. Go to *Settings > Secrets*. Add the following three secrets along with their values as **Repository secrets**. +7. Go to _Settings > Secrets_. Add the following three secrets along with their values as **Repository secrets**. + ``` NOTION_API_TOKEN NOTION_READER_DATABASE_ID NOTION_FEEDS_DATABASE_ID ``` - > To find your database id, visit your database on Notion. You'll get a URL like this: https://www.notion.so/{workspace_name}/{database_id}?v={view_id}. For example, if your URL looks like this: https://www.notion.so/abc/xyz?v=123, then `xyz` is your database ID. + + > To find your database id, visit your database on Notion. You'll get a URL like this: https://www.notion.so/{workspace_name}/{database_id}?v={view_id}. For example, if your URL looks like this: https://www.notion.so/abc/xyz?v=123, then `xyz` is your database ID. 8. Delete the [release workflow file](.github/workflows/release.yml) as it is only required in the original repository. -That's it. Now every day, your feed will be updated at 12:30 UTC. You can change the time at which the script runs from [here](.github/workflows/main.yml#L5). +9. That's it. Now every day, your feed will be updated at 12:30 UTC. + +**Note**: You can change the time at which the script runs from [here](.github/workflows/main.yml#L5) and the frequency of running from [here](.github/workflows/main.yml#L15). ## Development @@ -98,8 +102,8 @@ $ npm run watch ## Tech Stack -* [Node](https://nodejs.org/) -* [Notion API](https://developers.notion.com) +- [Node](https://nodejs.org/) +- [Notion API](https://developers.notion.com) ## Contributors diff --git a/src/feed.js b/src/feed.js index 203d91aa..fdd614fd 100644 --- a/src/feed.js +++ b/src/feed.js @@ -1,7 +1,12 @@ import Parser from 'rss-parser'; +import dotenv from 'dotenv'; import timeDifference from './helpers'; import { getFeedUrlsFromNotion } from './notion'; +dotenv.config(); + +const { RUN_FREQUENCY } = process.env; + async function getNewFeedItemsFrom(feedUrl) { const parser = new Parser(); let rss; @@ -11,11 +16,13 @@ async function getNewFeedItemsFrom(feedUrl) { console.error(error); return []; } - const todaysDate = new Date().getTime() / 1000; + const currentTime = new Date().getTime() / 1000; + + // Filter out items that fall in the run frequency range return rss.items.filter((item) => { - const blogPublishedDate = new Date(item.pubDate).getTime() / 1000; - const { diffInDays } = timeDifference(todaysDate, blogPublishedDate); - return diffInDays === 0; + const blogPublishedTime = new Date(item.pubDate).getTime() / 1000; + const { diffInSeconds } = timeDifference(currentTime, blogPublishedTime); + return diffInSeconds < RUN_FREQUENCY; }); }