barchart_data 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed65fd6b74e559dedbe41fb2b7a5a924630e736f
4
+ data.tar.gz: 5ca2f13c1c54d0e2e7d5b830199269636a281263
5
+ SHA512:
6
+ metadata.gz: 75fa510e7ad7a18474713f1ed2761646825ffbdb488928d32bfb31f73b3cb317045c9516df91b229a210e48e6e106c229f65195e255a1e633da358f1f7d65756
7
+ data.tar.gz: 090c479d94d05ffa5053d7999d7fc95e21f72247c4f44065bcb68cc98f832f838b3d009adf4aa1f05e8578beb1a4ee92cd4f5f55d52cacba1601f339f5f5abc2
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in barchart_data.gemspec
4
+ gemspec
5
+
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # BarchartData
2
+
3
+ BarchartData: Screen Scrape Utility to grab and persist stock releated data.
4
+
5
+ Current version (0.1.0) extracts All Time Highs. This project is still in its infancy and will be heavily modified over time.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'barchart_data'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install barchart_data
22
+
23
+ ## Usage
24
+
25
+ ```rails generate barchart_data:install```
26
+
27
+ ```rake db:migrate```
28
+
29
+ ```rails runner bin/barchart```
30
+
31
+ ***Best Run Time:*** 7PM PST (2AM GMT) as data stabalizes.
32
+
33
+ ***Be Kind*** Test against the file test/test_files/athigh.php and limit hits against site.
34
+
35
+ ## Prevent Duplicate Records
36
+ There should only be one record per symbol per date.
37
+
38
+
39
+ **AllTimeHigh**
40
+
41
+ class AllTimeHigh < ActiveRecord::Base
42
+ validates :symbol, uniqueness: { scope: :saved_on }
43
+ end
44
+
45
+
46
+ ## Future Features:
47
+ * 52-Week High
48
+ * All-Time-Low
49
+ * 52-Week Low
50
+ * Current New Highs/Lows
51
+ * Error Handling
52
+
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it ( https://github.com/https://github.com/trendwithin/barchart_data/fork )
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create a new Pull Request
67
+
68
+ ## Contact:
69
+ Feel free to contract me with questions, collaborations, features and ideas, refactoring and code improvement etc...
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.test_files = FileList['test/*_test.rb']
6
+ end
7
+
8
+ task default: :test
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'barchart_data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "barchart_data"
8
+ spec.version = BarchartData::VERSION
9
+ spec.authors = ["Michael Becco"]
10
+ spec.email = ["e4e6d4d5@gmail.com"]
11
+ spec.licenses = ['MIT']
12
+ spec.summary = %q{Scrape Data From BarCharts.com and persist in database}
13
+ spec.description = %q{Extract data for all-time-highs, new-highs, new-lows and store. Generator for schema
14
+ and Ruby scripts for integration with Rails. }
15
+ spec.homepage = "https://github.com/trendwithin/barchart_data"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.9"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency 'fakeweb', '~> 1.3.0'
33
+ spec.add_development_dependency 'sqlite3', '~> 1.3.10'
34
+ spec.add_dependency 'activerecord', '~> 4.2.2'
35
+ spec.add_dependency 'mechanize', '~> 2.7.3'
36
+ spec.add_dependency 'nokogiri', '~> 1.6.6.2'
37
+ end
data/bin/barchart_data ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "barchart_data"
5
+
6
+ require_relative '../lib/barchart_data/alltimehigh'
7
+ ath = BarchartData::AllTimeHigh.new
8
+ page = ath.parse_url
9
+ symbols = ath.strip_symbols(page)
10
+ puts symbols
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "barchart_data"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,3 @@
1
+ module BarchartData
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "barchart_data/version"
2
+ require 'barchart_data/alltimehigh'
3
+ module BarchartData
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/active_record'
4
+
5
+
6
+ module BarchartData
7
+ module Generators
8
+ class InstallGenerator < Rails::Generators::Base
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ def copy_schema
12
+ time = Time.now.strftime("%Y%m%d%H%M%S")
13
+ template "schema.rb", "db/migrate/#{time}_create_all_time_highs.rb"
14
+ copy_file "../../../../barchart_data/alltimehigh.rb", 'lib/barchart_data/alltimehigh.rb'
15
+ copy_file "../../../../../bin/barchart_data", 'bin/barchart'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAllTimeHighs < ActiveRecord::Migration
2
+ def change
3
+ create_table :all_time_highs, :force => true do |t|
4
+ t.string :symbol
5
+ t.datetime :saved_on
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barchart_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Becco
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fakeweb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.10
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.10
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.2.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.2.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: mechanize
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.7.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.7.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.6.6.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.6.6.2
111
+ description: "Extract data for all-time-highs, new-highs, new-lows and store. Generator
112
+ for schema\n and Ruby scripts for integration with Rails. "
113
+ email:
114
+ - e4e6d4d5@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - barchart_data.gemspec
125
+ - bin/barchart_data
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/barchart_data.rb
129
+ - lib/barchart_data/alltimehigh.rb
130
+ - lib/barchart_data/version.rb
131
+ - lib/generators/barchart_data/install/install_generator.rb
132
+ - lib/generators/barchart_data/install/templates/schema.rb
133
+ homepage: https://github.com/trendwithin/barchart_data
134
+ licenses:
135
+ - MIT
136
+ metadata:
137
+ allowed_push_host: https://rubygems.org
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.5
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Scrape Data From BarCharts.com and persist in database
158
+ test_files: []