Skip to content

Instantly share code, notes, and snippets.

@lukaszkorecki
Forked from jugyo/event_notifier.rb
Created March 22, 2012 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaszkorecki/2164949 to your computer and use it in GitHub Desktop.
Save lukaszkorecki/2164949 to your computer and use it in GitHub Desktop.
file_notifier.rb
# Writes number of "unread" tweets to a file
# so that it can be used in tmux' status bar, like so:
#
# tail -1 ~/.earthquake_count
#
# You can reset the counter with :reset_count command
class NotiFile
def initialize file_path
log "new NotiFile"
@file = File.expand_path file_path
@count = -1 # XXX
update_count
end
def update_count
log 'updating ocunt'
@count += 1
save_count
end
def reset
log 'reseting'
@count = 0
save_count
end
def log(str)
File.open(File.expand_path("~/.earthquake/fn.log"), "w") do |f|
f.write "#{str}\n"
end
end
private
def save_count
log 'saving file with ' + @count.to_s
File.open(@file, 'a') { |f| f.write "#{@count}\n"}
end
end
__notififle = NotiFile.new "~/.earthquake_count"
Earthquake.init do
output do |item|
if item["source"] && item['source']['screen_name'] && item["source"]["screen_name"] != twitter.info["screen_name"]
__notififle.log 'yo'
__notififle.update_count
end
end
command :reset_count do
__notififle.reset
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment