barchart_data 0.1.1 → 0.1.2
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/.gitignore +2 -0
- data/README.md +17 -1
- data/barchart_data-0.1.1.gem +0 -0
- data/barchart_data.gemspec +10 -7
- data/bin/barchart_data +30 -7
- data/lib/barchart_data.rb +4 -4
- data/lib/barchart_data/version.rb +1 -1
- data/lib/barchart_scripts/barchart_connection.rb +16 -0
- data/lib/barchart_scripts/scrape_new_highs_new_lows.rb +76 -0
- data/lib/barchart_scripts/scraper.rb +37 -0
- data/lib/generators/barchart_data/install/install_generator.rb +3 -2
- data/lib/generators/barchart_data/install/templates/highlow_migration.rb +2 -0
- metadata +82 -22
- data/lib/barchart_data/alltimehigh.rb +0 -30
- data/lib/barchart_data/high_low_scraper.rb +0 -56
- data/lib/barchart_data/newhigh.rb +0 -30
- data/lib/barchart_data/scraper.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a650e81ec1da0f0464f7ca67e29a4e968ee5d5e8
|
4
|
+
data.tar.gz: d66ab9f7f81445f1e75ff37a7e7eead4b9f34fa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2264434c8ae67a12e6357090d516aaa2c893ccc79e5b1bac69a83d3e5a9b4103a7c949991b7f4379dc95b4659f5cc59e0282319d346916a84e08d1ff3b9bfb64
|
7
|
+
data.tar.gz: f4cb381853ead748af91b79a7c15ea7df4eae021fbe3a77d31badea19c9eab99a2c6800abc7ad64116d0bc43955a999cf0f2b005238df116e9f18366ceda0019
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
### UPDATE:
|
2
|
+
Version(0.1.2) released. Modification to schema so will break previous version. URLs work with old.barchart.com. Working on updating to current site specifics.
|
3
|
+
|
4
|
+
### ALERT:
|
5
|
+
|
6
|
+
Recently it has come to my attention that this gem is broken as there has been a major over haul to Barchart.
|
7
|
+
|
8
|
+
Links in the following format are now invalid: http://www.barchart.com/stocks/athigh.php?_dtp1-0
|
9
|
+
|
10
|
+
Links in the following format are currently active http://old.barchart.com/stocks/athigh.php?_dtp1-0
|
11
|
+
|
12
|
+
I'm currently working on cleaning up this gem's codebase for an update with the new urls.
|
13
|
+
|
14
|
+
Applies to version **(0.1.1)**
|
15
|
+
|
16
|
+
|
1
17
|
# BarchartData
|
2
18
|
|
3
19
|
**BarchartData:** Screen Scrape Utility to grab and persist stock releated data from the site Barcharts.com Current implemenation extracts:
|
@@ -8,7 +24,7 @@
|
|
8
24
|
* 52-Week Lows
|
9
25
|
* New Highs, New Lows
|
10
26
|
|
11
|
-
Version (0.1.
|
27
|
+
Version (0.1.2) This project is still in its infancy and will be heavily modified over time.
|
12
28
|
|
13
29
|
## Installation
|
14
30
|
|
Binary file
|
data/barchart_data.gemspec
CHANGED
@@ -27,11 +27,14 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_development_dependency "bundler", "~> 1.
|
31
|
-
spec.add_development_dependency "rake", "~>
|
32
|
-
spec.add_development_dependency '
|
33
|
-
spec.add_development_dependency 'sqlite3', '~> 1.3.
|
34
|
-
spec.
|
35
|
-
spec.
|
36
|
-
spec.
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12.4"
|
31
|
+
spec.add_development_dependency "rake", "~> 11.3.0"
|
32
|
+
spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
|
33
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3.11'
|
34
|
+
spec.add_development_dependency 'minitest-coverage', '~> 1.0.0.b1'
|
35
|
+
spec.add_development_dependency 'byebug', '~> 9.0', '>= 9.0.6'
|
36
|
+
spec.add_development_dependency 'webmock', '~> 2.0', '>= 2.0.3'
|
37
|
+
spec.add_dependency 'activerecord', '~> 5.0.1'
|
38
|
+
spec.add_dependency 'mechanize', '~> 2.7.5'
|
39
|
+
spec.add_dependency 'nokogiri', '~> 1.6.8.1'
|
37
40
|
end
|
data/bin/barchart_data
CHANGED
@@ -2,14 +2,37 @@
|
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "barchart_data"
|
5
|
-
require_relative '../lib/
|
6
|
-
require_relative '../lib/
|
5
|
+
require_relative '../lib/barchart_scripts/barchart_connection'
|
6
|
+
require_relative '../lib/barchart_scripts/scraper'
|
7
|
+
require_relative '../lib/barchart_scripts/scrape_new_highs_new_lows'
|
7
8
|
|
9
|
+
BARCHART_URLS = { AllTimeHigh: 'http://old.barchart.com/stocks/athigh.php?_dtp1=0',
|
10
|
+
AllTimeLow: 'http://old.barchart.com/stocks/atlow.php?_dtp1=0',
|
11
|
+
NewHigh: 'http://old.barchart.com/stocks/high.php?_dtp1=0',
|
12
|
+
NewLow: 'http://old.barchart.com/stocks/low.php?_dtp1=0' }
|
13
|
+
BARCHART_HIGH_LOWS_URL = 'https://www.barchart.com/stocks/highs-lows/summary'
|
14
|
+
|
15
|
+
connection = BarchartData::BarchartConnection.new
|
8
16
|
scraper = BarchartData::Scraper.new
|
9
|
-
|
17
|
+
high_low = BarchartData::ScrapeNewHighsNewLows.new
|
10
18
|
|
19
|
+
BARCHART_URLS.each do |symbol, url|
|
20
|
+
page = connection.fetch_page url
|
21
|
+
data = scraper.extract_symbols_from_page page
|
22
|
+
scraper.insert_data data, symbol
|
23
|
+
end
|
11
24
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
25
|
+
page = connection.fetch_page BARCHART_HIGH_LOWS_URL
|
26
|
+
highs = high_low.extract_table_data_with_class_even page
|
27
|
+
lows = high_low.extract_table_data_with_class_odd page
|
28
|
+
high_values = high_low.extract_values highs
|
29
|
+
low_values = high_low.extract_values lows
|
30
|
+
high_fields = high_low.convert_stringy_numbers_to_int high_values
|
31
|
+
low_fields = high_low.convert_stringy_numbers_to_int low_values
|
32
|
+
convert_highs = high_low.convert_field_names_to_symbols(high_fields, "high")
|
33
|
+
convert_lows = high_low.convert_field_names_to_symbols(low_fields, "low")
|
34
|
+
merged = high_low.merge_high_low(convert_highs, convert_lows)
|
35
|
+
to_hash = high_low.hash_data_before_insertion merged
|
36
|
+
high_low.add_datestamp to_hash
|
37
|
+
high_low.insert_data to_hash
|
38
|
+
to_hash
|
data/lib/barchart_data.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require "barchart_data/version"
|
2
|
-
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
2
|
+
|
3
|
+
require 'barchart_scripts/barchart_connection'
|
4
|
+
require 'barchart_scripts/scrape_new_highs_new_lows'
|
5
|
+
require 'barchart_scripts/scraper'
|
6
6
|
module BarchartData
|
7
7
|
# Your code goes here...
|
8
8
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
module BarchartData
|
4
|
+
class BarchartConnection
|
5
|
+
attr_accessor :mechanize
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@mechanize = Mechanize.new
|
9
|
+
@mechanize.user_agent = 'Mac FireFox'
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch_page(url)
|
13
|
+
@mechanize.get(url)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
module BarchartData
|
3
|
+
class ScrapeNewHighsNewLows
|
4
|
+
def extract_table_data_with_class_even page
|
5
|
+
array = page.search('.even').map { |e| e.text() }
|
6
|
+
array = prune_array_data array
|
7
|
+
array.map! { |elem| elem.split }
|
8
|
+
end
|
9
|
+
|
10
|
+
def extract_table_data_with_class_odd page
|
11
|
+
array = page.search('.odd').map { |e| e.text() }
|
12
|
+
array = prune_array_data array
|
13
|
+
array.map! { |elem| elem.split }
|
14
|
+
end
|
15
|
+
|
16
|
+
def prune_array_data arr
|
17
|
+
ten = arr[10]
|
18
|
+
arr.slice!(5..15)
|
19
|
+
arr << ten
|
20
|
+
end
|
21
|
+
|
22
|
+
def extract_values array
|
23
|
+
temp = []
|
24
|
+
array.each do |elem|
|
25
|
+
elem.each_with_index do |e, i|
|
26
|
+
temp << e if i == 0 || i == 2
|
27
|
+
end
|
28
|
+
end
|
29
|
+
temp
|
30
|
+
# remove_extraneous_elements temp
|
31
|
+
end
|
32
|
+
|
33
|
+
def convert_stringy_numbers_to_int array
|
34
|
+
array.map! { |elem| elem !~ /\D/ ? elem.to_i : elem }
|
35
|
+
array
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_data_integrity array
|
39
|
+
return false unless array.partition { |v| v.is_a? String }[0].count == 6
|
40
|
+
return false unless array.partition { |v| v.is_a? Integer }[0].count == 6
|
41
|
+
array
|
42
|
+
end
|
43
|
+
|
44
|
+
def convert_field_names_to_symbols array, arg
|
45
|
+
keyed_array = []
|
46
|
+
hash = { "1-Month" => :"one_month_#{arg}", "3-Month" => :"three_month_#{arg}",
|
47
|
+
"6-Month" => :"six_month_#{arg}", "52-Week" => :"twelve_month_#{arg}",
|
48
|
+
"YTD" => :"ytd_#{arg}", "All-Time" => :"all_time_#{arg}" }
|
49
|
+
|
50
|
+
array.each { |elem| hash.include?(elem) ? keyed_array << hash[elem] : keyed_array << elem }
|
51
|
+
keyed_array
|
52
|
+
end
|
53
|
+
|
54
|
+
def merge_high_low highs, lows
|
55
|
+
highs + lows
|
56
|
+
end
|
57
|
+
|
58
|
+
def hash_data_before_insertion array
|
59
|
+
array.each_slice(2).to_h
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_datestamp hash
|
63
|
+
hash[:saved_on] = Time.now.strftime("%Y-%m-%d")
|
64
|
+
end
|
65
|
+
|
66
|
+
def insert_data high_low
|
67
|
+
HighLow.create(high_low)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def remove_extraneous_elements array
|
72
|
+
array.slice!(10,10)
|
73
|
+
array
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
module BarchartData
|
3
|
+
class Scraper
|
4
|
+
def extract_symbols_from_page page
|
5
|
+
array = page.search('.ds_symbol').map { |e| e.text() }
|
6
|
+
array.map! { |elem| elem.split }
|
7
|
+
end
|
8
|
+
|
9
|
+
def validate_data_integrity dirty_array
|
10
|
+
dirty_array.reduce([]) { |cleaned_array, i|
|
11
|
+
cleaned_array << i if i.to_s == i.to_s.upcase
|
12
|
+
cleaned_array
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def insert_data arr, sym
|
17
|
+
case sym
|
18
|
+
when :AllTimeHigh
|
19
|
+
arr.each do |s|
|
20
|
+
AllTimeHigh.create(symbol: s, saved_on: Time.current)
|
21
|
+
end
|
22
|
+
when :AllTimeLow
|
23
|
+
arr.each do |s|
|
24
|
+
AllTimeLow.create(symbol: s, saved_on: Time.current)
|
25
|
+
end
|
26
|
+
when :NewHigh
|
27
|
+
arr.each do |s|
|
28
|
+
NewHigh.create(symbol: s, saved_on: Time.current)
|
29
|
+
end
|
30
|
+
when :NewLow
|
31
|
+
arr.each do |s|
|
32
|
+
NewLow.create(symbol: s, saved_on: Time.current)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -34,8 +34,9 @@ module BarchartData
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def copy_classes
|
37
|
-
copy_file "../../../../
|
38
|
-
copy_file "../../../../
|
37
|
+
copy_file "../../../../barchart_scripts/barchart_connection.rb", "lib/barchart_scripts/barchart_connection.rb"
|
38
|
+
copy_file "../../../../barchart_scripts/scraper.rb", 'lib/barchart_scripts/scraper.rb'
|
39
|
+
copy_file "../../../../barchart_scripts/scrape_new_highs_new_lows.rb", 'lib/barchart_scripts/scrape_new_highs_new_lows.rb'
|
39
40
|
copy_file "../../../../../bin/barchart_data", 'bin/barchart'
|
40
41
|
end
|
41
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barchart_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Becco
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,98 +16,158 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.12.4
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.12.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 11.3.0
|
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:
|
40
|
+
version: 11.3.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: vcr
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '3.0'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 3.0.3
|
48
51
|
type: :development
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
55
|
- - "~>"
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
57
|
+
version: '3.0'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.0.3
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: sqlite3
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.3.
|
67
|
+
version: 1.3.11
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.3.11
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: minitest-coverage
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.0.0.b1
|
62
82
|
type: :development
|
63
83
|
prerelease: false
|
64
84
|
version_requirements: !ruby/object:Gem::Requirement
|
65
85
|
requirements:
|
66
86
|
- - "~>"
|
67
87
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
88
|
+
version: 1.0.0.b1
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: byebug
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '9.0'
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 9.0.6
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '9.0'
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 9.0.6
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: webmock
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '2.0'
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 2.0.3
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.0'
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 2.0.3
|
69
129
|
- !ruby/object:Gem::Dependency
|
70
130
|
name: activerecord
|
71
131
|
requirement: !ruby/object:Gem::Requirement
|
72
132
|
requirements:
|
73
133
|
- - "~>"
|
74
134
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
135
|
+
version: 5.0.1
|
76
136
|
type: :runtime
|
77
137
|
prerelease: false
|
78
138
|
version_requirements: !ruby/object:Gem::Requirement
|
79
139
|
requirements:
|
80
140
|
- - "~>"
|
81
141
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
142
|
+
version: 5.0.1
|
83
143
|
- !ruby/object:Gem::Dependency
|
84
144
|
name: mechanize
|
85
145
|
requirement: !ruby/object:Gem::Requirement
|
86
146
|
requirements:
|
87
147
|
- - "~>"
|
88
148
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.7.
|
149
|
+
version: 2.7.5
|
90
150
|
type: :runtime
|
91
151
|
prerelease: false
|
92
152
|
version_requirements: !ruby/object:Gem::Requirement
|
93
153
|
requirements:
|
94
154
|
- - "~>"
|
95
155
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.7.
|
156
|
+
version: 2.7.5
|
97
157
|
- !ruby/object:Gem::Dependency
|
98
158
|
name: nokogiri
|
99
159
|
requirement: !ruby/object:Gem::Requirement
|
100
160
|
requirements:
|
101
161
|
- - "~>"
|
102
162
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.6.
|
163
|
+
version: 1.6.8.1
|
104
164
|
type: :runtime
|
105
165
|
prerelease: false
|
106
166
|
version_requirements: !ruby/object:Gem::Requirement
|
107
167
|
requirements:
|
108
168
|
- - "~>"
|
109
169
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.6.
|
170
|
+
version: 1.6.8.1
|
111
171
|
description: "Extract data for all-time-highs, new-highs, new-lows and store. Generator
|
112
172
|
for schema\n and Ruby scripts for integration with Rails. "
|
113
173
|
email:
|
@@ -123,16 +183,16 @@ files:
|
|
123
183
|
- README.md
|
124
184
|
- Rakefile
|
125
185
|
- barchart_data-0.1.0.gem
|
186
|
+
- barchart_data-0.1.1.gem
|
126
187
|
- barchart_data.gemspec
|
127
188
|
- bin/barchart_data
|
128
189
|
- bin/console
|
129
190
|
- bin/setup
|
130
191
|
- lib/barchart_data.rb
|
131
|
-
- lib/barchart_data/alltimehigh.rb
|
132
|
-
- lib/barchart_data/high_low_scraper.rb
|
133
|
-
- lib/barchart_data/newhigh.rb
|
134
|
-
- lib/barchart_data/scraper.rb
|
135
192
|
- lib/barchart_data/version.rb
|
193
|
+
- lib/barchart_scripts/barchart_connection.rb
|
194
|
+
- lib/barchart_scripts/scrape_new_highs_new_lows.rb
|
195
|
+
- lib/barchart_scripts/scraper.rb
|
136
196
|
- lib/generators/barchart_data/install/install_generator.rb
|
137
197
|
- lib/generators/barchart_data/install/templates/alltimehigh_migration.rb
|
138
198
|
- lib/generators/barchart_data/install/templates/alltimelow_migration.rb
|
@@ -165,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
225
|
version: '0'
|
166
226
|
requirements: []
|
167
227
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
228
|
+
rubygems_version: 2.5.1
|
169
229
|
signing_key:
|
170
230
|
specification_version: 4
|
171
231
|
summary: Scrape Data From BarCharts.com and persist in database
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'barchart_data'
|
2
|
-
require 'active_record'
|
3
|
-
require 'mechanize'
|
4
|
-
|
5
|
-
module BarchartData
|
6
|
-
class AllTimeHigh
|
7
|
-
attr_reader :url, :agent
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@url = "http://www.barchart.com/stocks/athigh.php?_dtp1-0"
|
11
|
-
@agent = Mechanize.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def parse_url
|
15
|
-
@agent.get(@url).search("input")
|
16
|
-
end
|
17
|
-
|
18
|
-
def strip_symbols(page)
|
19
|
-
symbols = page[6].to_s
|
20
|
-
strip_symbols = symbols.scan(/[A-Z]+,[^a-z]+[A-Z]/)
|
21
|
-
tickers = strip_symbols[0].split(',')
|
22
|
-
end
|
23
|
-
|
24
|
-
def insert_symbols(symbols)
|
25
|
-
symbols.each do |s|
|
26
|
-
:AllTimeHigh.create(symbol: s, saved_on: Time.now.strftime("%m/%d/%Y"))
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'barchart_data'
|
2
|
-
require 'active_record'
|
3
|
-
require 'mechanize'
|
4
|
-
|
5
|
-
module BarchartData
|
6
|
-
class HighLowScraper
|
7
|
-
attr_reader :url, :agent
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@url = { high_low: 'http://www.barchart.com/stocks/newhilo.php?dwm=d'}
|
11
|
-
@agent = Mechanize.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def data_extraction
|
15
|
-
page = @agent.get(@url[:high_low]).search("div[id='divContent']")
|
16
|
-
page.css("td[align='right']").to_a
|
17
|
-
end
|
18
|
-
|
19
|
-
def strip_highs_and_lows_from links
|
20
|
-
strip_links = []
|
21
|
-
regex_the_links = []
|
22
|
-
overall_high_low = []
|
23
|
-
|
24
|
-
links.each do |a|
|
25
|
-
strip_links.push(a.to_s)
|
26
|
-
end
|
27
|
-
|
28
|
-
strip_links.slice!(0..3)
|
29
|
-
strip_links.shift(6)
|
30
|
-
strip_links.each { |e| regex_the_links.push(e.match(/>\d+</).to_s) }
|
31
|
-
regex_the_links.map! do |e|
|
32
|
-
if e.blank?
|
33
|
-
e = ">0<"
|
34
|
-
else
|
35
|
-
e = e
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
regex_the_links.map! { |e| e.gsub(/[><]/,"") }
|
40
|
-
extracted_values = regex_the_links.each_slice(10).to_a
|
41
|
-
extracted_values.each do |value|
|
42
|
-
overall_high_low << value.first.to_i
|
43
|
-
end
|
44
|
-
overall_high_low
|
45
|
-
end
|
46
|
-
|
47
|
-
def insert_data high_low
|
48
|
-
::HighLow.create(one_month_high: high_low[0], one_month_low: high_low[1],
|
49
|
-
three_month_high: high_low[2], three_month_low: high_low[3],
|
50
|
-
six_month_high: high_low[4], six_month_low: high_low[5],
|
51
|
-
twelve_month_high: high_low[6], twelve_month_low: high_low[7],
|
52
|
-
ytd_high: high_low[8], ytd_low: high_low[8],
|
53
|
-
saved_on: Time.current )
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'barchart_data'
|
2
|
-
require 'active_record'
|
3
|
-
require 'mechanize'
|
4
|
-
|
5
|
-
module BarchartData
|
6
|
-
class NewHigh
|
7
|
-
attr_reader :url, :agent
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@url = 'http://www.barchart.com/stocks/high.php'
|
11
|
-
@agent = Mechanize.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def parse_url
|
15
|
-
@agent.get(@url).search("input")
|
16
|
-
end
|
17
|
-
|
18
|
-
def strip_symbols(page)
|
19
|
-
symbols = page[6].to_s
|
20
|
-
strip_symbols = symbols.scan(/[A-Z]+,[^a-z]+[A-Z]/)
|
21
|
-
tickers = strip_symbols[0].split(',')
|
22
|
-
end
|
23
|
-
|
24
|
-
def insert_symbols(symbols)
|
25
|
-
symbols.each do |s|
|
26
|
-
:NewHigh.create(symbol: s, saved_on: Time.now.strftime("%m/%d/%Y"))
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'barchart_data'
|
2
|
-
require 'active_record'
|
3
|
-
require 'mechanize'
|
4
|
-
|
5
|
-
module BarchartData
|
6
|
-
class Scraper
|
7
|
-
attr_reader :urls, :agent
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@urls = {
|
11
|
-
all_time_high: 'http://www.barchart.com/stocks/athigh.php?_dtp1-0',
|
12
|
-
new_high: 'http://www.barchart.com/stocks/high.php?_dtp1-0',
|
13
|
-
new_low: 'http://www.barchart.com/stocks/low.php?_dtp1=0',
|
14
|
-
all_time_low: 'http://www.barchart.com/stocks/atlow.php?_dtp1=0'
|
15
|
-
}
|
16
|
-
@agent = Mechanize.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def data_extraction
|
20
|
-
@urls.each do |sym, url|
|
21
|
-
parse_url = @agent.get("#{url}").search("input")
|
22
|
-
symbols = self.strip_symbols(parse_url)
|
23
|
-
self.insert_symbols(sym, symbols)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def strip_symbols page
|
28
|
-
symbols = page[6].to_s
|
29
|
-
strip_symbols = symbols.scan(/[A-Z]+,[^a-z]+[A-Z]/)
|
30
|
-
tickers = strip_symbols[0].split(',')
|
31
|
-
end
|
32
|
-
|
33
|
-
def insert_symbols sym, symbols
|
34
|
-
case sym
|
35
|
-
when :all_time_high
|
36
|
-
symbols.each do |s|
|
37
|
-
::AllTimeHigh.create(symbol: s, saved_on: Time.current)
|
38
|
-
end
|
39
|
-
when :new_high
|
40
|
-
symbols.each do |s|
|
41
|
-
::NewHigh.create(symbol: s, saved_on: Time.current)
|
42
|
-
end
|
43
|
-
when :new_low
|
44
|
-
symbols.each do |s|
|
45
|
-
::NewLow.create(symbol: s, saved_on: Time.current)
|
46
|
-
end
|
47
|
-
when :all_time_low
|
48
|
-
symbols.each do |s|
|
49
|
-
::AllTimeLow.create(symbol: s, saved_on: Time.current)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|