A program to read a Phidget IR sensor and log pull-ups with Fitbit's API
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add countinual logger

+42
+42
lib/logger/countinual.rb
··· 1 + require "socket" 2 + 3 + class Countinual < Loggerish 4 + COUNTINUAL_HOST = "api.countinual.com" 5 + COUNTINUAL_PORT = 1025 6 + 7 + def self.args 8 + [ 9 + [ "--countinual-key", "-k", GetoptLong::REQUIRED_ARGUMENT, 10 + "log to a Countinual account (API key)" ], 11 + [ "--countinual-counter", "-c", GetoptLong::REQUIRED_ARGUMENT, 12 + "Countinual counter (default is \"pullups\"" ], 13 + ] 14 + end 15 + 16 + def after_initialize 17 + if @enabled = !!@parent.config["countinual-key"] 18 + @parent.vputs "enabling Countinual logging module" 19 + 20 + if !@parent.config["countinual-counter"] 21 + @parent.config["countinual-counter"] = "pullups" 22 + end 23 + end 24 + end 25 + 26 + def log_pullup!(time) 27 + line = [ 28 + @parent.config["countinual-key"], 29 + @parent.config["countinual-counter"], 30 + time.to_i, 31 + "+1", 32 + ].join(" ") + "\n" 33 + 34 + begin 35 + sock = UDPSocket.open 36 + sock.send(line, 0, COUNTINUAL_HOST, COUNTINUAL_PORT) 37 + @parent.vputs "logged pullup on countinual" 38 + rescue => e 39 + Rails.logger.info "Countinual error: #{e.message} (#{line.inspect})" 40 + end 41 + end 42 + end