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

Contents of /smsdaemon/plugins/WeatherPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 193 - (show annotations) (download)
Wed Dec 17 23:43:26 2008 UTC (15 years, 5 months ago) by torben
File size: 1203 byte(s)
Util.*, HttpClient.*: 
	make a new Http client based on libcurl and deprecate Util::readUrl
	
WeatherPlugin.cpp, TrainInfo.cpp:
	Make use of HttpClient
	
UrlTriggerPlugin.*:
	Make a new plugin which can trigger an external webapp. and return the response back to the requester




1 #include "WeatherPlugin.h"
2 #include "ISmsTransceiver.h"
3 #include "Sms.h"
4 #include "HttpClient.h"
5 #include "Exceptions.h"
6 #include "Util.h"
7
8 using namespace std;
9 using namespace Util;
10
11 WeatherPlugin::WeatherPlugin()
12 : Plugin("vejr", "Find danish weather report on dmi.dk")
13 {
14 }
15
16 void WeatherPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
17 {
18 string doc;
19 try
20 {
21 doc = HttpClient::GetString("http://www.dmi.dk/dmi/danmark.htm");
22 } catch (httpexception&e ) {
23 modem.SendSms(sms.GetSender(), "could not retrieve data", true);
24 return;
25 }
26
27 int pos = doc.find("<!-- tekst 5 -->");
28 int pos2 = doc.find("</table>",pos);
29
30 string title = doc.substr(pos, (pos2-pos) );
31 title = str_trim( str_striptags(title) ) + "\n";
32
33 pos = doc.find("<table", pos2);
34 pos2 = doc.find("</table>",pos);
35
36 string section = doc.substr(pos, (pos2-pos) );
37 section = str_trim( str_striptags(section) );
38 section = str_characters( section );
39 section = str_replace(section, "\r");
40 section = str_replace(section, " \n");
41
42 section = str_replace(section, " ", " ");
43 section = str_replace(section, "\n\n\n", "\n");
44 section = str_replace(section, "\n\n", "\n");
45
46 modem.SendSms(sms.GetSender(), title + section, true);
47
48
49 }

  ViewVC Help
Powered by ViewVC 1.1.20