rticker 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/rticker CHANGED
@@ -2,5 +2,7 @@
2
2
 
3
3
  require 'rticker/application'
4
4
 
5
+ Thread.abort_on_exception = true
6
+
5
7
  application = RTicker::Application.new(ARGV)
6
- application.run
8
+ application.run
@@ -57,8 +57,11 @@ module RTicker
57
57
  end
58
58
 
59
59
  # Set proxy settings
60
+ system_proxy = RTicker::Net.detect_system_proxy
60
61
  if @options.proxy
61
62
  RTicker::Net.proxy = @options.proxy
63
+ elsif not system_proxy.nil? and not @options.no_proxy
64
+ RTicker::Net.proxy = "#{system_proxy[:host]}:#{system_proxy[:port]}"
62
65
  end
63
66
 
64
67
  # Update entries via web calls until user quits via Ctrl-C
@@ -30,7 +30,7 @@ module RTicker
30
30
  fields = result.split(",")
31
31
  price = fields[1]
32
32
  last_date = fields[2]
33
- return if Date.strptime(last_date, '"%m/%d/%Y"') != Date.today
33
+ return if last_date.nil? or Date.strptime(last_date, '"%m/%d/%Y"') != Date.today
34
34
  if price.to_f != entry.curr_value and not entry.curr_value.nil?
35
35
  # The price has changed
36
36
  entry.last_changed = Time.now()
@@ -57,14 +57,16 @@ module RTicker
57
57
  symbols = entries.map { |e| e.symbol }
58
58
  uri = "http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=l1c1d1va2xj1b4j4dyekjm3m4rr5p5p6s7" % CGI::escape(symbols.join(","))
59
59
  response = RTicker::Net.get_response(uri) rescue return
60
+ return if response.nil?
60
61
  results = response.split("\n")
61
62
  entries.zip(results) do |entry, result|
62
63
  # Yahoo uses A CSV format.
64
+ return if result.nil?
63
65
  fields = result.split(",")
64
66
  price = fields[0]
65
67
  change = fields[1]
66
68
  last_date = fields[2]
67
- return if Date.strptime(last_date, '"%m/%d/%Y"') != Date.today
69
+ return if last_date.nil? or Date.strptime(last_date, '"%m/%d/%Y"') != Date.today
68
70
  if price.to_f != entry.curr_value and not entry.curr_value.nil?
69
71
  # The price has changed
70
72
  entry.last_changed = Time.now()
@@ -71,7 +71,7 @@ module RTicker
71
71
  price = fields[0]
72
72
  change = fields[1]
73
73
  last_date = fields[2]
74
- return if Date.strptime(last_date, '"%m/%d/%Y"') != Date.today
74
+ return if last_date.nil? or Date.strptime(last_date, '"%m/%d/%Y"') != Date.today
75
75
  if price.to_f != _entry.curr_value and not _entry.curr_value.nil?
76
76
  # The price has changed
77
77
  _entry.last_changed = Time.now()
data/lib/rticker/net.rb CHANGED
@@ -26,5 +26,27 @@ module RTicker
26
26
  return ""
27
27
  end
28
28
  end
29
+
30
+ def self.detect_system_proxy ()
31
+ require 'rbconfig'
32
+ os = Config::CONFIG['host_os']
33
+ # Only support mac os x right now
34
+ return detect_system_proxy_macosx() if os.start_with? "darwin"
35
+ return nil
36
+ end
37
+
38
+ def self.detect_system_proxy_macosx ()
39
+ ethernet_enabled = (not %x[networksetup -getinfo ethernet].match(/IP address:/).nil?)
40
+ airport_enabled = (not %x[networksetup -getinfo airport].match(/IP address:/).nil?)
41
+ return nil if not (ethernet_enabled or airport_enabled)
42
+ networkservice = ethernet_enabled ? "ethernet" : "airport"
43
+ webproxy_info = %x[networksetup -getwebproxy #{networkservice}]
44
+ return nil if webproxy_info.match(/Enabled: Yes/).nil?
45
+ host, port, authentication_required = "", "", false
46
+ host = webproxy_info.match(/Server: ([^\n]*)/)[1]
47
+ port = webproxy_info.match(/Port: ([^\n]*)/)[1]
48
+ authentication_required = webproxy_info.match(/Authenticated Proxy Enabled: (0|1)/)[1] == "1"
49
+ return {:host => host, :port => port, :authentication_required => authentication_required}
50
+ end
29
51
  end
30
52
  end
@@ -5,7 +5,7 @@ module RTicker
5
5
  class Options
6
6
 
7
7
  attr_reader :once, :no_color, :input_files
8
- attr_reader :sleep, :rest, :proxy
8
+ attr_reader :sleep, :rest, :proxy, :no_proxy
9
9
 
10
10
  def initialize (args)
11
11
  # Defaults
@@ -13,6 +13,7 @@ module RTicker
13
13
  @no_color = false # Don't use color when showing results to user
14
14
  @input_files = [] # Input files provided by user
15
15
  @proxy = nil # "host:port" proxy
16
+ @no_proxy = false # Don't default to system proxy if one is detected
16
17
  @sleep = 2 # how long to delay between web requests
17
18
  @rest = [] # The rest of the command line arguments
18
19
  parse!(args)
@@ -44,10 +45,14 @@ module RTicker
44
45
  @sleep = secs.to_f
45
46
  end
46
47
 
47
- opts.on("-p", "--proxy HOST:PORT", "Host and port of HTTP proxy to use.") do |proxy|
48
+ opts.on("-p", "--proxy HOST:PORT", "Host and port of HTTP proxy to use. This overrides any system proxy that is detected.") do |proxy|
48
49
  @proxy = proxy
49
50
  end
50
51
 
52
+ opts.on("-x", "--no-proxy", "Don't default to system proxy if one is detected.") do
53
+ @no_proxy = true
54
+ end
55
+
51
56
  opts.on("-h", "--help", "Display this screen") do
52
57
  puts opts
53
58
  exit
data/rticker.gemspec CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
3
3
  s.name = "rticker"
4
4
  s.summary = "Command line-based stock ticker application"
5
5
  s.description = File.read(File.join(File.dirname(__FILE__), 'README'))
6
- s.version = "1.1.2"
6
+ s.version = "1.2.0"
7
7
  s.author = "Alfred J. Fazio"
8
8
  s.email = "alfred.fazio@gmail.com"
9
9
  s.platform = Gem::Platform::RUBY
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rticker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
9
8
  - 2
10
- version: 1.1.2
9
+ - 0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alfred J. Fazio
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-14 00:00:00 -05:00
18
+ date: 2012-02-17 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21