function get_last_query_result($svc)
{
	//free subscription currently allows 10 request per minute, 500 requests per day
	$delay = _DELAY;
	$conditions = array('conditions'=>array('value = ?', 'MrpLastWeatherResults'));
	$MrpLastWeatherResults = MythSettings::first($conditions);
	
	if(empty($MrpLastWeatherResults)){
		$MrpLastWeatherResults = new MythSettings();
		$MrpLastWeatherResults->value = 'MrpLastWeatherResults';
		//TODO: refactor
		$MrpLastWeatherResults->hostname = new DateTime("-$delay seconds"); //init with obsolete timestamp
		$MrpLastWeatherResults->save(); 
	}
	
	$lastCall = new DateTime($MrpLastWeatherResults->hostname);
	$tooSoon = new DateTime("-$delay seconds"); 
	if($lastCall <= $tooSoon || empty($MrpLastWeatherResults->data))
	{
		try{
			error_log(">>>calling weather service: $svc", 0);
			
			$data = new SimpleXMLElement($svc, NULL, TRUE);			
			if(can_process_feed($data))
				$MrpLastWeatherResults->data = gzcompress($data->asXML(), 9);
			else 
				return $data;
		}catch (Exception $e){
			return new SimpleXMLElement("<error> <type>Exception</type> <description>". $e->getMessage() ."</description> </error>");
		}
		$MrpLastWeatherResults->hostname = new DateTime();
		$MrpLastWeatherResults->save();
	}
	
	error_log(">>>using stored weather results: $MrpLastWeatherResults->hostname", 0);
	return simplexml_load_string(gzuncompress($MrpLastWeatherResults->data));	
}
Example #2
0
function useUTC(){
	if(!defined('_UTC')){
		$conditions = array('conditions'=>array('value = ?', 'DBSchemaVer'));
		$settings = MythSettings::first($conditions);
		$value = $settings->data;		
		error_log(">>> DB SCHEMA: $value", 0);
		
		define('_UTC', (int)$value >= (int)DB_UTC_VER ? true:false);		
	}
	return _UTC == true; 
}