Skip to content

Commit

Permalink
feat: allow users to run action mroe frequently without adding duplic…
Browse files Browse the repository at this point in the history
…ate entries
  • Loading branch information
ravgeetdhillon committed Jun 2, 2023
1 parent 03cc98f commit 9fd3ca6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NOTION_API_TOKEN=
NOTION_READER_DATABASE_ID=
NOTION_FEEDS_DATABASE_ID=
RUN_FREQUENCY=86400 # in seconds
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Get Feed

on:
schedule:
- cron: "30 12 * * *" # 6pm IST
- cron: '30 12 * * *' # 6pm IST
workflow_dispatch:

jobs:
Expand All @@ -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
Expand Down
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

<a href="https://www.producthunt.com/posts/notion-feeder?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-notion-feeder" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=316289&theme=light" alt="Notion Feeder - Convert Notion to a Feed Reader | Product Hunt" style="width: 166px; height: 36px;" width="166" height="36" /></a>

# 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

Expand Down Expand Up @@ -46,25 +46,29 @@ 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.

5. Enable the GitHub Actions by visiting the **Actions** tab and click "I understand my workflows, enable them".

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

Expand Down Expand Up @@ -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

Expand Down
15 changes: 11 additions & 4 deletions src/feed.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
});
}

Expand Down

0 comments on commit 9fd3ca6

Please sign in to comment.