-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.rb
72 lines (63 loc) · 1.44 KB
/
index.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'sinatra'
require 'aws-sdk-core'
require 'json'
get "/" do
erb :index
end
get "/:ticker?.:format?" do
dynamodb = Aws::DynamoDB::Client.new(
region: 'us-east-1',
credentials: Aws::Credentials.new('AKIAI6PU7IIGNUBSI26A', 'qBrlCJMywo029GlaXsLVI8Rf4286eWsC6aU+ue53')
)
@data = dynamodb.query({
:table_name => "Catalog",
:consistent_read => true,
:select => 'ALL_ATTRIBUTES',
:key_conditions => {
'Ticker' => {
:comparison_operator => 'EQ',
:attribute_value_list => [
params["ticker"]
]
}
}
})
if params['format'] == "json"
content_type :json
@data.items.to_json
end
end
get "/:year/:ticker?.:format?" do
dynamodb = Aws::DynamoDB::Client.new(
region: 'us-east-1',
credentials: Aws::Credentials.new('AKIAI6PU7IIGNUBSI26A', 'qBrlCJMywo029GlaXsLVI8Rf4286eWsC6aU+ue53')
)
@data = dynamodb.query({
:table_name => params["year"],
:consistent_read => true,
:select => 'ALL_ATTRIBUTES',
:key_conditions => {
'Ticker' => {
:comparison_operator => 'EQ',
:attribute_value_list => [
params["ticker"] + " Index"
],
},
'Date' => {
:comparison_operator => 'BETWEEN',
:attribute_value_list => [
params["year"]+'-01-01', params["year"]+'-12-31'
]
}
}
})
if params['format'] == "json"
content_type :json
@data.items.to_json
else
erb :view
end
end
get "/migrateToParse" do
File.read('transferToParse.html')
end