Skip to content

Commit

Permalink
v0.02 init commit mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
davzoku committed Aug 3, 2022
1 parent bc9a989 commit a671caf
Show file tree
Hide file tree
Showing 5 changed files with 6,710 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RSS_URL=https://walterteng.com/rss.xml
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": ["wesbos"] }
30 changes: 30 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env node
import chalk from 'chalk';
import * as dotenv from 'dotenv';
import { createSpinner } from 'nanospinner';
import path from 'path';
import RSSParser from 'rss-parser';

const __dirname = path.resolve();
dotenv.config({ path: `${__dirname}/./.env` });

const rssUrl = process.env.RSS_URL;

async function getLatestPosts(url, count) {
const spinner = createSpinner(`Fetching ${count} latest posts`).start();
const posts = await new RSSParser().parseURL(url);

// console.log(posts.items);
for (let i = 0; i < count; i++) {
console.log(
`\n#${chalk.dim(i + 1)} - ${chalk.bold.blueBright(
posts.items[i].title
)} - ${chalk.underline(posts.items[i].link)}\n${chalk.italic(
posts.items[i].contentSnippet
)}\n${chalk.dim(posts.items[i].isoDate.substring(0, 10))}`
);
}
spinner.success({ text: `Fetched ${count} latest posts, Enjoy~!` });
}

getLatestPosts(rssUrl, 10);
Loading

0 comments on commit a671caf

Please sign in to comment.