Skip to content

Commit

Permalink
Implementation of Meta page. A lot of modules rejiggered. More module…
Browse files Browse the repository at this point in the history
…s to be added but it closes #32.
  • Loading branch information
jacroe committed Jun 9, 2013
1 parent be51da8 commit 466dacc
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if($w != -1) alice_mysql_put("modules", "weather", $w);
if (!(date('i') % 30) || ($_GET['purge'])) alice_mysql_putImage("weather_radar", alice_weather_getRadar($l), "image/gif");
if (!(date('i') % 30) || ($_GET['purge'])) alice_mysql_putImage("weather_satellite", alice_weather_getSatellite($l), "image/gif");
alice_mysql_put("modules", "email", array("count"=>$e));
if($e != -1) alice_mysql_put("modules", "email", array("count"=>$e));
alice_mysql_put("modules", "update", array("time"=>$t));
}
else
Expand Down
1 change: 1 addition & 0 deletions inc/templates/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ padding-bottom: 40px;
<li class="{{if $page=='weather'}}active{{/if}}"><a href="weather.php">Weather</a></li>
<li class="{{if $page=='xbmc'}}active{{/if}}"><a href="xbmc.php">XBMC</a></li>
<li class="{{if $page=='home'}}active{{/if}}"><a href="home.php">Home</a></li>
<li class="{{if $page=='meta'}}active{{/if}}"><a href="meta.php">Meta</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
Expand Down
26 changes: 26 additions & 0 deletions inc/templates/meta.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{include file="header.tpl" page="meta"}}
<div class="hero-unit">
<h1>{{$masthead}}</h1>
<p>{{$subhead}}</p>
</div>

<div class="row">

<div class="span4">
<h2>Services</h2>
<table class="table table-bordered table-condensed">
<tbody>
{{foreach $serviceList as $service}}
<tr><td><strong>{{$service.title}}</strong></td><td><span class={{if $service.status == 1}}text-warning{{elseif $service.status == 2}}text-error{{else}}text-success{{/if}}>{{$service.message}}</span></td></tr>
{{/foreach}}
</tbody>
</table>
</div>

<div class="span8">
<h2>Error log</h2>
<pre class=.pre-scrollable>{{$errorLog}}</pre>
</div>

</div>
{{include file="footer.tpl" page="meta"}}
22 changes: 22 additions & 0 deletions meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
require "alice.php";

if (time()-$u['time'] > 1200) $errors[] = array("error", "Alice's data is at least 20 minutes old.");

/* Masthead */
$masthead = "Meta";

/* Subhead */
$subhead = "It is ".date("g:i a");

$errorLog = file_get_contents(PATH."error.log");

$smarty->assign("masthead", $masthead);
$smarty->assign("subhead", $subhead);
$smarty->assign("serviceList", $serviceList);
$smarty->assign("errorLog", $errorLog);
$smarty->assign("updateTime", date("g:i a", $u['time']));
$smarty->assign("updateCity", $l['city'].', '.$l['state']);
$smarty->assign("error", $errors);
$smarty->display("meta.tpl");
?>
33 changes: 32 additions & 1 deletion modules/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,38 @@
ABOUT: Checks for, sends, and organizes email
DEPENDENCIES: Swift library;
*/

$serviceList[] = alice_email_status();

function alice_email_status()
{
$lData = alice_mysql_get("modules", "email");

if($lData["status"])
{
$sMessage = "Mail man's running.";
$sStatus = "0";
}
else
{
$sMessage = "Postal holiday.";
$sStatus = "2";
}

return array("title"=>"Email", "message"=>$sMessage, "status"=>$sStatus);
}


function alice_email_openServer()
{
return imap_open(IMAP_SERVER, IMAP_USER, IMAP_PASS);
if($con = imap_open(IMAP_SERVER, IMAP_USER, IMAP_PASS))
alice_mysql_put("modules", "email", array("status"=>"1"));
else
{
alice_mysql_put("modules", "email", array("status"=>"0"));
alice_error_add("Email module", "Couldn't open IMAP connection");
}
return $con;
}
function alice_email_closeServer(&$con)
{
Expand All @@ -16,6 +45,8 @@ function alice_email_closeServer(&$con)
function alice_email_check($meta = "sentence")
{
$mbox = alice_email_openserver();
if(!$mbox)
return -1;
$check = imap_mailboxmsginfo($mbox);
imap_close($mbox);
$count = $check->Unread;
Expand Down
23 changes: 23 additions & 0 deletions modules/location.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@
ABOUT: Returns data about certain locations. Can look up where a person is based on Google Latitude
DEPENDENCIES: None;
*/

$serviceList[] = alice_loc_status();

function alice_loc_status()
{
$lData = alice_mysql_get("modules", "location");

if($lData["status"])
{
$sMessage = "I see you.";
$sStatus = "0";
}
else
{
$sMessage = "Where'd you go?";
$sStatus = "2";
}

return array("title"=>"Location", "message"=>$sMessage, "status"=>$sStatus);
}

function alice_loc_check($string)
{
if(preg_match('/\(? (\d\d\d\d\d)/x', $string, $matches)) return true;
Expand All @@ -28,8 +49,10 @@ function alice_loc_get($string)
if($jsonWund->response->error)
{
alice_error_add("Location module", "Location lookup error ".$jsonWund->response->error->description);
alice_mysql_put("modules", "location", array("status"=>"0"));
return -1;
}
else alice_mysql_put("modules", "location", array("status"=>"1"));
return array("city"=>$jsonWund->location->city,
"state"=>$jsonWund->location->state,
"zip"=>$jsonWund->location->zip,
Expand Down
24 changes: 24 additions & 0 deletions modules/weather.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,38 @@
ABOUT: Gets the current weather, forecast and and other conditions. Provides URLs to radar and satellite images
DEPENDENCIES: Location data;
*/

$serviceList[] = alice_weather_status();

function alice_weather_status()
{
$wData = alice_mysql_get("modules", "weather");

if($wData["status"])
{
$sMessage = "Looking out the window.";
$sStatus = "0";
}
else
{
$sMessage = "Blinds are closed.";
$sStatus = "2";
}

return array("title"=>"Weather", "message"=>$sMessage, "status"=>$sStatus);
}


function alice_weather_get($loc)
{
$jsonWeather = json_decode(file_get_contents("http://api.wunderground.com/api/".WUNDERGROUND_API."/conditions/forecast/alerts/q/{$loc['zip']}.json"));
if($jsonWeather->response->error)
{
alice_error_add("Weather module", "Weather lookup error ".$jsonWeather->response->error->description);
alice_mysql_put("modules", "weather", array("status"=>"0"));
return -1;
}
else alice_mysql_put("modules", "weather", array("status"=>"1"));
$icon = alice_weather_getIcon($jsonWeather->current_observation->icon);
if ($jsonWeather->response->features->alerts)
foreach($jsonWeather->alerts as $alert)
Expand Down
19 changes: 19 additions & 0 deletions modules/x10.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
ABOUT: Turns off and on X10 devices. Must be preset as shown
DEPENDENCIES: None
*/

$serviceList[] = alice_x10_status();

function alice_x10_status()
{
if(is_writable("/dev/ttyUSB0"))
{
$sMessage = "Awaiting orders.";
$sStatus = "0";
}
else
{
$sMessage = "Not listening.";
$sStatus = "2";
}

return array("title"=>"X10", "message"=>$sMessage, "status"=>$sStatus);
}

function alice_x10($device, $action, $amount = 1)
{
#alice_notification_add("x10", "$device - $action - $amount");
Expand Down
18 changes: 18 additions & 0 deletions modules/xbmc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
ABOUT: Plays films, tv shows, and controls the playback of XBMC
DEPENDENCIES: None;
*/

$serviceList[] = alice_xbmc_status();

function alice_xbmc_status()
{
if(alice_xbmc_isOn())
{
$sMessage = "Feeling jolly good.";
$sStatus = 0;
}
else
{
$sMessage = "Not feeling too smokey.";
$sStatus = 2;
}
return array("title"=>"XBMC", "message"=>$sMessage, "status"=>$sStatus);
}

function alice_xbmc_talk($data)
{
$data = json_encode($data);
Expand Down
4 changes: 3 additions & 1 deletion recipes/purge-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
if ((date('i') % 2))
{
$con = alice_email_openServer();

if(!$con) goto endPurgeEmail;

$messages = alice_email_getAllMessages($con);
foreach($messages as $msg)
{
Expand Down Expand Up @@ -74,3 +75,4 @@

alice_email_closeServer($con);
}
endPurgeEmail:;

0 comments on commit 466dacc

Please sign in to comment.