-
-
Save lukaszkorecki/2164949 to your computer and use it in GitHub Desktop.
file_notifier.rb
This file contains hidden or 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
# 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