-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeatherUnderground.cpp
More file actions
116 lines (93 loc) · 2.26 KB
/
WeatherUnderground.cpp
File metadata and controls
116 lines (93 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "WeatherUnderground.h"
WeatherUnderground::WeatherUnderground()
{
this->update();
}
void WeatherUnderground::update(void)
{
//Download JSON-Datei
URLDownloadToFile(NULL, (LPCWSTR) JSONFILE, lFILENAME, NULL, NULL);
//Lese json-Datei
std::string buffer;
std::ifstream in( FILENAME );
copy( std::istreambuf_iterator< char >( in ), std::istreambuf_iterator< char >(), back_inserter( buffer ) );
JSONValue *value = JSON::Parse(buffer.c_str());
JSONObject root;
JSONObject child;
JSONArray jarr;
root = value->AsObject();
if (root.find(L"forecast") != root.end() && root[L"forecast"]->IsObject())
{
root = root[L"forecast"]->AsObject();
root = root[L"simpleforecast"]->AsObject();
jarr = root[L"forecastday"]->AsArray();
root = jarr[0]->AsObject();
child = root[L"high"]->AsObject();
this->max = child[L"celsius"]->AsString().c_str(),5;
child = root[L"low"]->AsObject();
this->min = child[L"celsius"]->AsString().c_str(),5;
this->cond = root[L"conditions"]->AsString().c_str(),30;
child = root[L"avewind"]->AsObject();
this->wind = child[L"kph"]->AsNumber();
this->wdir = child[L"dir"]->AsString().c_str(),20;
this->luft = root[L"avehumidity"]->AsNumber();
}
}
char* WeatherUnderground::maxDayTempC()
{
char ma [5];
wcstombs(ma, this->max.c_str(),5);
return ma;
}
std::wstring WeatherUnderground::maxDayTempW()
{
return this->max;
}
char* WeatherUnderground::minDayTempC()
{
char mi [5];
wcstombs(mi, this->min.c_str(),5);
return mi;
}
std::wstring WeatherUnderground::minDayTempW()
{
return this->min;
}
char* WeatherUnderground::conditionC()
{
char mi [30];
wcstombs(mi, this->cond.c_str(),30);
return mi;
}
std::wstring WeatherUnderground::conditionW()
{
return this->cond;
}
std::wstring WeatherUnderground::windSpeed()
{
wchar_t buffer[256];
std::wstring s;
int slen;
slen = swprintf(buffer, 255, L"%f", this->wind);
s.assign(buffer, slen);
return s;
}
char* WeatherUnderground::windDirectionC()
{
char mi [20];
wcstombs(mi, this->wdir.c_str(),20);
return mi;
}
std::wstring WeatherUnderground::windDirectionW()
{
return this->wdir;
}
std::wstring WeatherUnderground::humidity()
{
wchar_t buffer[256];
std::wstring s;
int slen;
slen = swprintf(buffer, 255, L"%f", this->luft);
s.assign(buffer, slen);
return s;
}