A simple Ruby script to be alerted by email whenever one specific keyword is mentioned on YCombinator Hacker News (not just on the front page). By design this script covers the frontpage, the new submitted articles and comments. For hosted service and more features see HNWatcher.
The code is based on the hnsearch API / ThriftDB Search API
Modify the file alert_hackernews.rb & configure your database as follow. Then add the script to the cron jobs. And wait for alerts :)
Update the file alert_hackernews.rb, line 10
look_for = 'docker'
Update the file alert_hackernews.rb from line 14 to 16
email_from = 'your@email_from.io'
email_to = 'your@email_to.com'
email_title = "New mention of #{look_for} on HN"
Create the MySQL database and add the table from the mysql.db script file
CREATE TABLE `logs` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_hn` int(11) NOT NULL,
`id_parent_hn` int(11) DEFAULT NULL,
`create_ts` date NOT NULL,
`type` enum('SUBMISSION','COMMENT') NOT NULL DEFAULT 'SUBMISSION',
`title` varchar(1024) DEFAULT NULL,
`url` varchar(1024) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8;
Update the file alert_hackernews with the right credentials (lines 11-12-13)
db_db = 'hn_alert'
db_username = 'mdm'
db_password = 'charmes_g'
Add the script as a cron job with the frequency you want it to check for your keyword on HackerNews
Be free to use the code and improve it to:
- add more than one keyword (being able to monitor several keywords on HackerNews)
- add more than one email to be alerted
- add more information (usernames, points, ...)
- add a back office to list all mentionned on HackerNews (from the database)
- add a back office option to manage the keywords and the emails for each keyword
If you have any questions, feel free ton contact me on twitter
For hosted service and more features see HNWatcher.
Have fun!