/[projects]/smsdaemon/plugins/TrainInfo.cpp
ViewVC logotype

Diff of /smsdaemon/plugins/TrainInfo.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 64 by torben, Thu Jun 12 12:47:32 2008 UTC revision 218 by torben, Thu Mar 26 22:10:28 2009 UTC
# Line 2  Line 2 
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    
18  string ConvertUpdateInfo(char ch)  string ConvertUpdateInfo(char ch)
19  {  {
20          string result;          string result;
21          switch( ch)          switch ( ch)
22          {          {
23                  case '1':          case '1':
24                          result = "< 3 min";                  result = "< 3 min";
25                          break;                  break;
26                  case '2':          case '2':
27                          result = "3 - 10 min";                  result = "3 - 10 min";
28                          break;                  break;
29                  case '3':          case '3':
30                          result = "> 10 min";                  result = "> 10 min";
31                          break;                  break;
32                  case '4':          case '4':
33                          result = "No info";                  result = "No info";
34                          break;                  break;
35                  default:          default:
36                          result = "Unknown";                  result = "Unknown";
37          }          }
38          return result;          return result;
39  }  }
# Line 58  vector<TrainInfo> GetTrainInfo(string st Line 64  vector<TrainInfo> GetTrainInfo(string st
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();
# Line 67  vector<TrainInfo> GetTrainInfo(string st Line 89  vector<TrainInfo> GetTrainInfo(string st
89    
90          unsigned int ankomstpos = html.find("id='ankomsttabel'");          unsigned int ankomstpos = html.find("id='ankomsttabel'");
91    
92          while(1)          while (1)
93          {          {
94                  //start with time                  //start with time
95                  pos = html.find("<td class='tid'>", pos);                  pos = html.find("<td class='tid'>", pos);
# Line 80  vector<TrainInfo> GetTrainInfo(string st Line 102  vector<TrainInfo> GetTrainInfo(string st
102    
103                  TrainInfo info;                  TrainInfo info;
104    
105                  int start = pos+16;                  pos = html.find("<span", pos);
106    
107                    int start = pos;
108                  int stop = html.find("</td>", pos);                  int stop = html.find("</td>", pos);
109    
110                  info.time = html.substr(start, stop-start).c_str();                  info.time = html.substr(start, stop-start).c_str();
# Line 110  vector<TrainInfo> GetTrainInfo(string st Line 134  vector<TrainInfo> GetTrainInfo(string st
134                  info.origin = html.substr(start, stop-start).c_str();                  info.origin = html.substr(start, stop-start).c_str();
135    
136                  //Current location                  //Current location
137          pos++; //since origin and current use the same search pattern, we must increase the position                  pos++; //since origin and current use the same search pattern, we must increase the position
138                        //so we don't get origin twice.                  //so we don't get origin twice.
139                    
140                  pos = html.find( "<td class='visikke'>", pos);                  pos = html.find( "<td class='visikke'>", pos);
141                  start = pos + 20;                  start = pos + 20;
142                  stop = html.find( "</td>", pos);                  stop = html.find( "</td>", pos);

Legend:
Removed from v.64  
changed lines
  Added in v.218

  ViewVC Help
Powered by ViewVC 1.1.20