ztrening 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/History.txt +4 -0
- data/Manifest.txt +13 -0
- data/README.rdoc +46 -0
- data/Rakefile +25 -0
- data/bin/zt +67 -0
- data/lib/zt/cli.rb +42 -0
- data/lib/ztrening.rb +119 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_helper.rb +3 -0
- data/test/test_zt_cli.rb +14 -0
- data/test/test_ztrening.rb +11 -0
- metadata +115 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
= ztrening
|
2
|
+
|
3
|
+
* http://github.com/bkrsta/ztrening
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
* API za pristup Z-Trening zadatcima
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
usage: zt.rb [refresh, list, find, open]
|
16
|
+
find [string]
|
17
|
+
open [filename] => file mora imati '// zt [ime zadatka]' na 1. liniji
|
18
|
+
|
19
|
+
== INSTALL:
|
20
|
+
|
21
|
+
sudo gem install ztrening
|
22
|
+
|
23
|
+
== LICENSE:
|
24
|
+
|
25
|
+
(The MIT License)
|
26
|
+
|
27
|
+
Copyright (c) 2010 BKrsta
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
30
|
+
a copy of this software and associated documentation files (the
|
31
|
+
'Software'), to deal in the Software without restriction, including
|
32
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
33
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
34
|
+
permit persons to whom the Software is furnished to do so, subject to
|
35
|
+
the following conditions:
|
36
|
+
|
37
|
+
The above copyright notice and this permission notice shall be
|
38
|
+
included in all copies or substantial portions of the Software.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
41
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
42
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
43
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
44
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
45
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
46
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/ztrening'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'ztrening' do
|
14
|
+
self.developer 'BKrsta', 'bkrsta@gmail.com'
|
15
|
+
# self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
+
self.rubyforge_name = self.name # TODO this is default value
|
17
|
+
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'newgem/tasks'
|
21
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
22
|
+
|
23
|
+
# remove_task :default
|
24
|
+
# task :default => [:spec, :features]
|
25
|
+
# ...
|
data/bin/zt
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created on 2010-6-30.
|
4
|
+
# Copyright (c) 2010. All rights reserved.
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/ztrening")
|
8
|
+
# require "zt/cli"
|
9
|
+
|
10
|
+
# Zt::CLI.execute(STDOUT, ARGV)
|
11
|
+
|
12
|
+
include ZtreningM
|
13
|
+
|
14
|
+
USAGE = <<EOS
|
15
|
+
usage: zt.rb [refresh, list, find, open]
|
16
|
+
find [string]
|
17
|
+
open [filename] => file mora imati '// zt [ime zadatka]' na 1. liniji
|
18
|
+
EOS
|
19
|
+
|
20
|
+
@imefromfile_regex = /\/\/ zt (.*)/
|
21
|
+
|
22
|
+
|
23
|
+
if !ARGV[0] || ARGV[0]=='-h' || ARGV[0]=='--help'
|
24
|
+
puts USAGE
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
if ARGV[0] == 'refresh'
|
30
|
+
z = Ztrening.new(:web)
|
31
|
+
puts 'New list downloaded'
|
32
|
+
elsif ARGV[0] == 'open' && ARGV[1]
|
33
|
+
# TODO: maknuti gore const file regex
|
34
|
+
z = Ztrening.new
|
35
|
+
file = File.new(ARGV[1], 'r')
|
36
|
+
prvalin = file.gets
|
37
|
+
if !prvalin.grep @imefromfile_regex
|
38
|
+
puts "Prva linija ne sadrzi ime zadatka"
|
39
|
+
exit
|
40
|
+
else
|
41
|
+
z.lista
|
42
|
+
ime = (prvalin.sub! /\/\/ (zt )?/, '').to_s
|
43
|
+
puts "Ime zadatka iz datoteke: #{ime}"
|
44
|
+
z.find ime
|
45
|
+
puts "z.lista: "
|
46
|
+
z.lista
|
47
|
+
z.find_by_id z.lista[0][0]
|
48
|
+
z.open
|
49
|
+
end
|
50
|
+
elsif ARGV[0] == 'find'
|
51
|
+
if ARGV[1]
|
52
|
+
z = Ztrening.new
|
53
|
+
#z.find ARGV[1..32].join ' '
|
54
|
+
if ARGV[1].grep '.'
|
55
|
+
z.find ARGV[1]
|
56
|
+
z.lista_txt
|
57
|
+
else
|
58
|
+
puts 'Search text nema dovoljno znakova'
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
else
|
62
|
+
# pitaj!
|
63
|
+
end
|
64
|
+
elsif ARGV[0] == 'list'
|
65
|
+
z = Ztrening.new
|
66
|
+
z.lista_txt
|
67
|
+
end
|
data/lib/zt/cli.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Zt
|
4
|
+
class CLI
|
5
|
+
def self.execute(stdout, arguments=[])
|
6
|
+
|
7
|
+
# NOTE: the option -p/--path= is given as an example, and should be replaced in your application.
|
8
|
+
|
9
|
+
options = {
|
10
|
+
:path => '~'
|
11
|
+
}
|
12
|
+
mandatory_options = %w( )
|
13
|
+
|
14
|
+
parser = OptionParser.new do |opts|
|
15
|
+
opts.banner = <<-BANNER.gsub(/^ /,'')
|
16
|
+
This application is wonderful because...
|
17
|
+
|
18
|
+
Usage: #{File.basename($0)} [options]
|
19
|
+
|
20
|
+
Options are:
|
21
|
+
BANNER
|
22
|
+
opts.separator ""
|
23
|
+
opts.on("-p", "--path PATH", String,
|
24
|
+
"This is a sample message.",
|
25
|
+
"For multiple lines, add more strings.",
|
26
|
+
"Default: ~") { |arg| options[:path] = arg }
|
27
|
+
opts.on("-h", "--help",
|
28
|
+
"Show this help message.") { stdout.puts opts; exit }
|
29
|
+
opts.parse!(arguments)
|
30
|
+
|
31
|
+
if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
|
32
|
+
stdout.puts opts; exit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
path = options[:path]
|
37
|
+
|
38
|
+
# do stuff
|
39
|
+
stdout.puts "To update this executable, look in lib/zt/cli.rb"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/ztrening.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
class Array
|
5
|
+
def moj_keys() Hash[*self.collect { |v| [v, true] }.flatten] end
|
6
|
+
end
|
7
|
+
|
8
|
+
module ZtreningM
|
9
|
+
VERSION = '0.0.1'
|
10
|
+
|
11
|
+
class Ztrening
|
12
|
+
def initialize(*opts)
|
13
|
+
@list_fname = 'lista.txt'
|
14
|
+
@cmd_dwl = "wget -q http://z-trening.com/training.php\?all_tasks\=1 -O #{@list_fname}"
|
15
|
+
@link_base = 'http://z-trening.com/tasks.php?show_task=_ID_'
|
16
|
+
|
17
|
+
@lista ||= []
|
18
|
+
@opts = opts.moj_keys
|
19
|
+
|
20
|
+
execerrmsg = "'exec' error! Aborting ..."
|
21
|
+
|
22
|
+
if !@opts[:web].nil?
|
23
|
+
web
|
24
|
+
execout = exec
|
25
|
+
(puts execerrmsg; exit) if execout.nil? || execout.empty?
|
26
|
+
@lista = parse(execout)
|
27
|
+
else
|
28
|
+
if !File.exists? @list_fname
|
29
|
+
puts "Datoteka #{@list_fname} ne postoji, skidam s weba ..."
|
30
|
+
web
|
31
|
+
end
|
32
|
+
execout = exec
|
33
|
+
(puts execerrmsg; exit) if execout.nil? || execout.empty?
|
34
|
+
@lista = parse(execout)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def find(str)
|
39
|
+
puts "Lista je prazna!" if @lista.nil? || @lista.empty?
|
40
|
+
ll ||= []
|
41
|
+
@lista.each do |e|
|
42
|
+
if e[1] =~ /#{str}/
|
43
|
+
ll << e
|
44
|
+
end
|
45
|
+
end
|
46
|
+
@lista = []
|
47
|
+
@lista = ll
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_by_id(id)
|
51
|
+
@lista.detect { |e| id == e[0] }
|
52
|
+
end
|
53
|
+
|
54
|
+
def open
|
55
|
+
puts "Lista je prazna!" if @lista.nil? || @lista.empty?
|
56
|
+
if @lista.count == 1
|
57
|
+
system "open #{link @lista[0][0]}"
|
58
|
+
else
|
59
|
+
puts "Lista ne sadrzi 1 zadatak!"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def lista
|
64
|
+
@lista
|
65
|
+
end
|
66
|
+
|
67
|
+
def lista_txt
|
68
|
+
puts 'Zadatci:'
|
69
|
+
@lista.each { |l| puts "Zadatak: #{l[1]}" }
|
70
|
+
end
|
71
|
+
|
72
|
+
def lista_as_html(*args)
|
73
|
+
opts = args.moj_keys
|
74
|
+
puts '<ul>' if opts[:li]
|
75
|
+
puts '<b>Zadatci:</b>' if opts[:naslov]
|
76
|
+
@lista.each { |l|
|
77
|
+
print '<li>' if opts[:li]
|
78
|
+
print "<a href='#{link(l[0])}'>#{l[1]}</a>"
|
79
|
+
puts if !opts[:li]
|
80
|
+
print "</li>\n" if opts[:li]
|
81
|
+
}
|
82
|
+
puts '</ul>' if opts[:li]
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def link(id)
|
88
|
+
@link_base.sub '_ID_', id
|
89
|
+
end
|
90
|
+
|
91
|
+
def exec
|
92
|
+
t = Thread.new { `#{cmd}` }
|
93
|
+
return t.value.split "\r\n"
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse(exec)
|
97
|
+
lista = []
|
98
|
+
exec.each {|e| lista << e.split(' - ') }
|
99
|
+
return lista
|
100
|
+
end
|
101
|
+
|
102
|
+
def web
|
103
|
+
puts 'Downloading list ...'
|
104
|
+
%x[#{@cmd_dwl}]
|
105
|
+
end
|
106
|
+
|
107
|
+
def cmd
|
108
|
+
# return <<EOS
|
109
|
+
# cat #{@list_fname} | grep ' <a href="tasks.php?show_task=.*>' | sed 's/.* //g' | \
|
110
|
+
# grep -o '[0-9]\\{10\\}.*' | sed -e 's/">/ - /g' -e 's:</a></TD>::g'
|
111
|
+
# EOS
|
112
|
+
return <<EOS
|
113
|
+
cat #{@list_fname} | grep ' <a href="tasks.php?show_task=.*>' | sed 's/.* //g' | \
|
114
|
+
grep -o '[0-9]\\{10\\}.*' | sed -e 's/">/ - /g' -e 's:</a></TD>::g'
|
115
|
+
EOS
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/ztrening.rb'}"
|
9
|
+
puts "Loading ztrening gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_helper.rb
ADDED
data/test/test_zt_cli.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require 'zt/cli'
|
3
|
+
|
4
|
+
class TestZtCli < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Zt::CLI.execute(@stdout_io = StringIO.new, [])
|
7
|
+
@stdout_io.rewind
|
8
|
+
@stdout = @stdout_io.read
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_print_default_output
|
12
|
+
assert_match(/To update this executable/, @stdout)
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ztrening
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- BKrsta
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-30 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rubyforge
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
- 4
|
34
|
+
version: 2.0.4
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: hoe
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 21
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 6
|
49
|
+
- 1
|
50
|
+
version: 2.6.1
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: "* API za pristup Z-Trening zadatcima"
|
54
|
+
email:
|
55
|
+
- bkrsta@gmail.com
|
56
|
+
executables:
|
57
|
+
- zt
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files:
|
61
|
+
- History.txt
|
62
|
+
- Manifest.txt
|
63
|
+
files:
|
64
|
+
- History.txt
|
65
|
+
- Manifest.txt
|
66
|
+
- README.rdoc
|
67
|
+
- Rakefile
|
68
|
+
- bin/zt
|
69
|
+
- lib/zt/cli.rb
|
70
|
+
- lib/ztrening.rb
|
71
|
+
- script/console
|
72
|
+
- script/destroy
|
73
|
+
- script/generate
|
74
|
+
- test/test_helper.rb
|
75
|
+
- test/test_zt_cli.rb
|
76
|
+
- test/test_ztrening.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://github.com/bkrsta/ztrening
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --main
|
84
|
+
- README.rdoc
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project: ztrening
|
108
|
+
rubygems_version: 1.3.7
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: "* API za pristup Z-Trening zadatcima"
|
112
|
+
test_files:
|
113
|
+
- test/test_helper.rb
|
114
|
+
- test/test_zt_cli.rb
|
115
|
+
- test/test_ztrening.rb
|