-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.php
82 lines (58 loc) · 2.08 KB
/
diff.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
chdir(__DIR__);
$output = array();
$result = 0;
//github constantly moving hosts around and causing host-added warning.
exec("git fetch 2>/dev/null", $output, $result);
//With that warning gone, I will only get real errors from this.
exec("git pull");
$date = date("Y-m-d__H_i_s");
$newfile = "session-$date.json";
$newsession = trim(@file_get_contents("https://www.devspaceconf.com/api/v1/session"));
//$newsession = trim(file_get_contents("session.txt"));
if(empty($newsession)) {
echo "Could not reach DevSpace\n";
exit;
}
$indexhtml = file_get_contents("index.html");
$sessionpos = stripos($indexhtml, "jsonFile");
$sessionposEnd = stripos($indexhtml, "sessions", $sessionpos);
$start = $sessionpos+8;
$stop = $sessionposEnd - $start;
$sessionfile = substr($indexhtml, $start, $stop);
$sessionfile = trim(str_ireplace(array("\"", ":", ",", " ", "/", ";", "="), "", $sessionfile));
$oldsession = trim(file_get_contents($sessionfile));
$js1 = @json_decode($oldsession, true);
$js2 = @json_decode($newsession, true);
if(empty($js1)) {
echo "Old session json is bad. Seeding with empty.\n";
$js1 = [];
}
if(empty($js2)) {
echo "DevSpace returned bad json\n";
exit;
}
//DevSpace API has a quirk that a null date returns the current time. This confuses my diff.
//Lets just unset the DisplayDateTime
for($i = 0; $i < count($js1); $i++) {
$js1[$i]["TimeSlot"]["DisplayDateTime"] = "";
}
for($i = 0; $i < count($js2); $i++) {
$js2[$i]["TimeSlot"]["DisplayDateTime"] = "";
}
//print_r($js1[0]); exit;
$js1text = json_encode($js1, JSON_PRETTY_PRINT);
$js2text = json_encode($js2, JSON_PRETTY_PRINT);
if($js1text != $js2text) {
echo "Need new DevSpace session\n";
$indexhtml = str_replace($sessionfile, $newfile, $indexhtml);
file_put_contents($newfile, $newsession);
file_put_contents("index.html", $indexhtml);
echo "Need to update to GitHub\n";
exec("git rm $sessionfile");
exec("git add index.html $newfile");
exec("git commit -m 'Latest DevSpace session'");
exec("git push");
} else {
//echo "DevSpace session is current\n";
}