--- smsdaemon/plugins/TrainInfo.cpp 2008/06/12 12:47:32 64 +++ smsdaemon/plugins/TrainInfo.cpp 2009/03/26 22:10:28 218 @@ -2,32 +2,38 @@ #include "TrainInfo.h" #include "string_nocase.h" -#include "util.h" +#include "Util.h" +#include "Exceptions.h" +#include "Logger.h" + +#include "HttpClient.h" #include #include +#include + using namespace std; 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; } @@ -58,7 +64,23 @@ 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 == "") + { + throw std::runtime_error("Connection timeout"); + } + raw_doc = Util::str_replace(raw_doc, "\"", "'"); string_nocase html = raw_doc.c_str(); @@ -67,7 +89,7 @@ unsigned int ankomstpos = html.find("id='ankomsttabel'"); - while(1) + while (1) { //start with time pos = html.find("", pos); @@ -80,7 +102,9 @@ TrainInfo info; - int start = pos+16; + pos = html.find("", pos); info.time = html.substr(start, stop-start).c_str(); @@ -110,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);