atp_scraper 0.5.0 → 0.5.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 +4 -4
- data/README.md +10 -5
- data/lib/atp_scraper/activities/record.rb +24 -0
- data/lib/atp_scraper/activities/tournament.rb +5 -0
- data/lib/atp_scraper/activity.rb +10 -31
- data/lib/atp_scraper/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7fe84730985d940e8b413c65f1b33cc375c30ec
|
4
|
+
data.tar.gz: ef3f2b93d9fa239d98254e0c272ef4cd3cd6d7e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b614765df55a42cfdababaf9c798970d868676fff8be8e7d4b8538d87081d9a0800721dd03231aeec982ff3dd2e187dee53951bca0350cc6ca32c4013cb7148e
|
7
|
+
data.tar.gz: bd0e5db0f6f37e89321c0436b734a59878db052c9ab7b39ef114a4de9ecabc18bf38d2b59737724ff0af651ff684cdef57f7ef9bf7f07fb6eee875a19d4f41a4
|
data/README.md
CHANGED
@@ -29,7 +29,8 @@ AtpScraper::Get.singles_ranking
|
|
29
29
|
# rannking: "5"
|
30
30
|
# player_name: "Rafael Nadal",
|
31
31
|
# player_url_name: "rafael-nadal",
|
32
|
-
# player_id: "n409"
|
32
|
+
# player_id: "n409",
|
33
|
+
# points: "5000"
|
33
34
|
# }
|
34
35
|
|
35
36
|
# Get Singles Ranking 101-200
|
@@ -39,11 +40,11 @@ AtpScraper::Get.singles_ranking("101-200")
|
|
39
40
|
AtpScraper::Get.player_activity("n409", 2016)
|
40
41
|
# Response Json
|
41
42
|
# {
|
42
|
-
# year: 2016,
|
43
|
+
# year: "2016",
|
43
44
|
# player_name: "Rafael Nadal",
|
44
|
-
# player_rank: 5,
|
45
|
+
# player_rank: "5",
|
45
46
|
# opponent_name: "Fernand Verdasco",
|
46
|
-
# opponent_rank: 45,
|
47
|
+
# opponent_rank: "45",
|
47
48
|
# round: "Round of 128",
|
48
49
|
# score: "673 64 63 674 26",
|
49
50
|
# win_loss: "L",
|
@@ -51,8 +52,12 @@ AtpScraper::Get.player_activity("n409", 2016)
|
|
51
52
|
# tournament_location: "Melbourne, Australia",
|
52
53
|
# tournament_start_date: "2016.01.18",
|
53
54
|
# tournament_end_date: "2016.01.31",
|
54
|
-
# tournament_surface: "
|
55
|
+
# tournament_surface: "Hard",
|
56
|
+
# tournament_surface_inout: "Ourdoor"
|
55
57
|
# }
|
58
|
+
|
59
|
+
# Get Player All Activity. For Example Rafael Nadal's all activity
|
60
|
+
AtpScraper::Get.player_activity("n409", "all")
|
56
61
|
```
|
57
62
|
|
58
63
|
## Contributing
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Activities
|
2
|
+
# Activity Record Class
|
3
|
+
class Record
|
4
|
+
def self.pickup_record(record_doc)
|
5
|
+
result = {}
|
6
|
+
record_doc.css("td").each_with_index do |td, n|
|
7
|
+
record_content = td.content.strip
|
8
|
+
case n
|
9
|
+
when 0 then
|
10
|
+
result[:round] = record_content
|
11
|
+
when 1 then
|
12
|
+
result[:opponent_rank] = record_content
|
13
|
+
when 2 then
|
14
|
+
result[:opponent_name] = record_content
|
15
|
+
when 3 then
|
16
|
+
result[:win_loss] = record_content
|
17
|
+
when 4 then
|
18
|
+
result[:score] = record_content
|
19
|
+
end
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/atp_scraper/activity.rb
CHANGED
@@ -11,9 +11,11 @@
|
|
11
11
|
# record_doc
|
12
12
|
###################
|
13
13
|
|
14
|
+
require 'atp_scraper/activities/record'
|
14
15
|
module AtpScraper
|
15
16
|
# Scrape activity data
|
16
17
|
class Activity
|
18
|
+
include Activities
|
17
19
|
def initialize(html, html_charset = 'utf-8')
|
18
20
|
@activity_doc = AtpScraper::Html.parse(html, html_charset)
|
19
21
|
@player_name = pickup_player_name(@activity_doc)
|
@@ -22,13 +24,12 @@ module AtpScraper
|
|
22
24
|
def pickup_activity_data
|
23
25
|
result = []
|
24
26
|
player = {}
|
25
|
-
player[:name] = @player_name
|
26
27
|
|
27
28
|
search_tournaments_doc(@activity_doc).each do |tournament_doc|
|
28
29
|
tournament = pickup_tournament_info(tournament_doc)
|
29
30
|
player[:rank] = pickup_player_rank(tournament[:caption])
|
30
31
|
search_records_doc(tournament_doc).each do |record_doc|
|
31
|
-
record = pickup_record(record_doc)
|
32
|
+
record = Record.pickup_record(record_doc)
|
32
33
|
record_hash = create_record(record, player, tournament)
|
33
34
|
result.push(record_hash)
|
34
35
|
end
|
@@ -49,7 +50,7 @@ module AtpScraper
|
|
49
50
|
def create_record(record, player, tournament)
|
50
51
|
{
|
51
52
|
year: tournament[:year],
|
52
|
-
player_name:
|
53
|
+
player_name: @player_name,
|
53
54
|
player_rank: player[:rank],
|
54
55
|
opponent_name: record[:opponent_name],
|
55
56
|
opponent_rank: record[:opponent_rank],
|
@@ -71,26 +72,6 @@ module AtpScraper
|
|
71
72
|
.attr("content").value
|
72
73
|
end
|
73
74
|
|
74
|
-
def pickup_record(record_doc)
|
75
|
-
result = {}
|
76
|
-
record_doc.css("td").each_with_index do |td, n|
|
77
|
-
record_content = td.content.strip
|
78
|
-
case n
|
79
|
-
when 0 then
|
80
|
-
result[:round] = record_content
|
81
|
-
when 1 then
|
82
|
-
result[:opponent_rank] = record_content
|
83
|
-
when 2 then
|
84
|
-
result[:opponent_name] = record_content
|
85
|
-
when 3 then
|
86
|
-
result[:win_loss] = record_content
|
87
|
-
when 4 then
|
88
|
-
result[:score] = record_content
|
89
|
-
end
|
90
|
-
end
|
91
|
-
result
|
92
|
-
end
|
93
|
-
|
94
75
|
def pickup_tournament_info(tournament_doc)
|
95
76
|
tournament_date = pickup_text(tournament_doc, ".tourney-dates")
|
96
77
|
surface = pickup_surface(tournament_doc)
|
@@ -123,18 +104,16 @@ module AtpScraper
|
|
123
104
|
|
124
105
|
def pickup_surface(tournament_doc)
|
125
106
|
surface = tournament_doc
|
126
|
-
|
127
|
-
|
128
|
-
|
107
|
+
.css(".tourney-details")[1]
|
108
|
+
.css(".item-details")
|
109
|
+
.first.content.gsub(/\t|\s/, "")
|
129
110
|
divide_surface(surface)
|
130
111
|
end
|
131
112
|
|
132
113
|
def divide_surface(surface)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
return { surface: surface.gsub(/Indoor/, ''), inout: "Indoor" }
|
137
|
-
end
|
114
|
+
inout = surface.match(/^(Outdoor|Indoor)/)
|
115
|
+
return { surface: surface, inout: nil } if inout.nil?
|
116
|
+
{ surface: surface.gsub(/#{inout[0]}/, ''), inout: inout[0] }
|
138
117
|
end
|
139
118
|
end
|
140
119
|
end
|
data/lib/atp_scraper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atp_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mosuke5
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -141,6 +141,8 @@ files:
|
|
141
141
|
- bin/console
|
142
142
|
- bin/setup
|
143
143
|
- lib/atp_scraper.rb
|
144
|
+
- lib/atp_scraper/activities/record.rb
|
145
|
+
- lib/atp_scraper/activities/tournament.rb
|
144
146
|
- lib/atp_scraper/activity.rb
|
145
147
|
- lib/atp_scraper/get.rb
|
146
148
|
- lib/atp_scraper/html.rb
|