gettc 1.4 → 1.5

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: 60c1445699b1e6f8a76afbe8abae2037ce70b2a9
4
- data.tar.gz: 40efda2730b2655a7c7bf3c22c418052afa4b640
3
+ metadata.gz: ce198ab839b5f78ae035a774c6294bd1d8378807
4
+ data.tar.gz: 5d0295e172711215ef34efa74b95a03701b9e308
5
5
  SHA512:
6
- metadata.gz: c4853d10fbf7c4c628cb4046f6672c38f7eaec88c21975c35eef10f0b8a812b6f41790228db0b4ad60ee875575e097f0c005dd546839b83403de8f494f3e99c3
7
- data.tar.gz: 0976b9ec10c389974383ed00d272f1509eb63c89af202348e77d3e75707799e6c4d7f8e44f36745bc98c3a822863d5a0b2bd08d26fdafdb0e1efea4dbe8d1944
6
+ metadata.gz: bdee525b1578930dc32be932897b8cbf29cb9bdcbf2463a748772d4aef35b1420ebd0e87964105980b3d80aedb0151898b957b9cbbb67a31997a2ec668b1a127
7
+ data.tar.gz: 6675ce735256bf4b6d9ae8485fb6d9b35fda904e36198a31d11a9a47f84b6b4564cca507216907f31c07df55316d94c35160aa4600a45aa5692ecc78515cd505
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ spec = Gem::Specification.new do |s|
13
13
  s.name = 'gettc'
14
14
  s.summary = 'TopCoder offline arena supporting multiple languages'
15
15
  s.description = 'Given a TopCoder problem ID, gettc downloads the problem specification, parses the whole thing into a Markdown file, generates inputs/outputs based on the Examples and System Tests given, and finally generates basic solution files for you to get started.'
16
- s.version = '1.4'
16
+ s.version = '1.5'
17
17
 
18
18
  s.author = 'Seri'
19
19
  s.email = 'seritrinh@gmail.com'
data/bin/gettc CHANGED
File without changes
@@ -1,6 +1,7 @@
1
1
  require 'net/https'
2
2
  require 'cgi'
3
3
  require 'uri'
4
+ require 'ostruct'
4
5
 
5
6
  module TopCoder
6
7
  class Account
@@ -35,8 +36,38 @@ module TopCoder
35
36
  LIMIT = 10
36
37
  def initialize account
37
38
  @account = account
39
+ @proxy = get_proxy
38
40
  @raw = get_cookie
39
41
  end
42
+ def get_proxy
43
+ uri = URI.parse ENV['http_proxy']
44
+ proxy = OpenStruct.new
45
+ proxy.host, proxy.port = uri.host, uri.port
46
+ if uri.userinfo then
47
+ proxy.user, proxy.pass = uri.userinfo.split /:/
48
+ else
49
+ proxy.user, proxy.pass = nil, nil
50
+ end
51
+ return proxy
52
+ rescue URI::InvalidURIError
53
+ return nil
54
+ end
55
+ def connect uri
56
+ if @proxy.nil? then
57
+ Net::HTTP.start(uri.host, uri.port) do |http|
58
+ yield http
59
+ end
60
+ else
61
+ Net::HTTP.start(uri.host, uri.port, @proxy.host, @proxy.port,
62
+ @proxy.user, @proxy.pass) do |http|
63
+ begin
64
+ yield http
65
+ rescue Errno::ECONNRESET
66
+ raise DownloadError.new "Check the http_proxy environmental variable"
67
+ end
68
+ end
69
+ end
70
+ end
40
71
  def get_cookie
41
72
  uri = URI.join(ROOT, 'tc?&module=Login')
42
73
 
@@ -45,8 +76,9 @@ module TopCoder
45
76
  'password' => @account.password,
46
77
  'rem' => 'on' })
47
78
 
48
- http = Net::HTTP.new uri.host, uri.port
49
- res = http.request req
79
+ res = connect uri do |http|
80
+ http.request req
81
+ end
50
82
  raw = res['set-cookie']
51
83
 
52
84
  cookie = CGI::Cookie.parse raw
@@ -61,20 +93,22 @@ module TopCoder
61
93
  unless uri.is_a? URI then
62
94
  uri = url.start_with?('http') ? URI.parse(url) : URI.join(ROOT, url)
63
95
  end
64
- LIMIT.times do
65
- req = Net::HTTP::Get.new uri.request_uri
66
- req['cookie'] = @raw
67
96
 
68
- http = Net::HTTP.new uri.host, uri.port
69
- res = http.request req
70
-
71
- return res.body if res.is_a? Net::HTTPSuccess
72
- unless res.is_a? Net::HTTPMovedPermanently then
73
- raise DownloadError.new res.class.to_s
97
+ connect uri do |http|
98
+ LIMIT.times do
99
+ req = Net::HTTP::Get.new uri.request_uri
100
+ req['cookie'] = @raw
101
+ res = http.request req
102
+
103
+ return res.body if res.is_a? Net::HTTPSuccess
104
+ unless res.is_a? Net::HTTPMovedPermanently then
105
+ raise DownloadError.new res.class.to_s
106
+ end
107
+ uri = URI.parse res['location']
74
108
  end
75
- uri = URI.parse res['location']
76
- end
77
- raise DownloadError.new "Tried #{LIMIT} times without success"
109
+
110
+ raise DownloadError.new "Tried #{LIMIT} times without success"
111
+ end
78
112
  end
79
113
  def download_problem id
80
114
  url = "/stat?c=problem_statement&pm=#{id}"
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettc
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.4'
4
+ version: '1.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-24 00:00:00.000000000 Z
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hpricot
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdiscount
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Given a TopCoder problem ID, gettc downloads the problem specification,
@@ -99,12 +99,12 @@ require_paths:
99
99
  - core/lib
100
100
  required_ruby_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '>='
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '>='
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []