football__data 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 707998b5dd3cbd164065aa5e8a950452584590c4
4
- data.tar.gz: b7f4a287e8d4a4d886376848ffb5d4d351b73002
3
+ metadata.gz: e80953fbbd0b5eb6354ad2af427c6b913c1d96d9
4
+ data.tar.gz: 4b813627d13ce965c4847df5fea7df2e151b4e7a
5
5
  SHA512:
6
- metadata.gz: ceea9f5e640522bb22a840d6075dcc07b8111a558933ea149ae2083df6d0864a18346a115ab7f67c7904cc2970000af3e57a4423ed8c00f7d742a9f0db9a0f5b
7
- data.tar.gz: 6e0b033c89154db0525673f69dd2a9d5c5112fd73843e8fc9208b3c94afd31214b1dfb8920c40346f5ef7c79dd65d240051b20d18d757e603662b6225acce71e
6
+ metadata.gz: 4e4e3a68555129447f8390818291fd2fb80950770896cdc0920ade5c783728d1af8b303f48704052b566e9f83810bc9860e6784f6d240571b2614eeba36aef9a
7
+ data.tar.gz: 900a23a8d19e24211a143a937cf47217a46dd4d56f8dbc7f4b9593230412c23bdb101b4b7cf607790e29aae86422db89cd4843ecd8b04e91299a98015e1bebe5
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # FootballData
2
2
 
3
- A ruby wrapper of [football-data.org](http://api.football-data.org/index)
3
+ A ruby wrapper of [football-data.org](http://api.football-data.org/index),
4
+ it also has an executable to get football info from terminal.
4
5
 
5
6
  ## Installation
6
7
 
@@ -20,7 +21,45 @@ Or install it yourself as:
20
21
 
21
22
  ## Usage
22
23
 
23
- ### API Usage
24
+ ### Executable
25
+
26
+ You can use `football` from the terminal to get some football info.
27
+
28
+ ```
29
+ $ football help # get the help info
30
+
31
+ # examples
32
+ $ football config # config api key, fav team, fav league, etc
33
+ $ football table --league=398
34
+ Premier League 2015/16 matchday 15
35
+ ---------------------------------------------------------------------------
36
+ R Team P W D L GF GA GD Pts
37
+ ---------------------------------------------------------------------------
38
+ 1 Leicester City FC 15 9 5 1 32 21 11 32
39
+ 2 Arsenal FC 15 9 3 3 27 13 14 30
40
+ 3 Manchester City FC 15 9 2 4 30 16 14 29
41
+ ......
42
+
43
+ # you could also add -i to interactive mode, you can see the league id there
44
+ # such as:
45
+ $ football fixture -i
46
+ BL1 1. Bundesliga 394
47
+ BL2 2. Bundesliga 395
48
+ FL1 Ligue 1 396
49
+ ......
50
+ Enter the league id of the team: 394
51
+ FCB FC Bayern München 5
52
+ HSV Hamburger SV 7
53
+ ......
54
+ Enter the team id: 5
55
+ 2015-12-10 03:45 GNK Dinamo Zagreb : FC Bayern München (TBD)
56
+ 2015-12-12 22:30 FC Bayern München : FC Ingolstadt 04 (TBD)
57
+
58
+ # setting fav_league and fav_team would make it much simple
59
+ # use football help SUBCOMMAND to see details
60
+ ```
61
+
62
+ ### API
24
63
 
25
64
  First you need to configure the api
26
65
 
@@ -65,9 +104,6 @@ pp res['players'].find{|player| player['name'] =~ /Mesut/i}
65
104
 
66
105
  See api structure on page 'http://api.football-data.org/documentation'
67
106
 
68
- ### Executable Usage
69
-
70
- TODO
71
107
 
72
108
  ## Contributing
73
109
 
data/bin/football CHANGED
@@ -1 +1,174 @@
1
1
  #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require "time"
5
+ require "yaml"
6
+ require "fileutils"
7
+
8
+ require "football__data"
9
+
10
+
11
+ # constants
12
+ CLI = $PROGRAM_NAME
13
+ HOME = ENV["HOME"]
14
+ EDITOR = ENV["EDITOR"] || "vim"
15
+ CONFIG_FILE = "#{HOME}/.config/football-data/config.yml"
16
+ CONFIG_FILE_EXAMPLE = "./config.yml.example"
17
+
18
+
19
+ # check config file
20
+ unless File.exist? CONFIG_FILE
21
+ puts <<-END.gsub(/^\s*\|/, '')
22
+ |It seems you haven't configured it yet.
23
+ |#{CLI} will generate generate an example config file.
24
+ |Run `#{CLI} config` to config the file.
25
+ END
26
+
27
+ FileUtils.mkdir_p File.dirname(CONFIG_FILE)
28
+ FileUtils.cp CONFIG_FILE_EXAMPLE, CONFIG_FILE
29
+
30
+ exit
31
+ end
32
+
33
+
34
+ # get config info
35
+ CONFIG = YAML.load_file CONFIG_FILE
36
+
37
+ FootballData.configure do |config|
38
+ config.api_key = CONFIG['api_key']
39
+ config.api_version = CONFIG['api_version']
40
+ end
41
+
42
+ FAV_LEAGUE_ID = CONFIG['fav_league_id']
43
+ FAV_TEAM_ID = CONFIG['fav_team_id']
44
+
45
+
46
+ # cli
47
+ class Football < Thor
48
+ desc "config [EXAMPLE]", "Custom configuration file or edit it from an example"
49
+ option :example, :type => :boolean, :default => false
50
+ def config
51
+ if options[:example]
52
+ FileUtils.rm CONFIG_FILE
53
+ FileUtils.cp CONFIG_FILE_EXAMPLE, CONFIG_FILE
54
+ end
55
+ exec "#{EDITOR} #{CONFIG_FILE}"
56
+ end
57
+
58
+ desc "list TYPE", "List LEAGUE or TEAM id"
59
+ option :league, :type => :numeric
60
+ def list(type)
61
+ if type == "league"
62
+ __list_league
63
+ elsif type == "team"
64
+ if league_id = options[:league]
65
+ __list_team league_id
66
+ else
67
+ puts "can not get teams id without specifying the league id"
68
+ end
69
+ else
70
+ puts "type should be league or team"
71
+ end
72
+ end
73
+
74
+
75
+ desc "table [LEAGUE]", "Get LEAGUE table"
76
+ option :league, :type => :numeric
77
+ option :interactive, :type => :boolean, :default => false, :aliases => :i
78
+ def table
79
+ league_id = if options[:interactive]
80
+ __list_league
81
+ print "\nEnter league id: "
82
+ STDIN.gets.to_i
83
+ else
84
+ options[:league_id] || FAV_LEAGUE_ID
85
+ end
86
+ league_table = FootballData.fetch :soccerseasons, :leagueTable, :id => league_id
87
+ caption = league_table['leagueCaption']
88
+ matchday = league_table['matchday']
89
+ standing = league_table['standing']
90
+ div_line = "-" * 75
91
+ w = 5
92
+
93
+ puts "#{caption}\tmatchday #{matchday}"
94
+ puts div_line
95
+ puts "R".ljust(w) + "Team".ljust(30) + %w[P W D L GF GA GD Pts].map{|i|i.ljust(w)}.join
96
+ puts div_line
97
+ standing.each do |team|
98
+ row = team['position'].to_s.ljust(w)
99
+ row += team['teamName'].ljust(30)
100
+ row += team['playedGames'].to_s.ljust(w)
101
+ row += team['wins'].to_s.ljust(w)
102
+ row += team['draws'].to_s.ljust(w)
103
+ row += team['losses'].to_s.ljust(w)
104
+ row += team['goals'].to_s.ljust(w)
105
+ row += team['goalsAgainst'].to_s.ljust(w)
106
+ row += team['goalDifference'].to_s.ljust(w)
107
+ row += team['points'].to_s.ljust(w)
108
+ puts row
109
+ end
110
+ end
111
+
112
+ desc "fixture [TEAM]", "Get latest fixture of TEAM"
113
+ option :team, :type => :numeric
114
+ option :time, :type => :string
115
+ option :interactive, :type => :boolean, :default => false, :aliases => :i
116
+ def fixture
117
+ team_id = if options[:interactive]
118
+ __list_league
119
+ print "\nEnter the league id of the team: "
120
+ league_id = STDIN.gets.to_i
121
+ __list_team league_id
122
+ print "\nEnter the team id: "
123
+ STDIN.gets.to_i
124
+ else
125
+ options[:team] || FAV_TEAM_ID
126
+ end
127
+ time = options[:time] || "n7"
128
+ info = FootballData.fetch :teams, :fixtures, :id => team_id, :timeFrame => time
129
+ fixtures = info['fixtures']
130
+ if fixtures.empty?
131
+ puts "There is no match coming >_<"
132
+ else
133
+ fixtures.each do |fixture|
134
+ date = Time.parse(fixture['date']).localtime
135
+ home = fixture['homeTeamName']
136
+ away = fixture['awayTeamName']
137
+ goal_home = fixture['result']['goalsHomeTeam']
138
+ goal_away = fixture['result']['goalsAwayTeam']
139
+ gh = goal_home == -1 ? '' : " #{goal_home}"
140
+ ga = goal_away == -1 ? '' : " #{goal_away}"
141
+ l = "#{home.ljust(20)}#{gh}"
142
+ r = "#{ga}#{away}"
143
+ match = "#{date.strftime("%Y-%m-%d %H:%M").ljust(20)}\t"
144
+ match += "#{l} : #{r.ljust(20)}"
145
+ match += "(TBD)" if gh.empty?
146
+ puts match
147
+ end
148
+ end
149
+ end
150
+
151
+ private
152
+
153
+ def __list_league
154
+ leagues = FootballData.fetch :soccerseasons
155
+ leagues.each do |league|
156
+ id = league['_links']['self']['href'].split('/').last
157
+ *name, _ = league['caption'].split
158
+ code = league['league']
159
+ puts "#{code.ljust(15)}#{name.join(' ').ljust(25)}#{id}"
160
+ end
161
+ end
162
+
163
+ def __list_team(league_id)
164
+ teams = FootballData.fetch(:soccerseasons, :teams, :id => league_id)['teams']
165
+ teams.each do |team|
166
+ id = team['_links']['self']['href'].split('/').last
167
+ name = team['name']
168
+ code = team['code']
169
+ puts "#{code.ljust(15)}#{name.ljust(30)}#{id}"
170
+ end
171
+ end
172
+ end
173
+
174
+ Football.start
@@ -1,3 +1,3 @@
1
1
  module FootballData
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: football__data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - delta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-06 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler