--- smsdaemon/plugins/TrainInfo.cpp 2008/06/11 12:15:14 52 +++ smsdaemon/plugins/TrainInfo.cpp 2008/12/17 23:43:26 193 @@ -2,10 +2,16 @@ #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; @@ -58,12 +64,30 @@ 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(); - unsigned int pos =0; // = html.find("id='ankomsttabel'"); + unsigned int pos =0; + + unsigned int ankomstpos = html.find("id='ankomsttabel'"); while(1) { @@ -73,6 +97,9 @@ if (pos == string::npos) break; + if (pos > ankomstpos) + break; + TrainInfo info; int start = pos+16;