Skip to content

Commit

Permalink
initial codes of the application
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardakilic committed May 1, 2018
1 parent f03affa commit b155b99
Show file tree
Hide file tree
Showing 8 changed files with 2,277 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
# editorconfig-tools is unable to ignore longs strings or urls
max_line_length = null
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": [
"airbnb-base"
],
"env": {
"node": true
},
"parserOptions": {
"sourceType": "module"
},
"rules": {
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "ignore"
}
]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ typings/
# dotenv environment variables file
.env

# App-spesific
config.js
36 changes: 36 additions & 0 deletions config.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
interval: 6000, // Feed check interval
notifications: {
pushbullet: {
enabled: false,
accessToken: 'XXX',
},
smtp: {
enabled: true,
config: { // Nodemailer configuration
host: 'smtp.service.com',
port: 465,
secure: true,
auth: {
user: 'smtp@user.com',
pass: 'password',
},
},
// tls: true,
mailOptions: {
from: '"AlertHub" <smtp@user.com>', // from field, can be pure e-mail or "Name" <e-mail> format
to: 'your@email.com', // Your Email, can add more e-mails by commas
subjectPrefix: 'New Release', // Subject prefix
},
},
},
repositories: [
'ardakilic/alerthub', // can be resolved as https://github.com/ardakilic/alerthub
'expressjs/express',
'Unitech/pm2',
'facebook/react',
],
extras: [
// direct rss links from other sources if you want to watch in this tool
],
};
55 changes: 55 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// First, let's require the libraries
const config = require('./config');
const utils = require('./utils');
const RssFeedEmitter = require('rss-feed-emitter');

// RSS Feed emitter to watch and parse feed
const feeder = new RssFeedEmitter();

const bootTime = new Date();
console.log(`Application booted at ${bootTime}`);

// First, let's add all the feed lists
config.repositories.forEach((feed) => {
feeder.add({
url: `https://github.com/${feed}/releases.atom`,
refresh: config.interval,
});
});

config.extras.forEach((feed) => {
feeder.add({
url: feed,
refresh: config.interval,
});
});


feeder.add({
url: 'https://lorem-rss.herokuapp.com/feed?unit=second&interval=10',
refresh: 2000,
});

feeder.on('new-item', async (item) => {
console.log(`New item! ${item.title}!`);

// console.log(item);
// Past (Current) feeds are also pushed to feed on initial boot
// This may cause serious notification/mail spam after a possible crash
// That's why we make a simple time check to make sure feeds are new

const date = new Date(item.date);
// Let's compare the dates and make sure the feed a new feed.
if (date.getTime() > bootTime.getTime()) {
const feedData = utils.parseFeedData(item);
// First, try to send the push notification
await utils.sendPushNotification(config, feedData);

// Now try to send the email
await utils.sendEmailNotification(config, feedData);

console.log('Successfully notified about the feed!');

}
});

Loading

0 comments on commit b155b99

Please sign in to comment.