--- smsdaemon/plugins/TrainInfo.cpp 2008/06/15 19:33:02 81 +++ smsdaemon/plugins/TrainInfo.cpp 2009/03/26 22:10:28 218 @@ -2,7 +2,11 @@ #include "TrainInfo.h" #include "string_nocase.h" -#include "util.h" +#include "Util.h" +#include "Exceptions.h" +#include "Logger.h" + +#include "HttpClient.h" #include #include @@ -14,22 +18,22 @@ string ConvertUpdateInfo(char ch) { string result; - switch( ch) + switch ( ch) { - case '1': - result = "< 3 min"; - break; - case '2': - result = "3 - 10 min"; - break; - case '3': - result = "> 10 min"; - break; - case '4': - result = "No info"; - break; - default: - result = "Unknown"; + case '1': + result = "< 3 min"; + break; + case '2': + result = "3 - 10 min"; + break; + case '3': + result = "> 10 min"; + break; + case '4': + result = "No info"; + break; + default: + result = "Unknown"; } return result; } @@ -60,7 +64,17 @@ string url = string("http://www.bane.dk/visStation.asp?W=FJRN&S=") + stationcode + "&artikelId=4275&statnavn=" + stationname; - string raw_doc = Util::readUrl(url, "/tmp/sms_tog.tmp" ); + //string raw_doc = Util::readUrl(url, "/tmp/sms_tog.tmp" ); + + string raw_doc; + try + { + raw_doc = HttpClient::GetString(url); + } + catch (httpexception& e) + { + Logger::logMessage(e.what()); + } if (raw_doc == "") { @@ -75,7 +89,7 @@ unsigned int ankomstpos = html.find("id='ankomsttabel'"); - while(1) + while (1) { //start with time pos = html.find("", pos); @@ -88,7 +102,9 @@ TrainInfo info; - int start = pos+16; + pos = html.find("", pos); info.time = html.substr(start, stop-start).c_str(); @@ -118,9 +134,9 @@ info.origin = html.substr(start, stop-start).c_str(); //Current location - pos++; //since origin and current use the same search pattern, we must increase the position - //so we don't get origin twice. - + pos++; //since origin and current use the same search pattern, we must increase the position + //so we don't get origin twice. + pos = html.find( "", pos); start = pos + 20; stop = html.find( "", pos);