Created
February 24, 2010 06:52
-
-
Save kossnocorp/313188 to your computer and use it in GitHub Desktop.
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
| #!/opt/ruby-enterprise-1.8.7-2010.01/bin/ruby | |
| require 'rubygems' | |
| require 'json' | |
| require 'net/http' | |
| TOKEN = 'YOU_TOKEN' | |
| PROJECTS = [ | |
| ] | |
| time_from = Date.parse 'DATE_FROM, FOR EXAMPLE: 2010-02-15' | |
| time_to = Date.parse 'DATE_FROM, FOR EXAMPLE: 2010-02-21' | |
| puts <<EOF | |
| ╭ ━━━━━━━━━━━━━━━━━━━ ━━━━━━━━━━━━━━━━━━━ ╮ | |
| ┃ freckle exporter ┃ | |
| ┃ ^___^ ┃ | |
| ╰ ━━━━━━━━━━━━━━━━━━━ ━━━━━━━━━━━━━━━━━━━ ╯ | |
| — Today is #{Time.now.strftime("%d.%m.%y")} | |
| — You want to catcha #{time_from.strftime("%d.%m.%y")} - #{time_to.strftime("%d.%m.%y")} | |
| Ok, I got it! | |
| Thinking, plese leave me alone for few seconds... | |
| EOF | |
| response = Net::HTTP.get \ | |
| 'SUBDOMAIN.letsfreckle.com', | |
| "/api/entries.json?token=#{TOKEN}" | |
| entries = JSON.parse response | |
| timelog = entries.collect do |entry| | |
| entry_hash = { | |
| :date => Date.parse(entry['entry']['date']), | |
| :hours => entry['entry']['minutes'].to_i / 60.0, | |
| :description => entry['entry']['description'] | |
| } | |
| if entry_hash[:date] < time_from or entry_hash[:date] > time_to | |
| nil | |
| else | |
| entry_hash | |
| end | |
| end | |
| timelog.compact! | |
| timelog.sort! { |a, b| a[:date] <=> b[:date] } | |
| puts "\n#{'-' * 44}\n\n" | |
| timelog.each do |log| | |
| # puts entry[:date] | |
| puts "#{log[:date].strftime("%m/%d/%y")}\t#{log[:hours]}\t#{log[:description]}" #.inspect | |
| # puts '-' * 20 | |
| end | |
| puts "\n#{'-' * 44}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment