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 |
} |