-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
45 lines (35 loc) · 1.25 KB
/
update.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
include( "settings.php" );
$file_data = file_get_contents( $filename );
$decoded_json = json_decode( $file_data, true );
$datapoints = $decoded_json["graph"]["datasequences"][0]["datapoints"];
if ( !count($datapoints) ) {
for ($offset = 6; $offset >= 0; $offset--) {
$temp_data = array(
"title" => date( "l", strtotime("-".$offset." days") ),
"value" => 0
);
array_push( $datapoints, $temp_data );
}
}
$day_of_week = date( "l" );
if ( $type == "total" ) {
$number_of_things = exec( "osascript -e 'tell application \"Things\"' -e 'return count every to do whose status is open' -e 'end tell'" );
} else {
$number_of_things = exec( "osascript -e 'tell application \"Things\"' -e 'return count to dos of list \"Today\" whose status is open' -e 'end tell'" );
}
$new_record = array(
"title" => $day_of_week,
"value" => $number_of_things
);
$last_record = end( $datapoints );
if ( $last_record["title"] == $day_of_week ) {
array_pop( $datapoints );
} else {
array_shift( $datapoints );
}
array_push( $datapoints, $new_record );
if ( $datapoints != $decoded_json["graph"]["datasequences"][0]["datapoints"] ) {
$decoded_json["graph"]["datasequences"][0]["datapoints"] = $datapoints;
file_put_contents( $filename, json_encode($decoded_json) );
}