Leave myself more breadcrumbs

This commit is contained in:
Dan Buch 2015-10-04 18:41:08 -04:00
parent 20cddd116b
commit 23e4f02538
8 changed files with 121 additions and 14 deletions

4
.rubocop.yml Normal file
View File

@ -0,0 +1,4 @@
inherit_from: .rubocop_todo.yml
Style/Documentation:
Enabled: false

7
.rubocop_todo.yml Normal file
View File

@ -0,0 +1,7 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-10-04 18:16:18 -0400 using RuboCop version 0.34.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

View File

@ -1,8 +1,8 @@
source 'https://rubygems.org' source 'https://rubygems.org'
ruby '2.2.2' if ENV.key?('DYNO') ruby '2.2.3' if ENV.key?('DYNO')
gem 'aws-sdk', '~> 2' gem 'aws-sdk', '~> 2'
gem 'pry', group: [:development, :test] gem 'pry', group: %i(development test)
gem 'puma'
gem 'rack' gem 'rack'
gem 'rubocop', group: %i(development test)

View File

@ -1,6 +1,9 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
ast (2.1.0)
astrolabe (1.3.1)
parser (~> 2.2)
aws-sdk (2.1.20) aws-sdk (2.1.20)
aws-sdk-resources (= 2.1.20) aws-sdk-resources (= 2.1.20)
aws-sdk-core (2.1.20) aws-sdk-core (2.1.20)
@ -12,12 +15,22 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
method_source (0.8.2) method_source (0.8.2)
multi_json (1.11.2) multi_json (1.11.2)
parser (2.2.2.6)
ast (>= 1.1, < 3.0)
powerpack (0.1.1)
pry (0.10.1) pry (0.10.1)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
slop (~> 3.4) slop (~> 3.4)
puma (2.13.4)
rack (1.6.4) rack (1.6.4)
rainbow (2.0.0)
rubocop (0.34.2)
astrolabe (~> 1.3)
parser (>= 2.2.2.5, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.7.5)
slop (3.6.0) slop (3.6.0)
PLATFORMS PLATFORMS
@ -26,8 +39,8 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
aws-sdk (~> 2) aws-sdk (~> 2)
pry pry
puma
rack rack
rubocop
BUNDLED WITH BUNDLED WITH
1.10.6 1.10.6

View File

@ -2,3 +2,20 @@
Transforms [this](http://api.bls.gov/publicAPI/v2/timeseries/data/CUUSA210SA0) Transforms [this](http://api.bls.gov/publicAPI/v2/timeseries/data/CUUSA210SA0)
into [this](http://s3.amazonaws.com/meatballhat/cpi/current.csv) :tada:. into [this](http://s3.amazonaws.com/meatballhat/cpi/current.csv) :tada:.
## usage
This is intended for use with Google Sheets via:
```
=IMPORTDATA("http://s3.amazonaws.com/meatballhat/cpi/current.csv")
```
## deployment
A copy of this thing is deployed to Heroku with a Heroku Scheduler addon
configured to run the following once daily:
``` bash
bundle exec ruby cpi_fetcher.rb | bundle exec ruby mini_s3put.rb
```

View File

@ -1 +1 @@
run lambda { |env| [301, { 'Location' => ENV['CPI_FEED_URL'] }, []] } run ->(*) { [301, { 'Location' => ENV['CPI_FEED_URL'] }, []] }

View File

@ -31,3 +31,64 @@ if $PROGRAM_NAME == __FILE__
puts CPIFetcher.new.cpi puts CPIFetcher.new.cpi
exit 0 exit 0
end end
__END__
{
"status": "REQUEST_SUCCEEDED",
"responseTime": 36,
"message": [],
"Results": {
"series": [
{
"seriesID": "CUUSA210SA0",
"data": [
{
"year": "2015",
"period": "S01",
"periodName": "1st Half",
"value": "220.381",
"footnotes": [
{}
]
},
{
"year": "2014",
"period": "S02",
"periodName": "2nd Half",
"value": "220.891",
"footnotes": [
{}
]
},
{
"year": "2014",
"period": "S01",
"periodName": "1st Half",
"value": "220.352",
"footnotes": [
{}
]
},
{
"year": "2013",
"period": "S02",
"periodName": "2nd Half",
"value": "217.983",
"footnotes": [
{}
]
},
{
"year": "2013",
"period": "S01",
"periodName": "1st Half",
"value": "216.941",
"footnotes": [
{}
]
}
]
}
]
}
}

View File

@ -1,12 +1,17 @@
require 'aws-sdk' require 'aws-sdk'
bucket = ENV.fetch('CPI_FEED_AWS_BUCKET') def main
key = ARGV.first || ENV.fetch('CPI_FEED_AWS_KEY') bucket = ENV.fetch('CPI_FEED_AWS_BUCKET')
key = ARGV.first || ENV.fetch('CPI_FEED_AWS_KEY')
puts Aws::S3::Resource.new.bucket(bucket).object(key).put( puts Aws::S3::Resource.new.bucket(bucket).object(key).put(
body: $stdin.read body: $stdin.read
) )
puts Aws::S3::Client.new.put_object_acl( puts Aws::S3::Client.new.put_object_acl(
bucket: bucket, key: key, acl: 'public-read' bucket: bucket, key: key, acl: 'public-read'
) )
0
end
exit(main) if $PROGRAM_NAME == __FILE__