Permalink
Browse files

add weather module, fix a js glitch

  • Loading branch information...
allynbauer committed May 5, 2010
1 parent cf1ed62 commit a46b637702fb7b4a4010e67e3622b78709d42a75
View
@@ -1,3 +1,5 @@
+will work in webkit browsers (safari, chrome) without adjustment - will need effort for others
+
modules are for display wrappers - the data must be provided
if you provide args in config to a module, that module will get those args via GET
View
@@ -1,6 +1,7 @@
{
"width": 1030,
"title": "Status Board",
+ "rotate": "no",
"modules": [
{ "name": "clock",
"width": 200,
@@ -18,7 +19,7 @@
{
"name": "bargraph",
"width": 1000,
- "update": 0,
+ "update": 15,
"args": {
"height": 300
}
@@ -30,8 +31,13 @@
},
{
"name": "meta",
- "width": 600,
+ "width": 670,
"update": 0
+ },
+ {
+ "name": "weather",
+ "width": 400,
+ "update": 3600
}
]
}
View
@@ -8,6 +8,17 @@
if (!$data) die('JSON syntax error in "'.CONFIG.'"');
+if ($data->rotate === 'left') {
+ $rotate = '-webkit-transform: rotate(-90deg);';
+}
+elseif ($data->rotate === 'right') {
+ $rotate = '-webkit-transform: rotate(90deg);';
+} else {
+ $rotate = FALSE;
+}
+
+$width = (isset($data->width) ? $data->width . 'px' : '100%');
+
function render($module) {
$argstr = "''";
if (isset($module->args)) {
@@ -34,8 +45,13 @@ function render($module) {
<script type='text/javascript' src='resources/board.js'></script>
<style type='text/css'>
#board {
- width: <?php echo (isset($data->width) ? $data->width . 'px' : '100%') ?>;
- }
+ <?php if ($rotate) {
+ echo $rotate;
+ echo "height: $width;";
+ } else {
+ echo "width: $width;";
+ } ?>
+ }
</style>
</head>
<body>
View
@@ -1,11 +1,24 @@
<?php
+/* DATA */
$num = rand(-99, 99);
+if (rand(0,4) == 0) {
+ $num = 0;
+}
-if ($num > 0) $class = 'uparrow';
-else $class = 'downarrow';
-
+/* DISPLAY */
+if ($num > 0) {
+ $class = 'uparrow';
+ $code = 'A';
+} elseif ($num < 0) {
+ $class = 'downarrow';
+ $code = 'A';
+} else {
+ $class = 'zero-block';
+ $code = 'K';
+}
?>
-<span class='<?php echo $class ?>'>A</span><span class='mega'><?php echo $num ?>%</span>
+<span class='<?php echo $class ?>' id='arrow_icon'><?php echo $code ?></span>
+<span class='mega'><?php echo $num ?>%</span>
@@ -8,14 +8,17 @@ function __construct($name, $height, $header) {
}
}
+/* DATA */
$bars = array();
$bars[] = new Bar('TRANSMIT', 18, '18 / 1');
$bars[] = new Bar('CODA', 29, '29 / 3');
$bars[] = new Bar('UNISON', 48, '48 / 3');
$bars[] = new Bar('CANDYBAR', 8, '8 / 2');
-$bars[] = new Bar('GENERAL', 3, '3 / 0');
+$max = rand(3, 100);
+$bars[] = new Bar('GENERAL', $max, "$max / 0");
+/* DISPLAY */
$max_height = 0;
foreach($bars as $bar) {
if ($bar->height > $max_height)
View
@@ -7,5 +7,5 @@
?>
<p class='jumbo' style='line-height: 50px'>
- <em class='icon'>I</em><?php echo $time; ?>
+ <span class='icon'>H</span><?php echo $time; ?>
</p>
@@ -16,5 +16,5 @@
?>
<p class='jumbo test'>
- <em class='icon'>I</em><?php echo $result; ?>
+ <em class='icon'>H</em><?php echo $result; ?>
</p>
View
@@ -0,0 +1,165 @@
+<?php
+
+// found at php.net
+function xml2array($url, $get_attributes = 1, $priority = 'tag') {
+ $contents = "";
+ if (!function_exists('xml_parser_create'))
+ {
+ return array ();
+ }
+ $parser = xml_parser_create('');
+ if (!($fp = @ fopen($url, 'rb')))
+ {
+ return array ();
+ }
+ while (!feof($fp))
+ {
+ $contents .= fread($fp, 8192);
+ }
+ fclose($fp);
+ xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
+ xml_parse_into_struct($parser, trim($contents), $xml_values);
+ xml_parser_free($parser);
+ if (!$xml_values)
+ return; //Hmm...
+ $xml_array = array ();
+ $parents = array ();
+ $opened_tags = array ();
+ $arr = array ();
+ $current = & $xml_array;
+ $repeated_tag_index = array ();
+ foreach ($xml_values as $data)
+ {
+ unset ($attributes, $value);
+ extract($data);
+ $result = array ();
+ $attributes_data = array ();
+ if (isset ($value))
+ {
+ if ($priority == 'tag')
+ $result = $value;
+ else
+ $result['value'] = $value;
+ }
+ if (isset ($attributes) and $get_attributes)
+ {
+ foreach ($attributes as $attr => $val)
+ {
+ if ($priority == 'tag')
+ $attributes_data[$attr] = $val;
+ else
+ $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
+ }
+ }
+ if ($type == "open")
+ {
+ $parent[$level -1] = & $current;
+ if (!is_array($current) or (!in_array($tag, array_keys($current))))
+ {
+ $current[$tag] = $result;
+ if ($attributes_data)
+ $current[$tag . '_attr'] = $attributes_data;
+ $repeated_tag_index[$tag . '_' . $level] = 1;
+ $current = & $current[$tag];
+ }
+ else
+ {
+ if (isset ($current[$tag][0]))
+ {
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
+ $repeated_tag_index[$tag . '_' . $level]++;
+ }
+ else
+ {
+ $current[$tag] = array (
+ $current[$tag],
+ $result
+ );
+ $repeated_tag_index[$tag . '_' . $level] = 2;
+ if (isset ($current[$tag . '_attr']))
+ {
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
+ unset ($current[$tag . '_attr']);
+ }
+ }
+ $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
+ $current = & $current[$tag][$last_item_index];
+ }
+ }
+ elseif ($type == "complete")
+ {
+ if (!isset ($current[$tag]))
+ {
+ $current[$tag] = $result;
+ $repeated_tag_index[$tag . '_' . $level] = 1;
+ if ($priority == 'tag' and $attributes_data)
+ $current[$tag . '_attr'] = $attributes_data;
+ }
+ else
+ {
+ if (isset ($current[$tag][0]) and is_array($current[$tag]))
+ {
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
+ if ($priority == 'tag' and $get_attributes and $attributes_data)
+ {
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
+ }
+ $repeated_tag_index[$tag . '_' . $level]++;
+ }
+ else
+ {
+ $current[$tag] = array (
+ $current[$tag],
+ $result
+ );
+ $repeated_tag_index[$tag . '_' . $level] = 1;
+ if ($priority == 'tag' and $get_attributes)
+ {
+ if (isset ($current[$tag . '_attr']))
+ {
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
+ unset ($current[$tag . '_attr']);
+ }
+ if ($attributes_data)
+ {
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
+ }
+ }
+ $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
+ }
+ }
+ }
+ elseif ($type == 'close')
+ {
+ $current = & $parent[$level -1];
+ }
+ }
+ return ($xml_array);
+}
+
+
+$zipcode ='50613';
+
+/* DATA */
+while(true) {
+ $url = 'http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=';
+ $data = xml2array($url . $zipcode);
+ if (empty($data)) {
+ sleep(5);
+ } else {
+ break;
+ }
+}
+
+$data = $data['current_observation'];
+
+
+/* DISPLAY */
+?>
+
+<span class='jumbo'>Weather in <?php echo $data['display_location']['city'] ?></span>
+<div>
+ <?php echo $data['temp_f'] . '&deg; F, ' . $data['weather'] ?></li>
+</div>
View
@@ -5,6 +5,6 @@ function render_module(name, args) {
function activate_module(name, seconds, args) {
render_module(name, args);
if (seconds > 0) {
- setInterval("render_module('"+name+"')", (seconds * 1000));
+ setInterval("render_module('"+name+"', '"+args+"')", (seconds * 1000));
}
}
View
@@ -17,10 +17,6 @@
color: #ded00b;
}
-.icon2 {
- font-family: 'Cutouts2';
-}
-
body {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 18px;
@@ -33,9 +29,9 @@ body {
text-align: center;
background-color: #171919;
-webkit-border-radius: 15px;
+ -moz-border-radius: 15px;
border: 5px solid #171919;
margin: 10px;
- min-height: 50px;
}
.jumbo {
@@ -46,20 +42,37 @@ body {
font-size: 40px;
}
+
+
+
+
+
+
+
+
+
+
/* ARROW MODULE */
-.uparrow {
+
+#arrow_icon {
font: normal 65px 'Cutouts';
+ display: block;
+}
+
+.uparrow {
color: #15af00;
- display: block;
}
.downarrow {
- font: normal 65px 'Cutouts';
color: #e31d18;
-webkit-transform: rotate(180deg);
-moz-transform: rotate(180deg);
- display: block;
}
+
+.zero-block {
+ color: #3d69fe;
+}
+
/* END ARROW MODULE */
/* COUNTDOWN MODULE */
@@ -87,6 +100,7 @@ body {
border-width: 5px;
border-style: solid;
-webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
}
#graph_1 {

0 comments on commit a46b637

Please sign in to comment.