Skip to content

Commit

Permalink
invalidating avatars that don't exist on HN
Browse files Browse the repository at this point in the history
  • Loading branch information
dkeskar committed Sep 9, 2010
1 parent 628192d commit 5830f78
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions application.rb
Expand Up @@ -83,8 +83,9 @@
case params[:format]
when :json, 'json'
ret = {:success => (!@stream.nil? && !@activity.nil?)}
ret[:stream_id] = @stream ? @stream.sid : params[:stream_id]
ret[:id] = @stream.id if @stream
ret[:stream_id] = @stream.sid
ret[:id] = @stream.id
ret[:status] = @stream.status
ret[:activity] = @activity || []
jsonp ret
else
Expand Down
1 change: 1 addition & 0 deletions lib/avatar.rb
Expand Up @@ -6,6 +6,7 @@ class Avatar
key :since, Integer
key :watch, Boolean
key :nwx, Integer, :default => 0
key :valid, Boolean, :default => true

has_many :postings
has_many :comments
Expand Down
6 changes: 5 additions & 1 deletion lib/discussion.rb
Expand Up @@ -24,7 +24,11 @@ def process_page
tracked_pid = nil
uppers = {}

@doc.search("td.default").each_with_index do |cmt, ix|
entries = @doc.search("td.default")
if entries.empty? and @doc.inner_html =~ /no such user/i
@avatar.set(:valid => false)
end
entries.each_with_index do |cmt, ix|
text = cmt.search("span.comment/font").inner_html
info = cmt.search("div/span.comhead")
html = info.inner_html
Expand Down
4 changes: 4 additions & 0 deletions lib/hacker_news.rb
Expand Up @@ -33,6 +33,10 @@ def self.stats
def refresh_watchlist
thread = Discussion.new(CMT_URL)
Avatar.watched.each do |user|
if not user.valid
# suspend streams that watch this user and mark them invalid
# That should automatically decrement avatar.nwx
end
thread.user = user
thread.crawl
end
Expand Down
1 change: 1 addition & 0 deletions lib/stream.rb
Expand Up @@ -13,6 +13,7 @@ class Stream
key :config, Hash
key :_type, String
key :cache, Hash # cache config in effect
key :status, String, :default => "Active"

def self.activity(sid)
me = Stream.where(:sid => sid).load
Expand Down

0 comments on commit 5830f78

Please sign in to comment.