code4lib-vote-notifier 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f3f2979ce33c13c90d2320d9bef380c7b0133665
4
+ data.tar.gz: 93aaea64daf52066249fca6c02d07d0d0427f69d
5
+ SHA512:
6
+ metadata.gz: c04c26cc3cc1f32e688ec9856b48b340c80b80b3336e4fb1e29aa585257aeec4f9cb4fdfd0d86d5f055802e67b163701ab9ce89640366f7818765544f50e57b3
7
+ data.tar.gz: 56c43912355868052f85c04a00802119088678e021beee928550f05c7861067a365b855eba3679ef5d8a6d65eb5c6f4d32e121ef7675b1a988e7a3baaca57571
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in code4lib-vote-notifier.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ code4lib-vote-notifier (0.0.1)
5
+ httpclient
6
+ json
7
+ slop
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ httpclient (2.5.3.2)
13
+ json (1.8.1)
14
+ rake (10.3.2)
15
+ slop (3.6.0)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler (~> 1.6)
22
+ code4lib-vote-notifier!
23
+ rake (~> 10.0)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 North Carolina State University
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Code4Lib Vote Notifier
2
+
3
+ Save your F5 key for tracking packages and get desktop notifications to find out where your talk is in the vote.
4
+
5
+ ## Usage
6
+
7
+ 1. Download the script and make it executable.
8
+ 2. Install the required gems.
9
+ 3. `code4lib-vote --help`
10
+
11
+
12
+ ## TODO
13
+ - Trottle notifications to only show them when something has changed or a threshold is passed
14
+ - Allow to work on Mac
15
+ - Package as a gem
16
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/ballot-box.png ADDED
Binary file
data/bin/code4lib-vote ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # To add this to cron do something like this to use the ruby wrapper script:
4
+ # */15 8-17 * * 1-5 env DISPLAY=:0.0 /home/jnronall/.rvm/wrappers/ruby-2.1.1/ruby /home/jnronall/bin/code4lib-vote > $HOME/tmp/code4lib-vote-cron.log 2>&1
5
+
6
+ require 'httpclient'
7
+ require 'json'
8
+ require 'slop'
9
+
10
+ require 'date'
11
+ require 'fileutils'
12
+
13
+ begin
14
+ case RUBY_PLATFORM
15
+ when /darwin/
16
+ require 'terminal-notifier'
17
+ platform = 'mac'
18
+ when /linux/
19
+ require 'libnotify'
20
+ platform = 'linux'
21
+ # when /win32/
22
+ # require 'YKK'
23
+ end
24
+ rescue LoadError
25
+ puts "You must have the proper gems installed.\nLinux: libnotify\nMac: terminal-notifier"
26
+ exit
27
+ end
28
+
29
+ opts = Slop.parse do
30
+ banner <<EOF
31
+ Usage: code4lib-vote --vote 33 --mytalk 655 --top 20 --timeout 60 --icon /home/jnronall/bin/images/ballot-box.png
32
+ EOF
33
+
34
+ on 'vote=', 'Number identifying vote', as: Integer, default: 33
35
+ on 'mytalk=', 'Number identifying your talk', as: Integer, default: 655
36
+ on 'top=', 'Number of results to show in notification', as: Integer, default: 20
37
+ on 'timeout=', 'Number of seconds to show the desktop notification for', as: Integer, default: 60
38
+ on 'icon=', 'Path to the icon to show in the notification area', as: String, default: '/home/jnronall/bin/images/ballot-box.png'
39
+ on 'h', 'help', 'Show this help message'
40
+ end
41
+
42
+ if opts[:help]
43
+ puts opts
44
+ exit
45
+ end
46
+
47
+ http = HTTPClient.new
48
+ response = http.get "http://vote.code4lib.org/election/results/#{opts[:vote]}.json"
49
+ results = JSON.parse(response.body)
50
+
51
+ ordered_results = results.sort_by{|talk| talk['score']}.reverse
52
+
53
+ rank = nil
54
+ score = nil
55
+ talks_list = []
56
+ ordered_results.each_with_index do |talk, index|
57
+ title = talk['title'].slice(0,30)
58
+ if talk['id'] == opts[:mytalk]
59
+ rank = index + 1
60
+ score = talk['score']
61
+ title = "<b>#{title}</b>"
62
+ end
63
+ talks_list << "#{talk['score']} #{title}"
64
+ end
65
+
66
+ top_talks = talks_list.slice(0,opts[:top])
67
+
68
+ message = %Q|<a href="http://vote.code4lib.org/election/results/#{opts[:vote]}">Code4Lib Vote</a>|
69
+ message << "\nRANK: #{rank}\nscore: #{score}\nhigh score: #{ordered_results.first['score']}\n\n"
70
+
71
+ top_ten = top_talks.slice(0,10)
72
+ top_rest = top_talks.slice(10,top_talks.length)
73
+ message << top_ten.join("\n\n")
74
+ message << "\n\n--------------\n\n"
75
+ message << top_rest.join("\n\n")
76
+
77
+ puts message
78
+
79
+ case platform
80
+ when 'linux'
81
+ Libnotify.show(:body => message, :timeout => opts[:timeout], icon_path: opts[:icon])
82
+ when 'mac'
83
+ `terminal-notifier -message "#{message}" -appIcon #{opts[:icon]} -title "Code4Lib Vote" -url "http://vote.code4lib.org/election/results/#{opts[:vote]}"`
84
+ end
85
+
86
+ logfile = File.expand_path('~/tmp/code4lib-vote.log')
87
+ FileUtils.mkdir_p logfile unless File.exist? logfile
88
+
89
+ File.open(logfile, 'a') do |fh|
90
+ fh.puts DateTime.now.to_s
91
+ fh.puts message
92
+ fh.puts "\n----------------\n"
93
+ end
94
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'code4lib/vote/notifier/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "code4lib-vote-notifier"
8
+ spec.version = Code4lib::Vote::Notifier::VERSION
9
+ spec.authors = ["Jason Ronallo"]
10
+ spec.email = ["jronallo@gmail.com"]
11
+ spec.summary = %q{Get desktop notifications for Code4Lib votes}
12
+ spec.description = %q{Get desktop notifications for Code4Lib votes}
13
+ spec.homepage = "https://github.com/jronallo/code4lib-vote-notifier"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httpclient"
22
+ spec.add_dependency "json"
23
+ spec.add_dependency "slop"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,9 @@
1
+ require "code4lib/vote/notifier/version"
2
+
3
+ module Code4lib
4
+ module Vote
5
+ module Notifier
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Code4lib
2
+ module Vote
3
+ module Notifier
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: code4lib-vote-notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason Ronallo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: slop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Get desktop notifications for Code4Lib votes
84
+ email:
85
+ - jronallo@gmail.com
86
+ executables:
87
+ - code4lib-vote
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - MIT-LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - ballot-box.png
97
+ - bin/code4lib-vote
98
+ - code4lib-vote-notifier.gemspec
99
+ - lib/code4lib/vote/notifier.rb
100
+ - lib/code4lib/vote/notifier/version.rb
101
+ homepage: https://github.com/jronallo/code4lib-vote-notifier
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Get desktop notifications for Code4Lib votes
125
+ test_files: []
126
+ has_rdoc: