cricket_score_notifier 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e105d1bc19a0e7fe3a9c1e3585463ad129f53464
4
+ data.tar.gz: ebc9722b2cbb041e446b218156c86f294a1745d1
5
+ SHA512:
6
+ metadata.gz: 2a7134ca25a1a0e97e695d2aa30a49764afaf6b53f722945fd743bbdef91404583e083ca0c34de348aef2d1fd47ff2972358e2b17d323b670166f289362896a8
7
+ data.tar.gz: ae7137a9173a46e9b33a867952398e20514f271d86b587d73cb0040747c4dae9f8b28ea93af0d2d71d0c6990ed57cd514f26b3efee1470fcac5416a3aef483d5
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ *.DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at absk1317@gmail.com or rohit.patel061@gmail.com.
59
+ All complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cricket_score_notifier.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 abhishek verma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # CricketScoreNotifier
2
+ [![Build Status](https://api.travis-ci.org/absk1317/cricket-score-notifier.svg?branch=master)](http://travis-ci.org/absk1317/cricket-score-notifier)
3
+
4
+ CricketScoreNotifier is a gem which answers the following question:
5
+
6
+ Wouldn't it be cool to get desktop notifications of live cricket scores?
7
+
8
+ CricketScoreNotifier answer this questions, by providing live score notifications right on your desktop with an interval and match of your choice.
9
+
10
+ To get started please follow below steps:
11
+
12
+
13
+ ## Installation
14
+
15
+ $ gem install cricket_score_notifier
16
+
17
+ ## Usage
18
+
19
+ $ cricket_score_notifier
20
+
21
+ CricketScoreNotifier will prompt you with a list of ongoing matches e.g.
22
+
23
+ To get live notifications, please select a match from following list:
24
+ Press 0 for:Hyderabad (India) 280/10 & 201/10 * v Mumbai 294/10 & 217/10
25
+ Press 1 for:Gujarat 623/9 & 263/10 * v Odisha 199/10
26
+ Press 2 for:Australia v Pakistan 310/6 *
27
+ Press 3 for:Lankan Cricket Club 428/10 v Kalutara Physical Culture Club 22/2 *
28
+ Press 4 for:South Africa 267/6 * v Sri Lanka
29
+ Press 5 for:Brisbane Heat Women 129/5 v Melbourne Stars Women 124/6 *
30
+ Press 6 for:Sydney Thunder Women 96/2 * v Melbourne Renegades Women 93/6
31
+ Press 7 for:Dhaka Metropolis 155/5 * v Barisal Division
32
+ Press 8 for:Khulna Division v Dhaka Division 113/2 *
33
+ Press 9 for:Rajshahi Division v Chittagong Division 107/4 *
34
+ Press 10 for:Rangpur Division v Sylhet Division 83/4 *
35
+ Press 11 for:Adelaide Strikers Women v Hobart Hurricanes Women
36
+ Press 12 for:Sydney Sixers v Perth Scorchers
37
+
38
+ Input your match choice for which you want live notifications.
39
+
40
+ After selecting a match CricketScoreNotifier will ask you for an updates frequency input i.e the time interval at which you want CricketScoreNotifier to provide you desktop notifications.
41
+
42
+ Input the frequency in seconds format and you're all set, you don't need to repeatedly go to your browser tab for checking cricket scores anymore as you can have live updates right on the desktop itself.
43
+
44
+ Any suggestions/features/ideas are most welcome!
45
+
46
+ ## Contributors
47
+ The current core team consists of:
48
+ * [Abhishek Verma](https://github.com/absk1317)
49
+ * [Rohit Patel](https://github.com/rohitcy)
50
+
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/absk1317/cricket_score_notifier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
55
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
60
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cricket_score_notifier"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cricket_score_notifier"
5
+ require "cricket_score_notifier/live_matches_feed_parser"
6
+ require "cricket_score_notifier/live_scores_parser"
7
+ require "cricket_score_notifier/notification"
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ CricketScoreNotifier.notify
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
@@ -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 'cricket_score_notifier/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cricket_score_notifier"
8
+ spec.version = CricketScoreNotifier::VERSION
9
+ spec.authors = ["abhishek verma", "rohit patel"]
10
+ spec.email = ["absk1317@gmail.com", "rohit.patel061@gmail.com"]
11
+
12
+ spec.summary = "Provides a realtime notification of ongoing cricket matches."
13
+ spec.homepage = "https://github.com/absk1317/cricket-score-notifier"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split("\n")
17
+ #spec.bindir = "exe"
18
+ spec.executables = ['cricket_score_notifier']#spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httparty", '~> 0.13.7'
22
+ spec.add_dependency "terminal-notifier", "~> 1.7"
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "pry", "~> 0.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,64 @@
1
+ require 'cricket_score_notifier/version'
2
+ require 'terminal-notifier'
3
+ require 'httparty'
4
+
5
+ module CricketScoreNotifier
6
+ class << self
7
+ def notify
8
+ @live_matches = show_live_matches_tally
9
+ match_choice = user_choice
10
+ frequency = user_match_update_frequency
11
+ puts 'Cool. Now sit back and relax. Hit ctrl+c whenever you want to exit.'
12
+ show_notifications(match_choice, frequency)
13
+ end
14
+
15
+ def show_live_matches_tally
16
+ LiveMatchesFeedParser.live_matches
17
+ end
18
+
19
+ def user_choice
20
+ puts 'No matches are going on currently' and return if @live_matches.empty?
21
+ puts 'To get live notifications, please select a match from following list:'
22
+ @live_matches.each_with_index do |match, index|
23
+ puts "Press #{index} for:" + match['title']
24
+ end
25
+ gets.chomp.to_i
26
+ end
27
+
28
+ def user_match_update_frequency
29
+ puts 'At what interval would like the score updates? (enter in seconds)'
30
+ gets.chomp.to_i
31
+ end
32
+
33
+ def show_notifications(choice, frequency)
34
+ loop do
35
+ @match_status, @live_scores = fetch_live_scores(choice)
36
+ unless @match_status
37
+ TerminalNotifier.notify('Match not started yet.', title: 'Current Status')
38
+ break
39
+ end
40
+ show_score_notification
41
+ sleep 2
42
+ show_status_notification
43
+ sleep frequency
44
+ end
45
+ end
46
+
47
+ def fetch_live_scores(choice)
48
+ match_url = @live_matches[choice]['guid'].gsub("html", "json")
49
+ LiveScoresParser.live_score(match_url)
50
+ end
51
+
52
+ private
53
+
54
+ def show_score_notification
55
+ notification = Notification.new(nil, @live_scores)
56
+ TerminalNotifier.notify(notification.score_message, title: notification.score_title)
57
+ end
58
+
59
+ def show_status_notification
60
+ notification = Notification.new('Current Status', @match_status)
61
+ TerminalNotifier.notify(notification.message, title: notification.title)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,16 @@
1
+ module CricketScoreNotifier
2
+ class LiveMatchesFeedParser
3
+ class << self
4
+ def live_matches
5
+ matches_from_feed = fetch_matches
6
+ end
7
+
8
+ private
9
+
10
+ def fetch_matches
11
+ feed_response = HTTParty.get('http://static.cricinfo.com/rss/livescores.xml')
12
+ matches = feed_response.parsed_response['rss']['channel']['item']
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,45 @@
1
+ module CricketScoreNotifier
2
+ class LiveScoresParser
3
+ class << self
4
+ def live_score(match_url)
5
+ match_details = HTTParty.get(match_url)
6
+ scores = {}
7
+ if match_details['live']['innings'].empty?
8
+ return false, scores
9
+ end
10
+ current_innings = match_details['live']['innings']
11
+ current_status = match_details['live']['status']
12
+ team1_id = match_details['innings'][0]['batting_team_id']
13
+ team2_id = match_details['innings'][0]['bowling_team_id']
14
+ team1 = find_team_name(match_details['team'], team1_id)
15
+ team2 = find_team_name(match_details['team'], team2_id)
16
+ scores[team1] = fetch_team_score(match_details['innings'], team1_id)
17
+ scores[team2] = fetch_team_score(match_details['innings'], team2_id)
18
+ return current_status, scores
19
+ end
20
+ private
21
+
22
+ def find_team_name(both_teams, team_id)
23
+ both_teams.select do |teams|
24
+ teams['team_id'] == team_id
25
+ end.first['team_abbreviation']
26
+ end
27
+
28
+ def fetch_team_score(all_innings, team_id)
29
+ result = []
30
+ all_innings.select do |innings|
31
+ innings['batting_team_id'] == team_id
32
+ end.map do |hash|
33
+ hash.select do |key, value|
34
+ ['runs', 'wickets', 'live_current'].include? key
35
+ end
36
+ end.each do |innings|
37
+ string = innings['runs'] + '/' + innings['wickets']
38
+ string << '*' if innings['live_current'] == '1'
39
+ result.push(string)
40
+ end
41
+ result
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ module CricketScoreNotifier
2
+ class Notification
3
+ attr_accessor :title, :message
4
+
5
+ def initialize(title , message)
6
+ self.title = title
7
+ self.message = message
8
+ end
9
+
10
+ def score_message
11
+ innings_score = message.values
12
+ innings_score[0].zip(*innings_score[1..-1]).map do |innings_score|
13
+ innings_score.join(" ")
14
+ end.join("\n")
15
+ end
16
+
17
+ def score_title
18
+ message.keys.join(" v/s ")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module CricketScoreNotifier
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe CricketScoreNotifier do
4
+ it "has a version number" do
5
+ expect(CricketScoreNotifier::VERSION).not_to be nil
6
+ end
7
+
8
+ it "does something useful" do
9
+ expect(true).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "cricket_score_notifier"
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cricket_score_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - abhishek verma
8
+ - rohit patel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.13.7
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.13.7
28
+ - !ruby/object:Gem::Dependency
29
+ name: terminal-notifier
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.7'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.7'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.13'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.13'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.10'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.10'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.0'
98
+ description:
99
+ email:
100
+ - absk1317@gmail.com
101
+ - rohit.patel061@gmail.com
102
+ executables:
103
+ - cricket_score_notifier
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".rspec"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/console
116
+ - bin/cricket_score_notifier
117
+ - bin/setup
118
+ - cricket_score_notifier.gemspec
119
+ - lib/cricket_score_notifier.rb
120
+ - lib/cricket_score_notifier/live_matches_feed_parser.rb
121
+ - lib/cricket_score_notifier/live_scores_parser.rb
122
+ - lib/cricket_score_notifier/notification.rb
123
+ - lib/cricket_score_notifier/version.rb
124
+ - spec/cricket_score_notifier_spec.rb
125
+ - spec/spec_helper.rb
126
+ homepage: https://github.com/absk1317/cricket-score-notifier
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.5.1
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Provides a realtime notification of ongoing cricket matches.
150
+ test_files: []
151
+ has_rdoc: