forked from dotmat/ATTHackDoorPiATL
/
UserHistoryEndPoint.php
33 lines (23 loc) · 1014 Bytes
/
UserHistoryEndPoint.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
<?php
$BaseURL = "http://255e42ec.ngrok.io/";
// PHP Script to convert the CSV to a JSON feed, each time the script is run it re-reads the file.
// {"Event":"DoorBell Pressed","TimeStamp":"15:57:22","Image":"./images/15:57:22.jpg"}
$csvFile = file('Events.csv');
$data = [];
foreach ($csvFile as $line) {
$data[] = str_getcsv($line);
}
foreach ($data as $EventData) {
//echo $EventData[2];
// Remove all the unwanted bits from the image file
$ParsedImage = str_replace(" ","",$EventData[2]);
$ParsedImage = str_replace("./","",$ParsedImage);
$EventHistoryArray[] = '{"Event":"'.$EventData[0].'","TimeStamp":"'.str_replace(" ","",$EventData[1]).'","Image":"'.$BaseURL.$ParsedImage.'"}';
}
$commaSeparated = implode(",", $EventHistoryArray);
// Convert the CSV into JSON Stream
//{"Event":"DoorBell Pressed","TimeStamp":"15:57:22","Image":"./images/15:57:22.jpg"}
// Assemble the JSON response
$JSONResponse = '{"Events":['.$commaSeparated.']}';
echo $JSONResponse;
?>