Skip to content

Commit

Permalink
storing ids
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbuddy committed Jan 4, 2010
1 parent d083f62 commit b8b86b2
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions lib/messed/interface/adapter/twitter_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def build_query
end

def start
@ids ||= []
@ids ||= default_ids
# do work.
begin
query = build_query
Expand Down Expand Up @@ -51,12 +51,39 @@ def start
end
end

def id_retention_count
interface.configuration.options[:id_retention_size] || 500
end

def trim_ids
while @ids.size > 500
while @ids.size > id_retention_count
@ids.shift
end
end

def store_ids?
id_retention_file
end

def write_ids
File.open(id_retention_file, 'w') { |f| f << @ids.to_json }
end

def read_ids
@ids = JSON.parse(File.read(id_retention_file))
end

def default_ids
store_ids? ? read_ids : []
rescue
logger.error "Twitter Search: Unable to load ids from #{id_retention_file.inspect}"
[]
end

def id_retention_file
interface.configuration.options[:id_retention_tmp_file]
end

def result_to_message(result)
unless @test_set.include?(result['id'])
message = Message::Twitter.new do |m|
Expand Down

0 comments on commit b8b86b2

Please sign in to comment.