dailyrep 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ require_relative '../Changable'
2
+
3
+ module DailyRep
4
+ module Entities
5
+ class Micex < IBrowser
6
+ include Changable
7
+ attr_reader :values
8
+
9
+ def self.create
10
+ result = [(new)]
11
+ end
12
+
13
+ def initialize(delta=Configer.micex_delta, source=Configer.micex_source)
14
+ @source = source
15
+ @notif_limit = delta
16
+ @values = {last: "", open: "", delta: "" }
17
+ @push = 0
18
+ super
19
+ end
20
+
21
+
22
+ def log_msg phase
23
+ super @entity, phase
24
+ end
25
+
26
+ def process
27
+ super do
28
+ result_json = get_source_json @source
29
+ result_json = result_json[1]
30
+ @last_val = result_json['LAST'].to_f
31
+ @open_val = result_json['OPEN'].to_f
32
+ @delta_prc_val = (((@last_val - @open_val)*100)/@open_val).round(2)
33
+ #evaluate push 0 or 1 via Chgable module
34
+ @push = track_change @delta_prc_val, @notif_limit
35
+ #store values to write to db
36
+ @values = { last: @last_val, open: @open_val, delta: @delta_prc_val }
37
+ end
38
+ end
39
+
40
+ def notify
41
+ super do
42
+ if @push == 1 then
43
+ note = "Micex USD/RUB
44
+ Last value: #{@last_val}
45
+ Open value: #{@open_val}
46
+ Delta percentage: #{@delta_prc_val}
47
+ www.googledrive.com/host/0Byb1mtPn4ZEAVm9zTUJQbHM2U0U"
48
+ push_note note
49
+ end
50
+ end
51
+ end
52
+
53
+ def write_to_db
54
+ super do
55
+ write_hist @entity, :delta.to_s, @delta_prc_val, @push
56
+ end
57
+ end
58
+
59
+ def web_reload
60
+ super do
61
+ set_html @entity, @values, @push
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,69 @@
1
+ require_relative '../Changable'
2
+ module DailyRep
3
+ module Entities
4
+ class Minfin < IBrowser
5
+ include Changable
6
+ attr_reader :usd_uah_info
7
+
8
+ def self.create
9
+ result = [(new)]
10
+ end
11
+
12
+ def initialize( delta=Configer.minfin_delta, source=Configer.minfin_source)
13
+ super
14
+ @search_path = source
15
+ @notif_limit = delta
16
+ @usd_uah_info = {:buy_bank => -999, :sale_bank => -999}
17
+ @push = 0
18
+ end
19
+
20
+ def log_msg phase
21
+ super @entity, phase
22
+ end
23
+
24
+ def process
25
+ super do
26
+
27
+ out_set_bank = get_source_http @search_path, '.mb-data .per'
28
+ @usd_uah_info[:buy_bank] = out_set_bank[0].text
29
+ @usd_uah_info[:sale_bank] = out_set_bank[3].text
30
+
31
+
32
+ @last_val = check_history_notif(@entity, :sale_bank.to_s, (Time.now - 1.week)).to_f
33
+ cur =@usd_uah_info[:sale_bank].to_f
34
+ @usd_uah_info[:delta] = (cur - @last_val)*100/cur
35
+
36
+ @push = track_change @usd_uah_info[:delta], @notif_limit
37
+
38
+ end
39
+ end
40
+
41
+
42
+ def notify
43
+ super do
44
+ if @push == 1 then
45
+ note = "Minfin
46
+ Current market: #{@usd_uah_info[:sale_bank]}
47
+ Last value: #{@last_val}
48
+ Delta percentage: #{@usd_uah_info[:delta]}"
49
+ push_note note
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+ def write_to_db
56
+ super do
57
+ write_hist @entity, :sale_bank.to_s, @usd_uah_info[:sale_bank], @push
58
+ write_hist @entity, :delta.to_s, @usd_uah_info[:delta], @push
59
+ end
60
+ end
61
+
62
+ def web_reload
63
+ super do
64
+ set_html @entity, {current: @usd_uah_info[:sale_bank], delta: @usd_uah_info[:delta]}
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,67 @@
1
+ require_relative '../Changable'
2
+ module DailyRep
3
+ module Entities
4
+ class Yanoil < IBrowser
5
+ include Changable
6
+ attr_reader :change
7
+
8
+ def self.create
9
+ result = [(new )]
10
+ end
11
+
12
+ def initialize( delta=Configer.yanoil_delta, source=Configer.yanoil_source)
13
+ super
14
+ @search_path = source
15
+ @notif_limit = delta
16
+ @scope = '.b-quote__last-day'
17
+ @is_current_date = false
18
+ @push = 0
19
+ end
20
+
21
+ def log_msg phase
22
+ super @entity, phase
23
+ end
24
+
25
+ def process
26
+ super do
27
+ out_set = get_source_http @search_path, @scope
28
+ @last = out_set.css('.b-quote__value').text.gsub(',','.').to_f
29
+ v_date = out_set.css('.b-quote__date').text
30
+ change = out_set.css('.b-quote__change').text.gsub(',','.')
31
+ change_sign = out_set.css('.b-quote__change .b-quote__sgn').text
32
+ @change = (change + change_sign).to_f
33
+ @is_current_date = (Time.now.day.to_i == v_date[0..2].to_i)
34
+ if @is_current_date then
35
+ @push = track_change @change, @notif_limit
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ def notify
42
+ super do
43
+ if @push == 1 then
44
+ note = "Yandex Brent Oil
45
+ Last value: #{@last}
46
+ Delta percentage: #{@change}"
47
+ push_note note
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+ def write_to_db
54
+ super do
55
+ write_hist @entity, :delta.to_s, @change, @push
56
+ end
57
+ end
58
+
59
+ def web_reload
60
+ super do
61
+ set_html @entity, { delta: @change, current: @last }
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module DailyRep
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+ require "dailyrep/entities/Doujob"
3
+
4
+ module DailyRep
5
+ describe "Doujob unit test" do
6
+ before do
7
+ @doujob1 = Entities::Doujob.new("Ruby")
8
+ end
9
+
10
+ it 'should test process method and write_to_hist' do
11
+ @doujob1.process
12
+ assert @doujob1.diff, 'process method returns empty json responce'
13
+ assert_not @doujob1.diff.count == 0, 'response count = 0'
14
+ assert_difference('History.count', @doujob1.diff.count) do
15
+ @doujob1.write_to_db
16
+ end
17
+ end
18
+
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ module DailyRep
4
+ ############################
5
+ describe "Dailyrep testing" do
6
+
7
+ before do
8
+ @browser = IBrowser.new
9
+ @browser.write_hist('test_entity_1', 'test_parameter', 'test_val')
10
+ @browser.write_hist('test_entity_2', 'test_parameter', 'test_val', 1)
11
+ end
12
+
13
+ it 'should check database via check_ro_exists' do
14
+ assert @browser.check_row_exists('test_entity_1', 'test_parameter', 'test_val')
15
+ end
16
+ it 'should perform http request to Dou.ua website' do
17
+ assert @browser.get_source_http('http://jobs.dou.ua/vacancies/?search=Ruby', 'div#vacancyListId li')
18
+ end
19
+
20
+ it 'should perform json request to micex website' do
21
+ assert @browser.get_source_json('http://www.micex.ru/issrpc/marketdata/currency/selt/daily/short/result.json?boardid=CETS&secid=USD000UTSTOM')
22
+ end
23
+
24
+ it 'should write history data to the database' do
25
+ hist_1 = History.where(entity: 'test_entity_1').first
26
+ hist_2 = History.where(entity: 'test_entity_2').first
27
+ assert_equal 'N', hist_1.notified
28
+ assert_equal 'Y', hist_2.notified
29
+ assert_not hist_1.entity.empty?, 'entity column is empty'
30
+ assert_not hist_1.parameter.empty?
31
+ assert_not hist_1.val.empty?
32
+ assert_not hist_1.created_at.empty?
33
+ assert_not hist_1.id.nil?, 'Id has not been set'
34
+ end
35
+
36
+ it 'should check if notification exists in' do
37
+ assert_nil @browser.check_history_notif('test_entity_1', 'test_parameter'), 'there should be no notifications'
38
+ assert @browser.check_history_notif('test_entity_2', 'test_parameter')
39
+ end
40
+
41
+ it 'should check pushbullet connection' do
42
+ client = Washbullet::Client.new(Configer.get_client_tokens.first)
43
+ assert_not client.me.body["email"].empty?
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+ require "dailyrep/entities/Kinozal"
3
+
4
+ module DailyRep
5
+ describe "Kinozal unit test" do
6
+ before do
7
+ @kinozal = Entities::Kinozal.new("Avatar")
8
+ end
9
+
10
+ it 'should test process method and write_to_hist' do
11
+ @kinozal.process
12
+ assert @kinozal.out_hash_clean, 'process method returns empty json responce'
13
+ assert_not @kinozal.out_hash_clean.count == 0, 'response count = 0'
14
+ assert_difference('History.count', @kinozal.out_hash_clean.count) do
15
+ @kinozal.write_to_db
16
+ end
17
+ assert @kinozal.to_notification.count == @kinozal.out_hash_clean.count
18
+ end
19
+
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+ require "dailyrep/entities/Micex"
3
+
4
+ module DailyRep
5
+ class Micex
6
+ def log_msg phase
7
+ end
8
+ end
9
+
10
+ describe "Micex unit test" do
11
+ before do
12
+ @micex = Entities::Micex.new()
13
+ end
14
+
15
+ it 'should test process method' do
16
+ @micex.process
17
+ assert @micex.values[:last] > 0, 'process method returns empty json responce'
18
+ end
19
+
20
+ it 'should test write_to_hist' do
21
+ assert_difference('History.count') do
22
+ @micex.write_to_db
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+ require "dailyrep/entities/Minfin"
3
+
4
+ module DailyRep
5
+ describe "Minfin unit test" do
6
+ before do
7
+ @minfin = Entities::Minfin.new()
8
+ end
9
+
10
+ it 'should test process method and write_to_hist' do
11
+ @minfin.process
12
+ @minfin.usd_uah_info.each { |key, val|
13
+ assert_not val == -999, "#{key} is not set in responce "
14
+ }
15
+ assert_difference('History.count', 2) do
16
+ @minfin.write_to_db
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+
23
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+ require "dailyrep/entities/Yanoil"
3
+
4
+ module DailyRep
5
+ describe "Yanoil unit test" do
6
+ before do
7
+ @yanoil = Entities::Yanoil.new()
8
+ end
9
+
10
+ it 'should test process method and write_to_hist' do
11
+ @yanoil.process
12
+ assert @yanoil.change, 'process method returns empty json responce'
13
+ assert_difference('History.count') do
14
+ @yanoil.write_to_db
15
+ end
16
+ end
17
+
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,37 @@
1
+ require "minitest/autorun"
2
+
3
+ require 'active_record'
4
+ require 'json'
5
+ require 'hashdiff'
6
+
7
+ DATABASE = 'db/db_test.sql3' #sets test database
8
+ CONFIG_FILE = 'config/config.json'
9
+
10
+ #config file loading
11
+ require 'dailyrep/Loadconfig'
12
+
13
+ DailyRep::Configer.set_index_file 'config/index.html'
14
+
15
+ require 'active_support/testing/assertions'
16
+ include ActiveSupport::Testing::Assertions
17
+
18
+ #clears test database
19
+ History.delete_all
20
+
21
+ require 'dailyrep/IBrowser'
22
+
23
+
24
+ module DailyRep
25
+ class IBrowser
26
+ def self.get_html entity, key
27
+ @@out_html.css("##{entity}_#{key}")[0].content
28
+ end
29
+ end
30
+
31
+ module Trackable
32
+ def log_msg entity, add_param='', phase
33
+ end
34
+ def log_error e
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dailyrep
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yurii Kurylenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashdiff
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: washbullet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |-
98
+ This is Ruby App collects the information you need (currency, new torrents, etc) from various web sites.
99
+
100
+ Main features:
101
+ - local SQlite3 database to store history info
102
+ - devices notification over PushBullet service
103
+ - recent information visualization via html
104
+ - flexible configuration using json file
105
+
106
+ Currently available web site notificattions:
107
+ - http://minfin.com.ua - UAH/USD currency
108
+ - http://micex.ru/ - RUB/USD currency
109
+ - http://dou.ua/ - new IT job opportunities
110
+ - http://kinozal.tv/ - new movies available on torrent
111
+ - http://news.yandex.ru/ - Breny Oil rate
112
+
113
+ As the example (app reloads index.html file that is shared thought Google Drive):
114
+ www.googledrive.com/host/0Byb1mtPn4ZEAVm9zTUJQbHM2U0U
115
+ email: yuriy.kurilenko7@gmail.com
116
+ executables:
117
+ - dailyrep
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - .gitignore
122
+ - README.md
123
+ - Rakefile
124
+ - bin/dailyrep
125
+ - config/.gitkeep
126
+ - config/config_template.json
127
+ - config/index_template.html
128
+ - dailyrep.gemspec
129
+ - db/.gitkeep
130
+ - lib/dailyrep/AppContainer.rb
131
+ - lib/dailyrep/Changable.rb
132
+ - lib/dailyrep/Dbops.rb
133
+ - lib/dailyrep/IBrowser.rb
134
+ - lib/dailyrep/IndexWriter.rb
135
+ - lib/dailyrep/Loadconfig.rb
136
+ - lib/dailyrep/Notificator.rb
137
+ - lib/dailyrep/Trackable.rb
138
+ - lib/dailyrep/entities/Doujob.rb
139
+ - lib/dailyrep/entities/Kinozal.rb
140
+ - lib/dailyrep/entities/Micex.rb
141
+ - lib/dailyrep/entities/Minfin.rb
142
+ - lib/dailyrep/entities/Yanoil.rb
143
+ - lib/dailyrep/version.rb
144
+ - test/dailyrep/Doujob_test.rb
145
+ - test/dailyrep/IBrowser_test.rb
146
+ - test/dailyrep/Kinozal_test.rb
147
+ - test/dailyrep/Micex_test.rb
148
+ - test/dailyrep/Minfin_test.rb
149
+ - test/dailyrep/Yanoil_test.rb
150
+ - test/test_helper.rb
151
+ homepage:
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '2.0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.4.5
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Ruby app that provides values checking on particular websites and performs
175
+ notification
176
+ test_files: []