fpl_gsheet 0.1.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
+ SHA256:
3
+ metadata.gz: 3a417d8474122e918abc03aab2dcce5f7687c9383ec4b5cea648f8533834f345
4
+ data.tar.gz: 94023b75aeb24c1257a1a7fa3d26a865b7c5b996b674c14a219777e050e2aed5
5
+ SHA512:
6
+ metadata.gz: cad9ce0b39d10ae267506741a8176b7665d3d2cf74a78e5c240a11540acd457ef90306a436ffb3fae0acbdd0ed8396626400081142194ca838cc73d951f77b08
7
+ data.tar.gz: 9e1fa97be9a71370bfd090feb5b16a1aa8d8c0132c346558e20440e856dd43ff35aec41b09e5ac805a67f7f75c636c2d047d81716c969274654d2ca50f2dfc10
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ client_secret.json
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in fpl_gsheet.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fpl_gsheet (0.1.0)
5
+ google_drive (~> 2.1)
6
+ recursive-open-struct (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ declarative (0.0.10)
14
+ declarative-option (0.1.0)
15
+ diff-lcs (1.2.5)
16
+ faraday (0.15.0)
17
+ multipart-post (>= 1.2, < 3)
18
+ google-api-client (0.19.8)
19
+ addressable (~> 2.5, >= 2.5.1)
20
+ googleauth (>= 0.5, < 0.7.0)
21
+ httpclient (>= 2.8.1, < 3.0)
22
+ mime-types (~> 3.0)
23
+ representable (~> 3.0)
24
+ retriable (>= 2.0, < 4.0)
25
+ google_drive (2.1.10)
26
+ google-api-client (>= 0.11.0, < 0.20.0)
27
+ googleauth (>= 0.5.0, < 1.0.0)
28
+ nokogiri (>= 1.5.3, < 2.0.0)
29
+ googleauth (0.6.2)
30
+ faraday (~> 0.12)
31
+ jwt (>= 1.4, < 3.0)
32
+ logging (~> 2.0)
33
+ memoist (~> 0.12)
34
+ multi_json (~> 1.11)
35
+ os (~> 0.9)
36
+ signet (~> 0.7)
37
+ httpclient (2.8.3)
38
+ jwt (2.1.0)
39
+ little-plugger (1.1.4)
40
+ logging (2.2.2)
41
+ little-plugger (~> 1.1)
42
+ multi_json (~> 1.10)
43
+ memoist (0.16.0)
44
+ mime-types (3.1)
45
+ mime-types-data (~> 3.2015)
46
+ mime-types-data (3.2016.0521)
47
+ mini_portile2 (2.3.0)
48
+ multi_json (1.13.1)
49
+ multipart-post (2.0.0)
50
+ nokogiri (1.8.2-x86-mingw32)
51
+ mini_portile2 (~> 2.3.0)
52
+ os (0.9.6)
53
+ public_suffix (3.0.2)
54
+ rake (10.4.2)
55
+ recursive-open-struct (1.1.0)
56
+ representable (3.0.4)
57
+ declarative (< 0.1.0)
58
+ declarative-option (< 0.2.0)
59
+ uber (< 0.2.0)
60
+ retriable (3.1.1)
61
+ rspec (3.5.0)
62
+ rspec-core (~> 3.5.0)
63
+ rspec-expectations (~> 3.5.0)
64
+ rspec-mocks (~> 3.5.0)
65
+ rspec-core (3.5.2)
66
+ rspec-support (~> 3.5.0)
67
+ rspec-expectations (3.5.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.5.0)
70
+ rspec-mocks (3.5.0)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.5.0)
73
+ rspec-support (3.5.0)
74
+ signet (0.8.1)
75
+ addressable (~> 2.3)
76
+ faraday (~> 0.9)
77
+ jwt (>= 1.5, < 3.0)
78
+ multi_json (~> 1.10)
79
+ uber (0.1.0)
80
+
81
+ PLATFORMS
82
+ x86-mingw32
83
+
84
+ DEPENDENCIES
85
+ bundler (~> 1.16)
86
+ fpl_gsheet!
87
+ rake (~> 10.0)
88
+ rspec (~> 3.0)
89
+
90
+ BUNDLED WITH
91
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 reedstonefood
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,59 @@
1
+ # Fpl_Gsheet
2
+
3
+ A Ruby gem for extracting information from [Fantasy Premier League](https://fantasy.premierleague.com/a/home) & storing the information in a Google Sheet, for onwards analysis.
4
+
5
+ For example, you could use Tableau Public to access the Google Sheet and create some great visualisations.
6
+
7
+ ## Installation
8
+
9
+ 1. Install the gem.
10
+ gem install fpl_gsheet
11
+
12
+ 2. To allow the gem access to a Google sheet, the following steps must be followed.
13
+ -- Create a Google service account
14
+ -- Store the client_secret.json file in the same location as the script you write that uses this gem
15
+ -- Create a google sheet & share it (giving it edit access) with the user created in the first step
16
+ More detailed instructions & a nice animated gif can be [found here](https://www.twilio.com/blog/2017/03/google-spreadsheets-ruby.html).
17
+
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ gem 'fpl_gsheet'
23
+
24
+ # stores all "generic" data, eg teams, players, fixtures
25
+ databank = FplGsheet::Databank.new
26
+
27
+ # put the reference to your spreadsheet here.
28
+ # This must already exist & have been shared with the service account
29
+ spreadsheet = FplGsheet::Spreadsheet.new('FplGsheet sample')
30
+
31
+ # Put all team names into the spreadsheet
32
+ spreadsheet.new_sheet('Teams')
33
+ spreadsheet.add_row(['Team ID', 'Team Name']) # header row
34
+ databank.teams.each do |t|
35
+ spreadsheet.insert_new_row([t['id'], t['name'])
36
+ end
37
+ spreadsheet.save # commits the changes you've written
38
+
39
+ # load a league - the ID can be found in the URL of the league table page,
40
+ # eg https://fantasy.premierleague.com/a/leagues/standings/487590/classic
41
+ league = FplGsheet::League.new(487590)
42
+
43
+ # Put team names & score into spreadsheet
44
+ spreadsheet.new_sheet('League')
45
+ spreadsheet.insert_new_row(%w(Rank Team Score))
46
+
47
+ league.standings.each do |s|
48
+ spreadsheet.insert_new_row([
49
+ s['rank'],
50
+ s['entry_name'],
51
+ s['total']
52
+ ])
53
+ end
54
+ spreadsheet.save
55
+ ```
56
+
57
+ ## More usage information
58
+
59
+ See the wiki on the [GitHub repo page](https://github.com/reedstonefood/fpl_gsheet).
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 "fpl/gsheet"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "innate-works-201616",
4
+ "private_key_id": "f1d63496e3156e67fee7fd2cf3393c61b6335691",
5
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCqYVuGNfyOBfl3\nJgvNJZ0Zvpc1zD1u2pwZ0pMnl7dXPim+2XL1h53s761gATvLSuqleQDMvZbxZ6iR\nbtISlcpW1q+dhYmk8r1ZyHO3Xjf8hrSg5T5NsxgJk5TG81BrQNkDyxhhF7VYuAtK\nU08fcZ5N6PWbyEHovbq2KisLGSjzC3xqdTGmUmM3FIgL19NdVgw09uKJlgUPXyHl\nYh8o7PGjgKYbX4Xura9iyqkZ1CEnA66r/DgU0+ff8Ayxfa8rZ9WZKGfo4dCGiRSd\noanaweWdRpAG6b7imXlhpKdU24YBoLgeLo9eA78IwZClu1fOEdc74mYvsS/+67I6\nxbko9SoJAgMBAAECggEAGvueLgwgujFSB7+bwNqDHc+kTN3SoNq4PBKwQWXyoDt1\nCwePADmBFkQC9iBb4t8zeA9IxCQGYqbi+F1PoafdSpFncI/0c44J1M09Hj4qqbB/\nrLeBfXauiN25gySHiOTVOZeRfdbuXmWPTC8TacxpoLcTJp+5aG2bwzu8Y16RsKPP\nqGjKWgQeDcXrLqMRADZXaQkBtfNZoi0GI3qxigec6fA4K6M6am908Jkm6zOv8Sh2\n+rBrQGsgtipUKQDz7xXek3c4r9gkCQEHh+QVYHhPx/HkCG05RoIpnt/imNjvxUnj\n/Xl9m2s30keAIowJaQtep1348CfSCE47ATk0GXvdLQKBgQDi66KwGRjFUoybinIx\nM5uOlARP7vNX/6CaljLN3ZFqoEIKBhDPynce7t+L7Yz/ZttP/G5DPxAjmKRaA9Bu\nUrWjnMVYifNHhO/CttrqH0uXfU7mx7XJCfLCj4EZY1r+2C9wJhC68iOe1NL+vW0i\nYUzlHwwMOytCxEn46mVZ37R/kwKBgQDANtzlYF9HXrLEtPDtPKmz+0LdN6C82+G+\nIKuhMRXZgQ70MNlBKarTo7FPh9HxqEWR76yXjib91v585m23ohFJtJ3Cae/Ly8ci\neOcHcesQYa7/fkP5s18O/3xWZ2nFfDosFqoyhXUlne9ZWVeCLlKOWTPGjYb7jnAE\nEB5V5XuZcwKBgCPqkex3fHE2+KRhzGM3PObbTLduJbwG7N+q6E2nRS3wQaOehCiv\nbh1KR725ErkWCZ5mYPlp0N8heNn6gpIDq1ZDKQUziHsIcn6KPKoT2/4VSljCwWYZ\nmf/rgM6I6E0v4IpKrBk63CJ2oxLI3q4zYl1dhaWl89n0gZTRXMtV2hbbAoGBAIu3\nFUexjnAdOIpdD4cSAjSuHYMZDUBZ/7OoobiQKlaoRctfuntwIxilMpwhmIw0iSUz\n9ttO267FWMRG5leFeVV+8PFA+anEHKJFCYFS389Pgdl62UQmiqEnOiTAFJUU4F/t\ntZb1hRpru2/Rzhb1PtLzqfvYIda2SVvar4I2RWpbAoGBAMalwnqw4NbS22qrZBG/\n6NU49X81C0jZcBRoVWUOsv9GPWHqB4p2+hA2a9sgZwVaqsqO8rmG06pr7urwi0gL\nrHuQ/KtYfdaZY9uHDqXgxSuvK4nzpv5I9MO/W8SeLArU61ZwNl5Nn6u+eqjY6JKD\nBwelbhBAxYvzdcNRKnM5WaK7\n-----END PRIVATE KEY-----\n",
6
+ "client_email": "ruby-service-account@innate-works-201616.iam.gserviceaccount.com",
7
+ "client_id": "117713227265954709342",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://accounts.google.com/o/oauth2/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/ruby-service-account%40innate-works-201616.iam.gserviceaccount.com"
12
+ }
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fpl_gsheet/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fpl_gsheet"
8
+ spec.version = FplGsheet::VERSION
9
+ spec.authors = ["reedstonefood"]
10
+ spec.email = ["reedstonefood@users.noreply.github.com"]
11
+
12
+ spec.summary = %q{Get Premier League Fantasy Football data into Google Sheets.}
13
+ spec.description = %q{Data comes from fantasy.premierleague.com.}
14
+ spec.homepage = "https://github.com/reedstonefood"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_dependency "google_drive", "~> 2.1"
29
+ #spec.add_dependency "google_api_client", "~> 0.4.3" #really?
30
+ spec.add_dependency "recursive-open-struct", "~> 1.1"
31
+ end
@@ -0,0 +1,103 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+ require_relative 'team.rb'
4
+ require_relative 'fixture.rb'
5
+ require_relative 'player.rb'
6
+
7
+
8
+ module FplGsheet
9
+
10
+ class Databank
11
+ def initialize
12
+ #some stuff outside the scope of this review
13
+ #just assume the fixtures and teams methods work
14
+ @all_data=JSON.load(open("https://fantasy.premierleague.com/drf/bootstrap-static", {ssl_verify_mode: 0}))
15
+ @fixture_data=JSON.load(open("https://fantasy.premierleague.com/drf/fixtures", {ssl_verify_mode: 0}))
16
+ end
17
+
18
+ def fixtures
19
+ #returns array of all Fixtures
20
+ @fixtures ||= @fixture_data.map { |f| Fixture.new(f, self) }
21
+ end
22
+
23
+ def teams
24
+ #returns array of all Teams
25
+ return @teams if defined? @teams
26
+ @teams = @all_data['teams'].map do |t|
27
+ Team.new(t, self)
28
+ end
29
+ end
30
+
31
+ def players
32
+ return @players if defined? @players
33
+ @players = @all_data['elements'].map do |t|
34
+ Player.new(t, self)
35
+ end
36
+ end
37
+
38
+ def fixtures_for_team(id)
39
+ fixtures.select do |f|
40
+ id==f.data['team_h'] || id==f.data['team_a']
41
+ end
42
+ end
43
+
44
+ def gameweeks
45
+ @gameweeks ||= @all_data['events']
46
+ end
47
+ end
48
+
49
+ #class Fixture
50
+ # attr_reader :data
51
+ # def initialize(data)
52
+ # @data = data
53
+ # end
54
+ #end
55
+ #
56
+ #class Team
57
+ # attr_reader :data, :fixtures
58
+ # def initialize(data, fixtures)
59
+ # @data = data
60
+ # @fixtures = fixtures.map { |f| TeamFixture.new(f, @data['id']) }
61
+ # end
62
+ #end
63
+
64
+ #class TeamFixture
65
+ # attr_reader :fixture, :venue
66
+ # def initialize(fixture,team_id)
67
+ # @fixture=fixture
68
+ # @venue = fixture.data['team_h']==team_id ? 'H' : 'A'
69
+ # @h_score = fixture.data['team_h_score']
70
+ # @a_score = fixture.data['team_a_score']
71
+ # end
72
+ #
73
+ # def result
74
+ # return '-' if @h_score=='null'
75
+ # return 'D' if @h_score==a_score
76
+ # winner = @h_score==@a_score ? 'H' : 'A'
77
+ # return @venue==winner ? 'W' : 'L'
78
+ # end
79
+ #
80
+ # def own_score
81
+ # @venue=='H' ? @h_score : @a_score
82
+ # end
83
+ #
84
+ # def opp_score
85
+ # @venue=='H' ? @a_score : @h_score
86
+ # end
87
+ #
88
+ # def opponent
89
+ # id = @venue=='H' ? @fixture['team_a'] : @fixture['team_h']
90
+ # # How to get from this id to the Team object it represents?
91
+ # end
92
+ #end
93
+ end
94
+
95
+ #d = Databank.new
96
+ #d.teams.each do |t|
97
+ # puts "#{t.data['name'].upcase} are playing these teams..."
98
+ # if t.data['name']=='Arsenal'
99
+ # t.fixtures.each do |tf|
100
+ # puts "#{tf.fixture.data['kickoff_time_formatted']}, #{tf.own_score} - #{tf.opp_score}"
101
+ # end
102
+ # end
103
+ #end
@@ -0,0 +1,65 @@
1
+
2
+ module FplGsheet
3
+ class Entry
4
+ attr_reader :name, :id
5
+ def initialize(entry_id)
6
+ entry_json=JSON.load(open("https://fantasy.premierleague.com/drf/entry/#{entry_id}/transfers", {ssl_verify_mode: 0}))
7
+ @entry_data=entry_json['entry']
8
+ @league_data=entry_json['leagues']
9
+ @name=@entry_data['name']
10
+ @id=@entry_data['id']
11
+ @historical_gameweeks = Hash.new()
12
+ #@fixtures = fixtures.map { |f| TeamFixture.new(f, @data['id']) }
13
+ end
14
+
15
+ def manager_name
16
+ @entry_data['player_first_name'] + ' ' + @entry_data['player_last_name']
17
+ end
18
+
19
+ def history
20
+ @history ||= JSON.load(open("https://fantasy.premierleague.com/drf/entry/#{id}/history", {ssl_verify_mode: 0}))
21
+ end
22
+
23
+
24
+ def transfers
25
+ @transfer_data ||= JSON.load(open("https://fantasy.premierleague.com/drf/entry/#{id}/transfers", {ssl_verify_mode: 0}))
26
+ @transfer_data["history"]
27
+ end
28
+
29
+ def chips; history["chips"]; end
30
+
31
+ def summary; history["entry"]; end
32
+
33
+ def past_seasons; history["season"]; end
34
+
35
+ def gameweek_history; history["history"]; end
36
+
37
+ def picks
38
+ latest_gameweek = gameweek_history.last['event']
39
+ picks_for_gameweek[latest_gameweek]
40
+ end
41
+
42
+ def picks_for_gameweek(gw)
43
+ return @historical_gameweeks[gw] if @historical_gameweeks.key?(gw)
44
+ api ||= JSON.load(open("https://fantasy.premierleague.com/drf/entry/#{id}/event/#{gw}/picks", {ssl_verify_mode: 0}))
45
+ @historical_gameweeks[gw] = api['picks'].map { |p| Pick.new(p)}
46
+ end
47
+
48
+ end
49
+
50
+ class Entries < Hash
51
+
52
+ def [](key)
53
+ val = super
54
+ if val.nil?
55
+ # Load it
56
+ val = Entry.new(key)
57
+ # Cache it so we don't have to create the Entry again
58
+ self[key] = val
59
+ end
60
+
61
+ val
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,11 @@
1
+ require 'recursive-open-struct'
2
+
3
+ module FplGsheet
4
+ class Fixture < RecursiveOpenStruct
5
+ #attr_reader :data
6
+ def initialize(data, databank)
7
+ super(data)
8
+ @databank = databank
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+
2
+ module FplGsheet
3
+ class League
4
+ attr_reader :name, :id
5
+ def initialize(league_id)
6
+ @league_data=JSON.load(open("https://fantasy.premierleague.com/drf/leagues-classic-standings/#{league_id}", {ssl_verify_mode: 0}))
7
+ @name=@league_data['league']['name']
8
+ @id=@league_data['league']['id']
9
+ #@fixtures = fixtures.map { |f| TeamFixture.new(f, @data['id']) }
10
+ end
11
+
12
+ def standings
13
+ @standings ||= @league_data['standings']['results']
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,36 @@
1
+
2
+ module FplGsheet
3
+ class Pick
4
+ def initialize(input_hash)
5
+
6
+ @input_hash = input_hash
7
+ #@fixtures = fixtures.map { |f| TeamFixture.new(f, @data['id']) }
8
+ end
9
+
10
+ def player_id
11
+ @input_hash['element']
12
+ end
13
+
14
+ #def selling_price
15
+ # @input_hash['selling_price'].to_f/10).round(1)
16
+ #end
17
+
18
+ def captain?; @input_hash['is_captain']; end
19
+ def vice_captain?; @input_hash['is_vice_captain']; end
20
+ def multiplier; @input_hash['multiplier']; end
21
+
22
+ # the above 5 are the only ones that show up all the time, eg this page
23
+ # https://fantasy.premierleague.com/drf/entry/483663/event/1/picks
24
+ # There's also this...
25
+ # https://fantasy.premierleague.com/drf/my-team/483663/ NUTS this is only if you are logged in :(
26
+
27
+ def on_bench? #not subsititue? cos you could be subbed on
28
+ return @input_hash['position'] > 11
29
+ end
30
+
31
+ # can_sub, has_played, can_captain
32
+
33
+ end
34
+
35
+
36
+ end
@@ -0,0 +1,20 @@
1
+ require 'ostruct'
2
+
3
+ module FplGsheet
4
+ class Player < OpenStruct # as in, football player, not an FPL manager
5
+ #attr_reader :details
6
+
7
+ def initialize(raw_hash, databank)
8
+ super(raw_hash)
9
+ @databank = databank
10
+ end
11
+
12
+ def full_name
13
+ self.first_name + ' ' + self.second_name
14
+ end
15
+
16
+ def price # FPL stores £5.4m as 54, let's change it back
17
+ (self.now_cost.to_f/10).round(1)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ require 'bundler'
2
+ require 'google_drive'
3
+ #Bundler.require
4
+ #with thanks to https://www.twilio.com/blog/2017/03/google-spreadsheets-ruby.html
5
+
6
+ module FplGsheet
7
+ class Spreadsheet
8
+
9
+ attr_reader :spreadsheet
10
+
11
+ def initialize(spreadsheet_title)
12
+ # Authenticate a session with your Service Account
13
+ session = GoogleDrive::Session.from_service_account_key("client_secret.json")
14
+
15
+ # Get the spreadsheet by its title
16
+ @spreadsheet = session.spreadsheet_by_title(spreadsheet_title)
17
+ @worksheet = @spreadsheet.worksheets.first # the default
18
+ @max_row = @worksheet.num_rows
19
+ @rows_to_add = Array.new
20
+ end
21
+
22
+ def new_sheet(sheet_name)
23
+ doomed_ws = @spreadsheet.worksheet_by_title(sheet_name)
24
+ doomed_ws.delete if !doomed_ws.nil?
25
+ @worksheet = @spreadsheet.add_worksheet(sheet_name)
26
+ @max_row = 1
27
+ save
28
+ end
29
+
30
+ def insert_new_row(row_data)
31
+ @rows_to_add << row_data
32
+ end
33
+
34
+ def insert_new_rows(row_data) # assumes array of arrays
35
+ @rows_to_add += row_data
36
+ end
37
+
38
+ def save
39
+ @worksheet.insert_rows(@max_row +1, @rows_to_add) if !@rows_to_add.empty?
40
+ @worksheet.save
41
+ @rows_to_add.clear # empty the array
42
+ @max_row = @worksheet.num_rows
43
+ end
44
+
45
+ def all_rows
46
+ @worksheet.rows
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ require 'recursive-open-struct'
2
+
3
+ module FplGsheet
4
+ class Team < RecursiveOpenStruct
5
+ #attr_reader :data
6
+ def initialize(data, databank)
7
+ super(data)
8
+ @databank = databank
9
+ @id = data['id']
10
+ #@fixtures = fixtures.map { |f| TeamFixture.new(f, @data['id']) }
11
+ end
12
+
13
+ def fixtures
14
+ @databank.fixtures.collect do |f|
15
+ fixture.team_h = id || fixture.team_a = id
16
+ end
17
+ end
18
+ end
19
+
20
+ class FixtureTeam
21
+ def initialize(fixture,team_id)
22
+ @fixture=fixture
23
+ @venue = fixture.data['team_h']==team_id ? 'H' : 'A'
24
+ @h_score = fixture.data['team_h_score']
25
+ @a_score = fixture.data['team_a_score']
26
+ end
27
+
28
+ def result
29
+ return '-' if @h_score=='null'
30
+ return 'D' if @h_score==@a_score
31
+ winner = @h_score==@a_score ? 'H' : 'A'
32
+ return @venue==winner ? 'W' : 'L'
33
+ end
34
+
35
+ def own_score
36
+ @venue=='H' ? @h_score : @a_score
37
+ end
38
+
39
+ def opp_score
40
+ @venue=='H' ? @a_score : @h_score
41
+ end
42
+
43
+ def opponent
44
+ id = @venue=='H' ? @fixture['team_a'] : @fixture['team_h']
45
+ # How to get from this id to the Team object it represents?
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module FplGsheet
2
+ VERSION = "0.1.1"
3
+ end
data/lib/fpl_gsheet.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "fpl_gsheet/version"
2
+ require "fpl_gsheet/spreadsheet"
3
+ require "fpl_gsheet/databank"
4
+ require "fpl_gsheet/fixture"
5
+ require "fpl_gsheet/league"
6
+ require "fpl_gsheet/player"
7
+ require "fpl_gsheet/team"
8
+ require "fpl_gsheet/entry"
9
+ require "fpl_gsheet/pick"
10
+
11
+ module FplGsheet
12
+ # Your code goes here...
13
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fpl_gsheet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - reedstonefood
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: google_drive
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: recursive-open-struct
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ description: Data comes from fantasy.premierleague.com.
84
+ email:
85
+ - reedstonefood@users.noreply.github.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - client_secret.json
101
+ - fpl_gsheet.gemspec
102
+ - lib/fpl_gsheet.rb
103
+ - lib/fpl_gsheet/databank.rb
104
+ - lib/fpl_gsheet/entry.rb
105
+ - lib/fpl_gsheet/fixture.rb
106
+ - lib/fpl_gsheet/league.rb
107
+ - lib/fpl_gsheet/pick.rb
108
+ - lib/fpl_gsheet/player.rb
109
+ - lib/fpl_gsheet/spreadsheet.rb
110
+ - lib/fpl_gsheet/team.rb
111
+ - lib/fpl_gsheet/version.rb
112
+ homepage: https://github.com/reedstonefood
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.7.6
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Get Premier League Fantasy Football data into Google Sheets.
136
+ test_files: []