-
Notifications
You must be signed in to change notification settings - Fork 0
/
denver_water.php
31 lines (23 loc) · 925 Bytes
/
denver_water.php
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
<?php
include 'simple_html_dom.php';
date_default_timezone_set('America/Denver');
$fh = fopen('raw_data/denver_water.csv', 'a');
$url = "http://www.denverwater.org/SupplyPlanning/WaterSupply/ReservoirLevels/?fullsite";
$html = file_get_html($url);
$date = $html->find('h2');
$full_date = preg_split('/:/', $date[0]->plaintext);
$formatted_date = date("m/d/Y", strtotime(trim($full_date[1])));
$res = $html->find('tr');
foreach($res as $row) {
$storage = $row->find('td', 4);
$store = str_replace(',', '', $storage->plaintext);
if(preg_match('/^\d/', $store)) {
$reservoir = $row->find('td', 0);
$res_name = str_replace('*', '', $reservoir->plaintext);
$capacity = $row->find('td', 6);
$cap = str_replace(',', '', $capacity->plaintext);
echo $res_name . "\n";
echo $cap . "\n";
fputcsv($fh, array($res_name, $store, $cap, $formatted_date));
}
}