Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 60 lines (52 sloc) 1.904 kb
8fdd9e8 making an executable
root authored
1 #!/usr/bin/php
b89c17c @travisj adding a few files to get us going
authored
2 <?php
da73404 @travisj updating script
authored
3 date_default_timezone_set('America/New_York');
4 $base = $argv[1]; //dirname(__FILE__);
b89c17c @travisj adding a few files to get us going
authored
5
da73404 @travisj updating script
authored
6 $teams = json_decode(file_get_contents($base . '/_json/teams.json'), true);
7 $picks = json_decode(file_get_contents($base . '/_json/picks.json'), true);
8 $players = json_decode(file_get_contents($base . '/_json/players.json'), true);
9 $history = json_decode(file_get_contents($base . '/_json/history.json'), true);
b89c17c @travisj adding a few files to get us going
authored
10
da73404 @travisj updating script
authored
11 $url = 'http://espn.go.com/mlb/standings/_/year/2010/seasontype/2';
b89c17c @travisj adding a few files to get us going
authored
12 $handle = fopen($url, "rb");
13
14 $contents = '';
15 while (!feof($handle)) {
16 $contents .= fread($handle, 8192);
17 }
18 fclose($handle);
69618c8 @travisj espn changed their format for the first time in years!
authored
19 //preg_match_all('/<a href="\/mlb\/clubhouse\?team=(.*?)">(.*?)<\/a><\/td><td>(.*?)<\/td><td>(.*?)<\/td>/is', $contents, $matches);
20 preg_match_all('/<a href="\/mlb\/team\/_\/name\/(.*?)\/(.*?)">(.*?)<\/a><\/td><td>(.*?)<\/td><td>(.*?)<\/td>/is', $contents, $matches);
b89c17c @travisj adding a few files to get us going
authored
21 foreach($matches[0] as $i=>$match) {
22 $code = $matches[1][$i];
23 $results[$code] = array(
24 "name" => $teams[$code],
69618c8 @travisj espn changed their format for the first time in years!
authored
25 "code" => $code,
26 "w" => $matches[4][$i],
27 "l" => $matches[5][$i]
b89c17c @travisj adding a few files to get us going
authored
28 );
29 }
30
31 $scores = array();
da73404 @travisj updating script
authored
32 $specifics = array();
b89c17c @travisj adding a few files to get us going
authored
33 foreach ($picks as $team => $pick) {
34 if (!isset($scores[$pick['owner']])) {
35 $scores[$pick['owner']] = 0;
36 }
37 $scores[$pick['owner']] += $results[$team][$pick['choice']];
da73404 @travisj updating script
authored
38 $specifics[$team] = $results[$team][$pick['choice']];
b89c17c @travisj adding a few files to get us going
authored
39 }
40
da73404 @travisj updating script
authored
41 $file = $base . '/_posts/' . date('Y-m-d') . '-Results.markdown';
42
43 $page = "---\n";
44 $page .= "layout: post\n";
45 foreach ($scores as $owner => $score) {
46 $history[date('Y-m-d')][$owner] = $score;
47 $page .= $owner . ': ' . $score . "\n";
48 }
49 foreach ($specifics as $t => $s) {
50 $page .= "$t: $s\n";
51 }
52 $page .= "---\n";
53
54 file_put_contents($base . '/_json/history.json', json_encode($history));
55 file_put_contents($file, $page);
56 system('cd ' . $base . ';' .
57 'git add ' . $file .';' .
58 'git commit -m "adding todays results";' .
59 'git push origin gh-pages');
Something went wrong with that request. Please try again.