2 |
#include "TrainInfo.h" |
#include "TrainInfo.h" |
3 |
|
|
4 |
#include "string_nocase.h" |
#include "string_nocase.h" |
5 |
#include "util.h" |
#include "Util.h" |
6 |
|
#include "Exceptions.h" |
7 |
|
#include "Logger.h" |
8 |
|
|
9 |
|
#include "HttpClient.h" |
10 |
|
|
11 |
#include <vector> |
#include <vector> |
12 |
#include <sstream> |
#include <sstream> |
13 |
|
#include <stdexcept> |
14 |
|
|
15 |
|
|
16 |
using namespace std; |
using namespace std; |
17 |
|
|
64 |
|
|
65 |
string url = string("http://www.bane.dk/visStation.asp?W=FJRN&S=") + stationcode + "&artikelId=4275&statnavn=" + stationname; |
string url = string("http://www.bane.dk/visStation.asp?W=FJRN&S=") + stationcode + "&artikelId=4275&statnavn=" + stationname; |
66 |
|
|
67 |
string raw_doc = Util::readUrl(url, "/tmp/sms_tog.tmp" ); |
//string raw_doc = Util::readUrl(url, "/tmp/sms_tog.tmp" ); |
68 |
|
|
69 |
|
string raw_doc; |
70 |
|
try |
71 |
|
{ |
72 |
|
raw_doc = HttpClient::GetString(url); |
73 |
|
} |
74 |
|
catch (httpexception& e) |
75 |
|
{ |
76 |
|
Logger::logMessage(e.what()); |
77 |
|
} |
78 |
|
|
79 |
|
if (raw_doc == "") |
80 |
|
{ |
81 |
|
throw std::runtime_error("Connection timeout"); |
82 |
|
} |
83 |
|
|
84 |
raw_doc = Util::str_replace(raw_doc, "\"", "'"); |
raw_doc = Util::str_replace(raw_doc, "\"", "'"); |
85 |
|
|
86 |
string_nocase html = raw_doc.c_str(); |
string_nocase html = raw_doc.c_str(); |
87 |
|
|
88 |
unsigned int pos = html.find("id='ankomsttabel'"); |
unsigned int pos =0; |
89 |
|
|
90 |
|
unsigned int ankomstpos = html.find("id='ankomsttabel'"); |
91 |
|
|
92 |
while(1) |
while(1) |
93 |
{ |
{ |
97 |
if (pos == string::npos) |
if (pos == string::npos) |
98 |
break; |
break; |
99 |
|
|
100 |
|
if (pos > ankomstpos) |
101 |
|
break; |
102 |
|
|
103 |
TrainInfo info; |
TrainInfo info; |
104 |
|
|
105 |
int start = pos+16; |
int start = pos+16; |