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

Contents of /smsdaemon/plugins/WeatherPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 188 - (show annotations) (download)
Mon Dec 15 13:27:53 2008 UTC (15 years, 5 months ago) by torben
File size: 1043 byte(s)
First version of a a weather plugin

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

  ViewVC Help
Powered by ViewVC 1.1.20