uva-tools 0.0.1 → 0.0.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/lib/uva-tools/problem.rb +21 -5
- data/lib/uva-tools/user.rb +22 -0
- data/lib/uva-tools/uva-tools.rb +27 -8
- data/lib/uva-tools/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c3615b3d3e8580d5a0bc5b202f0b193989e1aba
|
4
|
+
data.tar.gz: 59fca87b8834319e6034306d4fe54f77b52842bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78c1fb38a554df072af6c853e2ed0b1ce0f2ef1923882bdd3d3ea77c67fdc56f0e1ef9dda434009a9e15e5f7819604bbcc2e36e91be9d9d9508a5ea70481dd25
|
7
|
+
data.tar.gz: e639ce24547767f5c07aa1de554cba287000b0f4718dde267cb25d4187585ad0cdc0f8de6d02a1db4eeb26618934d9977ed22440daf95214bb5d316d125a30cf
|
data/lib/uva-tools/problem.rb
CHANGED
@@ -89,10 +89,8 @@ module UVaTools
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
-
puts "downloaded: #{number}"
|
93
92
|
true
|
94
93
|
else
|
95
|
-
puts "#{number} was already downloaded"
|
96
94
|
false
|
97
95
|
end
|
98
96
|
end
|
@@ -106,9 +104,9 @@ module UVaTools
|
|
106
104
|
end
|
107
105
|
end
|
108
106
|
end
|
109
|
-
|
107
|
+
true
|
110
108
|
else
|
111
|
-
|
109
|
+
false
|
112
110
|
end
|
113
111
|
end
|
114
112
|
|
@@ -116,9 +114,27 @@ module UVaTools
|
|
116
114
|
File.directory?(dir_name) && (File.exists?("#{dir_name}/#{number}.html") || File.exists?("#{dir_name}/#{number}.pdf"))
|
117
115
|
end
|
118
116
|
|
117
|
+
def open
|
118
|
+
if f_path = path
|
119
|
+
`open #{f_path}`
|
120
|
+
true
|
121
|
+
else
|
122
|
+
puts "Problem not downloaded!"
|
123
|
+
false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
119
127
|
private
|
120
128
|
def dir_name
|
121
|
-
"#{
|
129
|
+
"#{UVaTools::ROOT_DIR}/#{number/100}"
|
130
|
+
end
|
131
|
+
|
132
|
+
def path
|
133
|
+
if downloaded?
|
134
|
+
"#{dir_name}/#{number}.#{File.exists?("#{dir_name}/#{number}.html") ? 'html' : 'pdf'}"
|
135
|
+
else
|
136
|
+
nil
|
137
|
+
end
|
122
138
|
end
|
123
139
|
end
|
124
140
|
end
|
data/lib/uva-tools/user.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
module UVaTools
|
2
2
|
class User
|
3
|
+
def self.load(username)
|
4
|
+
if File.directory?(UVaTools::USER_SAVE_LOCATION) && File.exists?("#{UVaTools::USER_SAVE_LOCATION}/#{username}")
|
5
|
+
Marshal.load(File.binread("#{UVaTools::USER_SAVE_LOCATION}/#{username}"))
|
6
|
+
else
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
def initialize(username)
|
4
12
|
@username = username
|
5
13
|
end
|
@@ -35,6 +43,12 @@ module UVaTools
|
|
35
43
|
self
|
36
44
|
end
|
37
45
|
|
46
|
+
def save
|
47
|
+
FileUtils::mkdir_p UVaTools::USER_SAVE_LOCATION
|
48
|
+
File.open("#{UVaTools::USER_SAVE_LOCATION}/#{@username}", 'w') {|f| f.write(Marshal.dump(self))}
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
38
52
|
private
|
39
53
|
def uid
|
40
54
|
@uid ||= begin
|
@@ -76,5 +90,13 @@ module UVaTools
|
|
76
90
|
def unsolved_pids
|
77
91
|
UVaTools.problems.map(&:id) - solved_pids
|
78
92
|
end
|
93
|
+
|
94
|
+
def marshal_load array
|
95
|
+
@uid, @username, @solved_pids = array
|
96
|
+
end
|
97
|
+
|
98
|
+
def marshal_dump
|
99
|
+
[uid, @username, solved_pids]
|
100
|
+
end
|
79
101
|
end
|
80
102
|
end
|
data/lib/uva-tools/uva-tools.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
module UVaTools
|
2
|
+
ROOT_DIR = "#{ENV['HOME']}/uva-tools"
|
3
|
+
SAVE_LOCATION = "#{ROOT_DIR}/save"
|
4
|
+
USER_SAVE_LOCATION = "#{ROOT_DIR}/save/user"
|
5
|
+
|
2
6
|
class << self
|
3
7
|
def problems
|
4
8
|
problem_hash.values
|
@@ -14,13 +18,30 @@ module UVaTools
|
|
14
18
|
h
|
15
19
|
end
|
16
20
|
|
21
|
+
def save
|
22
|
+
FileUtils::mkdir_p UVaTools::SAVE_LOCATION
|
23
|
+
File.open("#{UVaTools::SAVE_LOCATION}/problems", 'w') {|f| f.write(Marshal.dump(problem_hash))}
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def load
|
28
|
+
if File.directory?(UVaTools::SAVE_LOCATION) && File.exists?("#{UVaTools::SAVE_LOCATION}/problems")
|
29
|
+
@@problems = Marshal.load(File.binread("#{UVaTools::SAVE_LOCATION}/problems"))
|
30
|
+
true
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
17
36
|
def download_multiple(prob_nums, worker_count = 4)
|
18
37
|
to_download = Array(prob_nums).map do |prob_num|
|
19
38
|
problems_by_number[prob_num]
|
20
39
|
end
|
21
40
|
|
22
|
-
|
23
|
-
|
41
|
+
length = to_download.length
|
42
|
+
|
43
|
+
if length > 0
|
44
|
+
worker_count = [worker_count, length].min
|
24
45
|
workers = []
|
25
46
|
|
26
47
|
worker_count.times do
|
@@ -34,20 +55,18 @@ module UVaTools
|
|
34
55
|
finished = 0
|
35
56
|
|
36
57
|
loop do
|
37
|
-
break if finished >=
|
58
|
+
break if finished >= length
|
38
59
|
|
39
60
|
ready = IO.select(reads, writes)
|
40
61
|
|
41
62
|
ready[0].each do |readable|
|
42
|
-
|
43
|
-
# assets.merge! data["assets"]
|
44
|
-
# files.merge! data["files"]
|
45
|
-
# paths_with_errors.merge! data["errors"]
|
63
|
+
number = Marshal.load(readable)
|
46
64
|
finished += 1
|
65
|
+
puts "(#{finished}/#{length}) Finished: #{number}"
|
47
66
|
end
|
48
67
|
|
49
68
|
ready[1].each do |write|
|
50
|
-
break if index >=
|
69
|
+
break if index >= length
|
51
70
|
|
52
71
|
Marshal.dump(index, write)
|
53
72
|
index += 1
|
data/lib/uva-tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uva-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Allie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Set of UVa Online tools
|
14
14
|
email: dave@daveallie.com
|