-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpitcher.js
66 lines (57 loc) · 1.71 KB
/
pitcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var cheerio = require('cheerio');
// Constructor
function Pitcher() {
}
Pitcher.prototype.someFunction = function() {
};
// export the class
module.exports = {
Pitcher,
// Returns an array of pitcher ids for the game specified
// pitchers are found by looking in the gid/pitchers directory on gameday
get_all_ids_for_game : function(pitcherPageData) {
var results = [];
if (pitcherPageData) {
$ = cheerio.load(pitcherPageData);
var a = $('ul').html();
if (a) {
$ = cheerio.load(a);
$('a').each(function(i, elem) {
// look at each link inside of a ul tag
if ($(this).text().includes(".xml")) {
// if the link contains the text '.xml' then it is a pitcher
var str = $(this).text().trim();
var pitcher_id = str.substring(0, str.length - 4);
results.push(pitcher_id);
}
});
}
}
return results
}
}
/*
# Returns an array of pitcher ids for the game specified
# pitchers are found by looking in the gid/pitchers directory on gameday
def self.get_all_ids_for_game(gid)
pitchers_page = GamedayFetcher.fetch_pitchers_page(gid)
results = []
if pitchers_page
doc = Hpricot(pitchers_page)
a = doc.at('ul')
if a
(a/"a").each do |link|
# look at each link inside of a ul tag
if link.inner_html.include?(".xml") == true
# if the link contains the text '.xml' then it is a pitcher
str = link.inner_html
str.strip!
pid = str[0..str.length-5]
results << pid
end
end
end
end
results
end
*/