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

Contents of /smsdaemon/plugins/WeatherPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 196 - (show annotations) (download)
Thu Dec 18 06:53:29 2008 UTC (15 years, 5 months ago) by torben
File size: 1205 byte(s)
Make pretty

astyle -t -b -N

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 }
23 catch (httpexception&e )
24 {
25 modem.SendSms(sms.GetSender(), "could not retrieve data", true);
26 return;
27 }
28
29 int pos = doc.find("<!-- tekst 5 -->");
30 int pos2 = doc.find("</table>",pos);
31
32 string title = doc.substr(pos, (pos2-pos) );
33 title = str_trim( str_striptags(title) ) + "\n";
34
35 pos = doc.find("<table", pos2);
36 pos2 = doc.find("</table>",pos);
37
38 string section = doc.substr(pos, (pos2-pos) );
39 section = str_trim( str_striptags(section) );
40 section = str_characters( section );
41 section = str_replace(section, "\r");
42 section = str_replace(section, " \n");
43
44 section = str_replace(section, " ", " ");
45 section = str_replace(section, "\n\n\n", "\n");
46 section = str_replace(section, "\n\n", "\n");
47
48 modem.SendSms(sms.GetSender(), title + section, true);
49
50
51 }

  ViewVC Help
Powered by ViewVC 1.1.20