uva-tools 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 600ae5264d13d0c083a5ad143e01f6cd5cd3b180
4
- data.tar.gz: c13486119816dc8ad210072915efac90142d6256
3
+ metadata.gz: 9c3615b3d3e8580d5a0bc5b202f0b193989e1aba
4
+ data.tar.gz: 59fca87b8834319e6034306d4fe54f77b52842bf
5
5
  SHA512:
6
- metadata.gz: 5d565deb6a25120c1f19a66d640f7e060055b28ba31a6abc1ee01457ff0c5da25bf08b9678e51f309ca0c9be57fb05a7329f296e3b125638b4853711c63c9e86
7
- data.tar.gz: 55be55d88c394e2570361d3508dcc506a626308f55fdc0136968ca98beed12bc8a2efa1c52cda3d9af0055b876a84a299194eb627eae2f9468d4d33657dd1d20
6
+ metadata.gz: 78c1fb38a554df072af6c853e2ed0b1ce0f2ef1923882bdd3d3ea77c67fdc56f0e1ef9dda434009a9e15e5f7819604bbcc2e36e91be9d9d9508a5ea70481dd25
7
+ data.tar.gz: e639ce24547767f5c07aa1de554cba287000b0f4718dde267cb25d4187585ad0cdc0f8de6d02a1db4eeb26618934d9977ed22440daf95214bb5d316d125a30cf
@@ -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
- puts "removed #{number}"
107
+ true
110
108
  else
111
- puts "#{number} wasn't downloaded"
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
- "#{ENV['HOME']}/uva-tools/#{number/100}"
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
@@ -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
@@ -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
- if to_download.length > 0
23
- worker_count = [worker_count, to_download.length].min
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 >= to_download.size
58
+ break if finished >= length
38
59
 
39
60
  ready = IO.select(reads, writes)
40
61
 
41
62
  ready[0].each do |readable|
42
- data = Marshal.load(readable)
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 >= to_download.size
69
+ break if index >= length
51
70
 
52
71
  Marshal.dump(index, write)
53
72
  index += 1
@@ -1,3 +1,3 @@
1
1
  module UVaTools
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
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.1
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-05 00:00:00.000000000 Z
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