tsp_scraper 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tsp_scraper/client.rb +8 -9
- data/lib/tsp_scraper/converter.rb +2 -8
- data/lib/tsp_scraper/version.rb +1 -1
- data/tsp_scraper.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06f326a47003377a09a52f6a6943355119373cfd73740f645a7e91f7f4583a91
|
4
|
+
data.tar.gz: 0e8f2a09436a87940f7b7fc66b7243d8c4c0b28e88b32e72ebf984b283c28237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 397fa873097f209732982fcdf156b2062e240aaf71ea53470861fca6e6a56715aa2b257099b825a1aa28438fa3206ab4fb775ad81b74eadbe136271dabc12540
|
7
|
+
data.tar.gz: 342ccc4844395e03c838d88fdcc79bf1bbe139406228cb7304738e720f9311cc6f7edd47e1915d16a8a4e32f3a78f806be6cd7a66881ec484858d99ade698805
|
data/lib/tsp_scraper/client.rb
CHANGED
@@ -4,22 +4,21 @@ module TSPScraper
|
|
4
4
|
class Client
|
5
5
|
include HTTParty
|
6
6
|
disable_rails_query_string_format
|
7
|
-
base_uri "https://
|
7
|
+
base_uri "https://secure.tsp.gov/components/CORS"
|
8
8
|
|
9
9
|
def self.scrape_raw(start_date = Date.today.prev_month, end_date = Date.today, options = {})
|
10
|
-
funds = ["Linc", "L2010", "L2020", "L2030", "L2040", "L2050", "G", "F", "C", "S", "I"]
|
11
10
|
default_options = {
|
12
11
|
query: {
|
13
|
-
|
14
|
-
startdate: start_date.strftime("%m
|
15
|
-
enddate: end_date.strftime("%m
|
16
|
-
|
17
|
-
|
12
|
+
download: 1,
|
13
|
+
startdate: start_date.strftime("%Y%m%d"),
|
14
|
+
enddate: end_date.strftime("%Y%m%d"),
|
15
|
+
format: "CSV",
|
16
|
+
Lfunds: 1,
|
17
|
+
InvFunds: 1
|
18
18
|
}
|
19
19
|
}
|
20
20
|
options = default_options.merge(options)
|
21
|
-
|
22
|
-
response = self.get("/index.html", options)
|
21
|
+
response = self.get("/getSharePrices.html", options)
|
23
22
|
response.body.strip
|
24
23
|
end
|
25
24
|
|
@@ -2,11 +2,10 @@ module TSPScraper
|
|
2
2
|
class Converter
|
3
3
|
# TSP CSV has a janky format:
|
4
4
|
# - Each field in a row, except for the first field, is prepended by a space
|
5
|
-
# - Each row has a final column containing just a space
|
6
5
|
# For this reason, we manually clean up the CSV instead of using the Ruby CSV library, especially since we know TSP
|
7
6
|
# does not use quotation marks in their CSV fields... at least for now.
|
8
7
|
def self.raw_csv_to_hash(raw_csv)
|
9
|
-
raw_data = raw_csv.lines.map { |row| row.strip.
|
8
|
+
raw_data = raw_csv.lines.map { |row| row.strip.split(',').map { |field| field.strip } }
|
10
9
|
headers = raw_data.shift
|
11
10
|
data = []
|
12
11
|
raw_data.each do |d|
|
@@ -16,12 +15,7 @@ module TSPScraper
|
|
16
15
|
}
|
17
16
|
headers.each_with_index do |header, index|
|
18
17
|
next if index == 0
|
19
|
-
|
20
|
-
value = nil
|
21
|
-
else
|
22
|
-
value = BigDecimal(d[index])
|
23
|
-
end
|
24
|
-
hash[:funds][header] = value
|
18
|
+
hash[:funds][header] = BigDecimal(d[index]) unless d[index].empty?
|
25
19
|
end
|
26
20
|
data.push(hash)
|
27
21
|
end
|
data/lib/tsp_scraper/version.rb
CHANGED
data/tsp_scraper.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = ['tsp_scraper']
|
18
18
|
|
19
19
|
s.add_runtime_dependency 'httparty', '~> 0.17.1'
|
20
|
-
s.add_development_dependency 'bundler', '~> 2.
|
20
|
+
s.add_development_dependency 'bundler', '~> 2.1.4'
|
21
21
|
s.add_development_dependency 'rake', '~> 13.0.0'
|
22
22
|
s.add_development_dependency 'pry', '~> 0.12.2'
|
23
23
|
s.add_development_dependency 'minitest', '~> 5.12.2'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tsp_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Fredrickson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
33
|
+
version: 2.1.4
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.
|
40
|
+
version: 2.1.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,7 +107,7 @@ homepage: https://github.com/jfredrickson/tsp_scraper
|
|
107
107
|
licenses:
|
108
108
|
- MIT
|
109
109
|
metadata: {}
|
110
|
-
post_install_message:
|
110
|
+
post_install_message:
|
111
111
|
rdoc_options: []
|
112
112
|
require_paths:
|
113
113
|
- lib
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubygems_version: 3.0.3
|
126
|
-
signing_key:
|
126
|
+
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Scrapes fund price history from the TSP.gov website
|
129
129
|
test_files: []
|