Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
322 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
tmp | ||
tmp | ||
db/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Watchtower | ||
module Beam | ||
def self.poll(beam) | ||
results = [] | ||
beam.new.results.each do |result| | ||
existing = BEAMS.find('unique' => result['unique']).first | ||
if !existing | ||
self.save(result) | ||
results << result | ||
end | ||
end | ||
results | ||
end | ||
|
||
def self.poll_all | ||
self.poll(Beam::HackerNews) | ||
self.poll(Beam::Twitter) | ||
end | ||
|
||
def self.save(object) | ||
BEAMS.insert(object.merge({ 'created_at' => Time.now})) | ||
end | ||
|
||
# Returns all Needles. Can be passed an options hash | ||
# :sort - An array of [ field, order ] pairs | ||
# :limit - How many results to return | ||
def self.all(options = {}) | ||
default_options = { | ||
:sort => [['created_at', 'descending']], | ||
:limit => 100 | ||
} | ||
|
||
BEAMS.find({}, default_options.merge(options)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Watchtower | ||
module Beam | ||
class HackerNews | ||
def initialize | ||
@stories_document = Nokogiri::HTML(open('http://news.ycombinator.com')) | ||
|
||
@results = self.find_github_stories | ||
end | ||
|
||
def find_github_stories | ||
stories = [] | ||
@stories_document.css('tr').each do |row| | ||
link = row.css('td.title a').first | ||
if link && (link['href'].downcase =~ (/github/) || link.content.downcase =~ (/github/)) | ||
author, author_url, comments, hn_url, points = "?" | ||
|
||
meta_row = row.next | ||
meta_row.css('td.subtext span').each do |span| | ||
points = span.content.match(/(.*?) points/)[1] if span.content =~ /(.*?) point/ | ||
end | ||
meta_row.css('td.subtext a').each do |inner_link| | ||
if inner_link['href'] =~ /^user(.*)/ | ||
author = inner_link.content | ||
author_url = 'http://news.ycombinator.com' + inner_link['href'] | ||
end | ||
if inner_link.content.downcase =~ /(.*?) comment/ | ||
comments = inner_link.content.downcase.match(/(.*?) comment/)[1] | ||
hn_url = 'http://news.ycombinator.com' + inner_link['href'] | ||
end | ||
end | ||
|
||
stories << { | ||
'unique' => Digest::SHA1.hexdigest(link['href']), | ||
'service' => 'Hacker News', | ||
'body' => link.content, | ||
'story_url' => link['href'], | ||
'author' => author, | ||
'author_url' => author_url, | ||
'comments' => comments, | ||
'points' => points | ||
} | ||
end | ||
end | ||
stories | ||
end | ||
|
||
def results | ||
@results || [] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Watchtower | ||
module Beam | ||
class Twitter | ||
def initialize | ||
@tweets_document = Nokogiri::HTML(open('http://search.twitter.com/search.atom?q=github')) | ||
|
||
@results = self.find_github_tweets | ||
end | ||
|
||
def find_github_tweets | ||
tweets = [] | ||
@tweets_document.css('entry').each do |entry| | ||
body = entry.css('title').first.content | ||
author_url = entry.css('author uri').first.content | ||
author = author_url.match(/twitter.com\/(.*?)$/)[1] | ||
tweet_url = entry.css('link').first['href'] | ||
tweets << { | ||
'unique' => Digest::SHA1.hexdigest(tweet_url), | ||
'service' => 'Twitter', | ||
'body' => body, | ||
'author' => '@' + author, | ||
'author_url' => author_url, | ||
'tweet_url' => tweet_url | ||
} | ||
end | ||
tweets | ||
end | ||
|
||
def results | ||
@results || [] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h1>All Events</h1> | ||
|
||
<ul class="events"> | ||
{{# beams }} | ||
<li class="event {{ service_short }}"> | ||
<div class="inner"> | ||
<div class="meta"> | ||
<span class="icon"></span> | ||
<h3><a href="{{ author_url }}">{{ author }}</a> <span class="sep">—</span> {{ created_at }}</h3> | ||
<ul class="actions"> | ||
{{# actions }} | ||
<li><a href="{{ url }}">{{ name }}</a></li> | ||
{{/ actions }} | ||
</ul> | ||
</div> | ||
<p>{{{ body }}}</p> | ||
</div> | ||
</li><!-- /.event --> | ||
{{/ beams }} | ||
</ul> |
Oops, something went wrong.