bets 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bets.gemspec
4
+ gemspec
5
+
6
+ gem 'sqlite3'
7
+ gem 'nokogiri'
8
+ gem 'firewatir'
9
+ gem 'watir-webdriver'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Bets
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bets'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bets
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require './lib/config/environment.rb'
4
+
5
+ namespace :db do
6
+ desc 'Migrate the database'
7
+ task :migrate do
8
+ ActiveRecord::Migrator.migrate('./lib/db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
9
+ end
10
+ end
data/bets.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bets/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["anonymous"]
6
+ gem.email = ["anonymous@gmail.com"]
7
+ gem.description = %q{Gem for get data from bets}
8
+ gem.summary = %q{Parser for bets}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "bets"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Bets::VERSION
17
+ end
data/bin/bets ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ module Bets
2
+ VERSION = "0.0.1"
3
+ end
data/lib/bets.rb ADDED
@@ -0,0 +1,187 @@
1
+ # encoding: utf-8
2
+
3
+ require "bets/version"
4
+ require 'watir-webdriver'
5
+
6
+
7
+ module Bets
8
+ class Parse
9
+ def initialize
10
+ end
11
+ public
12
+ def parse
13
+ end
14
+ end
15
+
16
+ class Processor
17
+ private
18
+ def initialize
19
+ @names = {}
20
+ @conditions = {}
21
+ @binds = []
22
+ @records = {}
23
+ @lexems = {
24
+ 'ДЕЙСТВИЕ' => [:name, :text, :end],
25
+ 'УСЛОВИЕ' => [:name, :text, :end],
26
+ 'СВЯЗАТЬ' => [:bind_name, :bind_name]
27
+ }
28
+ @ff = Watir::Browser.new :firefox
29
+
30
+ @lang_map = {
31
+ 'НАЖАТЬ' => 'ff_click ',
32
+ 'ОТКРЫТЬ' => 'ff_goto ',
33
+ 'ЗНАЧЕНИЕ' => 'ff_get',
34
+ 'ЗАПОЛНИТЬ' => 'ff_set ',
35
+ '\ И\ ' => ' && ',
36
+ '\ ИЛИ\ ' => ' || ',
37
+ '\ НЕТ\ ' => ' not ',
38
+ 'ЕСЛИ\ ' => 'if ',
39
+ '\ ТО\ ' => ' then ',
40
+ '\ ИНАЧЕ\ ' => ' else ',
41
+ 'КОНЕЦ' => 'end;',
42
+ 'ЗАДЕРЖКА' => 'sleep ',
43
+ 'СЛ\_ЧИСЛО\(' => 'Random.new.rand(',
44
+ 'Игра' => '$game',
45
+ '%_прибыли' => '$percent',
46
+ 'Дата_игры' => '$date',
47
+ 'Время_игры' => '$time',
48
+ 'Б1[^_]' => '$b1_name',
49
+ 'Б1\_ставка' => '$b1_type',
50
+ 'Б1\_коэф' => '$b1_coef',
51
+ 'Б1\_вид\_спорта' => '$b1_kind',
52
+ 'Б1\_ссылка' => '$b1_link',
53
+ 'Б2[^_]' => '$b2_name',
54
+ 'Б2\_ставка' => '$b2_type',
55
+ 'Б2\_коэф' => '$b2_coef',
56
+ 'Б2\_вид\_спорта' => '$b2_kind',
57
+ 'Б2\_ссылка' => '$b2_link',
58
+ 'ПЕЧАТЬ ' => 'puts '
59
+ }
60
+ end
61
+
62
+ def read_data
63
+ data = File.open("data.txt", "r").read
64
+ forks = data.split(/^\=.*?\n/)
65
+ @records = []
66
+
67
+ forks.each do |f|
68
+ next if f.strip.empty?
69
+ @records << {
70
+ game: "'#{f.scan(/\d{2}\:\d{2}\.\ (.*?)\:/).flatten(1)[0]}'",
71
+ percent: f.scan(/\:\ (.*?)\%/).flatten(1)[0].gsub(',','.'),
72
+ date: "'#{f.scan(/(\d{1,2}[^.].*?)\ в\ \d{2}\:\d{2}/).flatten(1)[0]}'",
73
+ time: "'#{f.scan(/в\ (\d{2}\:\d{2})/).flatten(1)[0]}'",
74
+ b1_name: "'#{f.scan(/^1\.\ (.*?);\ /).flatten(1)[0]}'",
75
+ b1_type: "'#{f.scan(/^1\..*?ставка\ (.*?)\;/).flatten(1)[0]}'",
76
+ b1_coef: f.scan(/^1\..*?коэф\.\ (.*?)\(/).flatten(1)[0].gsub(',','.'),
77
+ b1_kind: "'#{f.scan(/^1\..*\((.*?)\/\//).flatten(1)[0]}'",
78
+ b1_game: "'#{f.scan(/^1\..*?\/\/\ (.*?)\)/).flatten(1)[0]}'",
79
+ b1_link: "'#{f.scan(/^1\..*\n(http.*?)$/).flatten(1)[0]}'",
80
+ b2_name: "'#{f.scan(/^2\.\ (.*?);\ /).flatten(1)[0]}'",
81
+ b2_type: "'#{f.scan(/^2\..*?ставка\ (.*?)\;/).flatten(1)[0]}'",
82
+ b2_coef: f.scan(/^2\..*?коэф\.\ (.*?)\(/).flatten(1)[0].gsub(',','.'),
83
+ b2_kind: "'#{f.scan(/^2\..*\((.*?)\/\//).flatten(1)[0]}'",
84
+ b2_game: "'#{f.scan(/^2\..*?\/\/\ (.*?)\)/).flatten(1)[0]}'",
85
+ b2_link: "'#{f.scan(/^2\..*\n(http.*?)$/).flatten(1)[0]}'"
86
+ }
87
+ end
88
+ end
89
+
90
+ def translator
91
+ # Чтение исходного кода
92
+ text = File.open("./examples/test.rules", "r").read
93
+ # Удаление комментариев
94
+ text.gsub!(/\-\-.*\n/,'')
95
+ # Разделение на слова
96
+ input = text.split
97
+
98
+ p = 0
99
+ while p < input.length do
100
+ context = @lexems[input[p]]
101
+ return if context.nil?
102
+ i = 0
103
+ name = ''
104
+ while i < context.length
105
+ case context[i]
106
+ when :name
107
+ name = input[p+=1]
108
+ @names[name] = ''
109
+ i+=1
110
+ when :bind_name
111
+ if name.empty?
112
+ name = input[p+=1]
113
+ i+=1
114
+ else
115
+ @binds << [name, input[p+=1]]
116
+ i+=1
117
+ p+=1
118
+ end
119
+ when :text
120
+ if input[p+=1] =~ /КОНЕЦ_.*?/
121
+ @lang_map.each { |k,v| @names[name].gsub!(Regexp.new(k),v) }
122
+ i += 1
123
+ else
124
+ @names[name] << ' ' + input[p]
125
+ end
126
+ when :end
127
+ p+=1
128
+ i+=1
129
+ else
130
+ puts "error i=#{i} p=#{p}"
131
+ return
132
+ end
133
+ end
134
+ end
135
+ end
136
+
137
+ def exec
138
+ @records.each do |r|
139
+ @binds.each do |b|
140
+ variables = r.map { |k,v| "$" + k.to_s + "=" + v.to_s + ";" }.flatten(1).join
141
+
142
+ text = <<EOF
143
+ #{variables}
144
+ def ff_goto(str)
145
+ @ff.goto(str)
146
+ end
147
+
148
+ def ff_click(str)
149
+ eval "@ff.wait_until{@ff.\#{str}.exists?};@ff.\#{str}.click"
150
+ end
151
+
152
+ def ff_set(str, value)
153
+ eval "@ff.wait_until{@ff.\#{str}.exists?};@ff.\#{str}.set(\#{value})"
154
+ end
155
+
156
+ def ff_get(str, name)
157
+ eval "@ff.wait_until{@ff.\#{str}.exists?};@ff.\#{str}.\#{name}"
158
+ end
159
+
160
+ результат = FALSE;
161
+ begin
162
+ #{@names[b[0]]}
163
+ end
164
+ if результат
165
+ #{@names[b[1]]}
166
+ end
167
+ EOF
168
+ eval text
169
+ end
170
+ return
171
+ end
172
+ end
173
+ public
174
+ def run
175
+ translator
176
+ read_data
177
+ exec
178
+ end
179
+ end
180
+ # Your code goes here...
181
+ end
182
+
183
+ processor = Bets::Processor.new
184
+ processor.run
185
+
186
+ #bets = Bets::Parse.new()
187
+ #bets.parse
@@ -0,0 +1,2 @@
1
+ adapter: sqlite3
2
+ database: lib/db/bets.sqlite3
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_record'
4
+ require 'yaml'
5
+ require 'logger'
6
+
7
+ dbconfig = YAML::load(File.open(File.join(File.dirname(__FILE__), 'database.yml')))
8
+ ActiveRecord::Base.logger = Logger.new(STDERR)
9
+ ActiveRecord::Base.establish_connection(dbconfig)
Binary file
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ class CreateUrls < ActiveRecord::Migration
4
+ def self.up
5
+ create_table :urls do |t|
6
+ t.string :url
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :urls
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - anonymous
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Gem for get data from bets
15
+ email:
16
+ - anonymous@gmail.com
17
+ executables:
18
+ - bets
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bets.gemspec
28
+ - bin/bets
29
+ - lib/bets.rb
30
+ - lib/bets/version.rb
31
+ - lib/config/database.yml
32
+ - lib/config/environment.rb
33
+ - lib/db/bets.sqlite3
34
+ - lib/db/migrate/001_create_urls.rb
35
+ homepage: ''
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Parser for bets
59
+ test_files: []