I have a script that pulls in data from a website.
My host seems to have a regular problem with the connection and I cannot grab the data often. I get a message displayed that the "operation now in progress(115)"
What I would like to do is, when the data is able to be grabbed, have it also write to a text file. Then, the next time the page is loaded, and it cannot grab the data from the url, grab it from the text file. I'd also need it to overwrite the old data in the text file the next time it was able to get it from the URL.
I hope this made sense.
Here is the data that is grabed by the script:
http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=USMI0704
This is the code I have that grabs the data from the URL.
if (!$accid) {
$accid="USMI0704"; # Your default city location code, replace IDXX0005 with your city acid code.
// $accid="DTW";
}
if (!$tp) {
$tp=F; # Your Default temperature unit (C for Celsius, F for Fahrenheit)
}
# Fonts Setting
################
$fontface="Arial";
$fontcolor1="#000000";
$fontcolor2="red";
$fontsize1="1";
$fontsize2="3";
$fontsize3="4";
function WeatherIndex($tp) {
global $accid, $tp;
$fa = @fsockopen("www.msnbc.com", 80, &$num_error, &$str_error, 30);
if(!$fa)
{ print "Weather is not available: $str_error ($num_error)\n"; }
else
{
fputs($fa,"GET /m/chnk/d/weather_d_src.asp?acid=$accid HTTP/1.0\n\n");
$answer=fgets($fa,128);
$v_City = "";
$v_State = "";
$v_Country = "";
$v_Region = "";
$v_Temp = "";
$v_CIcon = "";
$v_Condition = "";
$v_WindS = "";
$v_WindD = "";
$v_Baro = "";
$v_Humid = "";
$v_Real = "";
$v_UV = "";
$v_Vis = "";
$v_LastUp = "";
$v_Fore = "";
$v_Acid = "";
while (!feof($fa))
{
$grabline = fgets($fa, 4096);
$grabline= trim($grabline) . "\n";
if (substr($grabline,7,4) == "City") { $v_City = substr($grabline,15,20); }
if (substr($grabline,7,6) == "SubDiv") { $v_SubDiv = substr($grabline,17,20); }
if (substr($grabline,7,7) == "Country") { $v_Country = substr($grabline,18,20); }
if (substr($grabline,7,6) == "Region") { $v_Region = substr($grabline,17,20); }
if (substr($grabline,7,5) == "Temp ") { $v_Temp = substr($grabline,15,20); }
if (substr($grabline,7,5) == "CIcon") { $v_CIcon = substr($grabline,16,20); }
if (substr($grabline,7,3) == "Condition") { $v_Condition = substr($grabline,14,20); }
if (substr($grabline,7,5) == "WindS") { $v_WindS = substr($grabline,16,20); }
if (substr($grabline,7,5) == "WindD") { $v_WindD = substr($grabline,16,20); }
if (substr($grabline,7,4) == "Baro") { $v_Baro = substr($grabline,15,20); }
if (substr($grabline,7,5) == "Humid") { $v_Humid = substr($grabline,16,20); }
if (substr($grabline,7,4) == "Real") { $v_Real = substr($grabline,15,20); }
if (substr($grabline,7,2) == "UV") { $v_UV = substr($grabline,13,20); }
if (substr($grabline,7,3) == "Vis") { $v_Vis = substr($grabline,14,20); }
if (substr($grabline,7,6) == "LastUp") { $v_LastUp = substr($grabline,17,19); }
if (substr($grabline,7,4) == "Fore") { $v_Fore = substr($grabline,15,200); }
if (substr($grabline,7,4) == "Acid") { $v_Acid = substr($grabline,15,20); }
// print $grabline . "\n";
}
$v_City = substr($v_City,0,strlen($v_City)-3);
$v_SubDiv = substr($v_SubDiv,0,strlen($v_SubDiv)-3);
$v_Country = substr($v_Country,0,strlen($v_Country)-3);
$v_Region = substr($v_Region,0,strlen($v_Region)-3);
$v_Temp = substr($v_Temp,0,strlen($v_Temp)-3);
$v_CIcon = substr($v_CIcon,0,strlen($v_CIcon)-3);
$v_Condition = substr($v_Condition,0,strlen($v_C)-3);
$v_WindS = substr($v_WindS,0,strlen($v_WindS)-3);
$v_WindD = substr($v_WindD,0,strlen($v_WindD)-3);
$v_Baro = substr($v_Baro,0,strlen($v_Baro)-3);
$v_Humid = substr($v_Humid,0,strlen($v_Humid)-3);
$v_Real = substr($v_Real,0,strlen($v_Real)-3);
$v_UV = substr($v_UV,0,strlen($v_UV)-3);
$v_Vis = substr($v_Vis,0,strlen($v_Vis)-3);
$v_LastUp = substr($v_LastUp,0,strlen($v_LastUp)-3);
$v_Fore = substr($v_Fore,0,strlen($v_Fore)-3);
$v_Acid = substr($v_Acid,0,strlen($v_Acid)-3);
$v_Fore = explode("|", $v_Fore);