uwace 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/uwace +31 -39
  2. metadata +4 -4
data/bin/uwace CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby -rubygems
2
2
 
3
3
  require 'mechanize'
4
- require 'net/https'
5
4
  require 'highline/import'
6
5
  require 'uri'
7
6
  require 'fileutils'
@@ -52,13 +51,6 @@ class AngelAccess
52
51
  li_node.css('div.title a').children.find{|c| c.class == Nokogiri::XML::Text}.content
53
52
  end
54
53
 
55
- def get_download_path(page_url)
56
- dl_page = @agent.get((@agent.get page_url).iframes.first.src)
57
- dl_page.link_with(:href => /AngelUploads/).href
58
- rescue NoMethodError
59
- nil
60
- end
61
-
62
54
  def dir_sanitize(dirname)
63
55
  dirname.gsub(/[^a-zA-Z0-9 _]/,'').strip
64
56
  end
@@ -103,44 +95,44 @@ class AngelAccess
103
95
  dir_tree.each do |node|
104
96
  if node[:type] == 'file'
105
97
 
106
- download_path = get_download_path node[:url]
98
+ dl_page = @agent.get(node[:url])
107
99
 
108
- if download_path.nil?
109
- puts "%s- %s - Failed (Skipping...)".color(:red) % ["\t" * depth, node[:name]]
110
- next
100
+ unless dl_page.class == Mechanize::File
101
+ dl_page = @agent.get(dl_page.iframes.first.src)
111
102
  end
112
-
113
- basename = File.basename(download_path)
114
- save_path = File.join(basedir, basename)
115
-
116
- print "%s- %s - " % ["\t" * depth, basename]
117
103
 
118
- if File.exists? save_path
119
- puts "Skipping...".color(:yellow)
120
- next
121
- else
122
- print "Saving... "
104
+ unless dl_page.class == Mechanize::File
105
+ dl_link = dl_page.link_with(:href => /AngelUploads/)
106
+ if dl_link.nil?
107
+ puts "%s- %s - No download link (Skipping...)".color(:red) % ["\t" * depth, node[:name]]
108
+ next
109
+ end
110
+
111
+ basename = File.basename(dl_link.href)
112
+ save_path = File.join(basedir,basename)
113
+
114
+ if File.exists? save_path
115
+ puts "%s- %s - Already saved (Skipping...)".color(:yellow) % ["\t" * depth, basename]
116
+ next
117
+ else
118
+ dl_page = dl_link.click
119
+ end
123
120
  end
124
121
 
125
- uri = URI.parse("https://uwangel.uwaterloo.ca")
126
- https = Net::HTTP.new(uri.host, uri.port)
127
- https.use_ssl = true
128
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
129
-
130
- request = Net::HTTP::Get.new(uri.request_uri)
131
-
132
- begin
133
- response = https.request(request)
134
- rescue
135
- puts "Failed.".color(:red)
136
- next
137
- end
138
-
139
- open(save_path,"wb") do |file|
140
- file.write(response.body)
122
+ if dl_page.class != Mechanize::File
123
+ puts "%s- %s - Not a file (Skipping...)" % ["\t" * depth, node[:name]]
124
+ else
125
+ basename = File.basename(dl_page.filename)
126
+ save_path = File.join(basedir,basename)
127
+
128
+ if File.exists? save_path
129
+ puts "%s- %s - Already saved (Skipping...)".color(:yellow) % ["\t" * depth, basename]
130
+ else
131
+ dl_page.save_as save_path
132
+ puts "%s- %s - Saved.".color(:green) % ["\t" * depth, basename]
133
+ end
141
134
  end
142
135
 
143
- puts "Done.".color(:green)
144
136
  elsif node[:type] == 'folder'
145
137
  puts "%s+ %s".color(:cyan) % ["\t" * depth, node[:name]]
146
138
  download_tree(node[:children],File.join(basedir, dir_sanitize(node[:name])),depth+1)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uwace
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jamie Wong
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-09 00:00:00 -05:00
18
+ date: 2010-11-10 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency