lita-espn-fantasy-football 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +16 -5
- data/README.md +21 -4
- data/lib/lita/handlers/espn_fantasy_football.rb +70 -18
- data/lita-espn-fantasy-football.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99c175e3670dd3dcb56c2e77b13b0fb2100fed68
|
4
|
+
data.tar.gz: ac10980944a301bc48bb50178f283d52d245eeb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9657aab7827d6c474cc986d74441546d762a668a96d3f338d41df3393a31f583b9c45779fd017df9ef8e9952d0b8b418bb5a65ebf1ac36bb669387e48590d524
|
7
|
+
data.tar.gz: 57a9c435392141d7391f99dd9966017c59972856ba319623f790e3cf82ea3b924fcfdb2f13af51f6f34ec680dd6d860df19d084129427d0f95aa53e06509e936
|
data/.rubocop_todo.yml
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2017-09-
|
3
|
+
# on 2017-09-06 02:31:11 -0500 using RuboCop version 0.49.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 1
|
10
|
+
Lint/UselessAssignment:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/lita/handlers/espn_fantasy_football.rb'
|
13
|
+
|
14
|
+
# Offense count: 5
|
10
15
|
Metrics/AbcSize:
|
11
|
-
Max:
|
16
|
+
Max: 69
|
12
17
|
|
13
18
|
# Offense count: 2
|
14
19
|
# Configuration parameters: CountComments, ExcludedMethods.
|
@@ -18,13 +23,13 @@ Metrics/BlockLength:
|
|
18
23
|
# Offense count: 1
|
19
24
|
# Configuration parameters: CountComments.
|
20
25
|
Metrics/ClassLength:
|
21
|
-
Max:
|
26
|
+
Max: 206
|
22
27
|
|
23
28
|
# Offense count: 1
|
24
29
|
Metrics/CyclomaticComplexity:
|
25
30
|
Max: 8
|
26
31
|
|
27
|
-
# Offense count:
|
32
|
+
# Offense count: 4
|
28
33
|
# Configuration parameters: CountComments.
|
29
34
|
Metrics/MethodLength:
|
30
35
|
Max: 48
|
@@ -39,3 +44,9 @@ Metrics/PerceivedComplexity:
|
|
39
44
|
Style/FileName:
|
40
45
|
Exclude:
|
41
46
|
- 'lib/lita-espn-fantasy-football.rb'
|
47
|
+
|
48
|
+
# Offense count: 3
|
49
|
+
# Cop supports --auto-correct.
|
50
|
+
Style/RescueModifier:
|
51
|
+
Exclude:
|
52
|
+
- 'lib/lita/handlers/espn_fantasy_football.rb'
|
data/README.md
CHANGED
@@ -10,17 +10,21 @@ This [Lita](https://www.lita.io/) handler is used to scrape data from ESPN's Fan
|
|
10
10
|
Add lita-espn-fantasy-football to your Lita instance's Gemfile:
|
11
11
|
|
12
12
|
``` ruby
|
13
|
-
gem
|
13
|
+
gem 'lita-espn-fantasy-football'
|
14
14
|
```
|
15
15
|
|
16
16
|
## Configuration
|
17
17
|
|
18
|
-
Set your `league_id`, and optionally `season_id` (defaults to 2017)
|
18
|
+
Set your `league_id`, and optionally `season_id` (defaults to 2017).
|
19
|
+
If you'd like league activity regularly reported, specify an `activity_room`.
|
20
|
+
The interval is configurable via `activity_interval` (defaults to 15 minutes).
|
19
21
|
|
20
22
|
```ruby
|
21
23
|
Lita.configure do |config|
|
22
|
-
config.handlers.espn_fantasy_football.league_id =
|
23
|
-
config.handlers.espn_fantasy_football.season_id =
|
24
|
+
config.handlers.espn_fantasy_football.league_id = '123456'
|
25
|
+
config.handlers.espn_fantasy_football.season_id = '2017'
|
26
|
+
config.handlers.espn_fantasy_football.activity_room = 'general'
|
27
|
+
config.handlers.espn_fantasy_football.activity_interval = 900
|
24
28
|
end
|
25
29
|
```
|
26
30
|
|
@@ -83,3 +87,16 @@ Lita: score 3
|
|
83
87
|
| | |
|
84
88
|
+-------------------------------+-------+
|
85
89
|
```
|
90
|
+
|
91
|
+
### See recent league activity
|
92
|
+
|
93
|
+
See recent trades, adds, drops, etc.
|
94
|
+
|
95
|
+
```
|
96
|
+
Lita: activity
|
97
|
+
|
98
|
+
:wrench: Renamed team The Prime Rib Special to The SubPrime Rib Special.
|
99
|
+
:green_heart: REED added *Kai Forbath*, NO K from Free Agency to Bench
|
100
|
+
:broken_heart: REED dropped *Martellus Bennett*, Chi TE to Waivers
|
101
|
+
|
102
|
+
```
|
@@ -9,6 +9,10 @@ module Lita
|
|
9
9
|
# configs
|
10
10
|
config :league_id, required: true
|
11
11
|
config :season_id, default: '2017'
|
12
|
+
config :activity_room
|
13
|
+
config :activity_interval, default: 60 * 15 # Fifteen minutes
|
14
|
+
|
15
|
+
on :connected, :activity_timer
|
12
16
|
|
13
17
|
# routes
|
14
18
|
route(/^player\s+(.+)/, :command_player, command: true, help: {
|
@@ -19,10 +23,9 @@ module Lita
|
|
19
23
|
'score WEEK' => 'Replies with the scoreboard for the specified week. If WEEK is empty, the current scoreboard is returned'
|
20
24
|
})
|
21
25
|
|
22
|
-
route(/^
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
+
route(/^activity/, :command_activity, command: true, help: {
|
27
|
+
'activity' => 'Replies with the latest league activity. This automatically runs every 15 minutes by default.'
|
28
|
+
})
|
26
29
|
|
27
30
|
# chat controllers
|
28
31
|
def command_player(response)
|
@@ -50,6 +53,42 @@ module Lita
|
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
56
|
+
def command_activity(response)
|
57
|
+
# Get last activity from redis or default to start of season
|
58
|
+
since = DateTime.parse(redis.get('espn_fantasy_football_last_activity')) rescue DateTime.new(config.season_id.to_i)
|
59
|
+
activity = espn_activity_scrape(since)
|
60
|
+
|
61
|
+
if activity && activity.any?
|
62
|
+
response.reply(espn_activity_scrape(since))
|
63
|
+
else
|
64
|
+
response.reply("No new activity since #{sinced.to_time}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def activity_timer
|
69
|
+
Lita.logger.debug('Setting up activity_timer')
|
70
|
+
|
71
|
+
# If config.activity_room wasn't specified, do not set timer
|
72
|
+
return unless config.activity_room
|
73
|
+
|
74
|
+
# If config.activity_interval is 0, do not set timer
|
75
|
+
return if config.activity_interval.zero?
|
76
|
+
|
77
|
+
every(config.activity_interval) do
|
78
|
+
Lita.logger.debug('Running activity_timer')
|
79
|
+
|
80
|
+
# Get last activity from redis or default to start of season
|
81
|
+
since = DateTime.parse(redis.get('espn_fantasy_football_last_activity')) rescue DateTime.new(config.season_id.to_i)
|
82
|
+
activity = espn_activity_scrape(since)
|
83
|
+
|
84
|
+
if activity && activity.any?
|
85
|
+
robot.send_message(Source.new(room: config.activity_room), activity)
|
86
|
+
else
|
87
|
+
Lita.logger.debug('No new activity found')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
53
92
|
# constants
|
54
93
|
ESPN_POSITION_MAP = {
|
55
94
|
'qb' => 0,
|
@@ -185,7 +224,7 @@ module Lita
|
|
185
224
|
resp
|
186
225
|
end
|
187
226
|
|
188
|
-
def espn_activity_scrape
|
227
|
+
def espn_activity_scrape(since = DateTime.new(config.season_id.to_i))
|
189
228
|
resp = []
|
190
229
|
params = {
|
191
230
|
'leagueId' => config.league_id,
|
@@ -201,24 +240,37 @@ module Lita
|
|
201
240
|
activity = page.xpath('//*[@class="games-fullcol games-fullcol-extramargin"]/table/tr').drop(2)
|
202
241
|
|
203
242
|
activity.each do |a|
|
204
|
-
#
|
205
|
-
|
206
|
-
line = a.css('td')[2].inner_html
|
207
|
-
|
208
|
-
# remove asterisks, as they'll conflict with markdown
|
209
|
-
line.delete!('*')
|
243
|
+
# Parse timestamp
|
244
|
+
timestamp = DateTime.parse("#{a.css('td')[0].children[0].text} #{a.css('td')[0].children[2].text}")
|
210
245
|
|
211
|
-
#
|
212
|
-
|
246
|
+
# Exit loop if we've passed the datetime passed into method
|
247
|
+
break if timestamp <= since
|
213
248
|
|
214
|
-
|
215
|
-
|
249
|
+
type = a.css('td')[1].children[1].text
|
250
|
+
subtype = a.css('td')[1].children[4].text
|
251
|
+
detail = a.css('td')[2].inner_html
|
252
|
+
.delete('*') # remove asterisks, as they'll conflict with markdown
|
253
|
+
.gsub(%r{<(/)?b>}, '*') # convert bold formatting
|
254
|
+
.gsub(/<br>/, "\n") # convert breaks to newlines
|
255
|
+
events = detail.split("\n")
|
216
256
|
|
217
257
|
# add emoji
|
218
|
-
|
219
|
-
|
258
|
+
if type == 'LM Changed League Settings'
|
259
|
+
events.map! { |ev| ":gear: #{ev}" }
|
260
|
+
elsif type == 'Transaction'
|
261
|
+
events.map! do |ev|
|
262
|
+
ev.gsub(/(\S+\sadded)/, ':green_heart: \\1')
|
263
|
+
.gsub(/(\S+\sdropped)/, ':broken_heart: \\1')
|
264
|
+
.gsub(/(\S+\straded)/, ':revolving_hearts: \\1')
|
265
|
+
.gsub(/(\S+\sdrafted)/, ':heavy_plus_sign: \\1')
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
resp << events.join("\n")
|
220
270
|
|
221
|
-
|
271
|
+
# Update redis timestamp if newer than latest activity
|
272
|
+
latest_activity = DateTime.parse(redis.get('espn_fantasy_football_last_activity')) rescue DateTime.new(config.season_id.to_i)
|
273
|
+
redis.set('espn_fantasy_football_last_activity', timestamp.to_s) if timestamp > latest_activity
|
222
274
|
end
|
223
275
|
|
224
276
|
resp
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'lita-espn-fantasy-football'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.3.0'
|
4
4
|
s.authors = ['Kevin Reedy', 'Miles Evenson']
|
5
5
|
s.email = ['kevinreedy@gmail.com', 'miles.evenson@gmail.com']
|
6
6
|
s.description = 'Lita handler for ESPN Fantasy Football'
|