weatherForecastData.js 14.5 KB
Newer Older
Weiser's avatar
asdf  
Weiser committed
1
2
import React from "react";

Weiser's avatar
new    
Weiser committed
3
import "./weatherForecastData.css";
Weiser's avatar
asdf  
Weiser committed
4
5
6
7
8
9
10

const WeatherForecastData = (props) => {
    return (
        <div className="home-container">
          <div>
            <div className="thq-grid-5">
              <div class="filter">
Weiser's avatar
new    
Weiser committed
11
                 <div>
Weiser's avatar
yippie    
Weiser committed
12
13
                 <label for="location">Location:</label>
                    <input type="text" id="city_text" placeholder="Location" />
Weiser's avatar
new    
Weiser committed
14
                    <br />
Weiser's avatar
yippie    
Weiser committed
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
                    <label for="region">Region:</label>
                    <input type="text" id="region_text" placeholder="Region" />
                    <br />
                    <label>Country:</label>
                    <input type="text" id="country_text" placeholder="Country" />
                    <br />
                    <label>Latitude:</label>
                    <input type="text" id="latitude_text" placeholder="Latitude" />
                    <label>Longitude:</label>
                    <input type="text" id="longitude_text" placeholder="Longitude" />
                    <br />
                  </div>
                  <div>
                    <input type="checkbox" id="name" className="checkBoxFilter" />
                    <label> City Name</label>
                    <br />
                    <input type="checkbox" id="region" className="checkBoxFilter" />
                    <label> Region</label>
                    <br />
                    <input type="checkbox" id="country" className="checkBoxFilter" />
                    <label> Country</label>
                    <br />
                    <input type="checkbox" id="lon" className="checkBoxFilter" />
                    <label> Longitude</label>
                    <br />
                    <input type="checkbox" id="lat" className="checkBoxFilter" />
                    <label> Latitude</label>
                    <br />
                    <input type="checkbox" id="tz_id" className="checkBoxFilter" />
                    <label> Timezone Id</label>
                    <br />
                    <input
                      type="checkbox"
                      id="localtime_epoch"
                      className="checkBoxFilter"
                    />
                    <label> Localtime Epoch</label>
                    <br />
                    <input type="checkbox" id="localtime" className="checkBoxFilter" />
                    <label> Localtime</label>
                    <br />
                    <input
                      type="checkbox"
                      id="last_updated_epoch"
                      className="checkBoxFilter"
                    />
                    <label> Last Updated Epoch</label>
                    <br />
                    <input
                      type="checkbox"
                      id="last_updated"
                      className="checkBoxFilter"
                    />
                    <label> Last Updated</label>
Weiser's avatar
new    
Weiser committed
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
                    <br />
                    <input type="checkbox" id="date" class="checkBoxFilter" />
                    <label for="date">Date</label>
                    <br />
                    <input type="checkbox" id="date_epoch" class="checkBoxFilter" />
                    <label for="date_epoch">Date Epoch</label>
                    <br />
                    <input type="checkbox" id="maxtemp" class="checkBoxFilter" />
                    <label for="maxtemp">Max Temperature</label>
                    <br />
                    <input type="checkbox" id="mintemp" class="checkBoxFilter" />
                    <label for="mintemp">Min Temperature</label>
                    <br />
                    <input type="checkbox" id="avgtemp" class="checkBoxFilter" />
                    <label for="avgtemp">Average Temperature</label>
                    <br />
                    <input type="checkbox" id="maxwind" class="checkBoxFilter" />
                    <label for="maxwind">Max Wind Speed</label>
                    <br />
                    <input type="checkbox" id="totalprecip" class="checkBoxFilter" />
                    <label for="totalprecip">Total Precipitation</label>
                    <br />
                    <input type="checkbox" id="avgvis" class="checkBoxFilter" />
                    <label for="avgvis">Average Visibility</label>
                    <br />
                    <input type="checkbox" id="avghumidity" class="checkBoxFilter" />
                    <label for="avghumidity">Average Humidity</label>
                    <br />
                    <input type="checkbox" id="daily_will_it_rain" class="checkBoxFilter" />
                    <label for="daily_will_it_rain">Daily Will it Rain</label>
                    <br />
                    <input type="checkbox" id="daily_chance_of_rain" class="checkBoxFilter" />
                    <label for="daily_chance_of_rain">Daily Chance of Rain</label>
                    <br />
                    <input type="checkbox" id="daily_will_it_snow" class="checkBoxFilter" />
                    <label for="daily_will_it_snow">Daily Will it Snow</label>
                    <br />
                    <input type="checkbox" id="daily_chance_of_snow" class="checkBoxFilter" />
                    <label for="daily_chance_of_snow">Daily Chance of Snow</label>
                    <br />
                    <input type="checkbox" id="condition_text" class="checkBoxFilter" />
                    <label for="condition_text">Condition Text</label>
                    <br />
                    <input type="checkbox" id="condition_icon" class="checkBoxFilter" />
                    <label for="condition_icon">Condition Icon</label>
                    <br />
                    <input type="checkbox" id="condition_code" class="checkBoxFilter" />
                    <label for="condition_code">Condition Code</label>
                    <br />
                    <input type="checkbox" id="uv" class="checkBoxFilter" />
                    <label for="uv">UV Index</label>
                    <br />
                    <input type="checkbox" id="sunrise" class="checkBoxFilter" />
                    <label for="sunrise">Sunrise</label>
                    <br />
                    <input type="checkbox" id="sunset" class="checkBoxFilter" />
                    <label for="sunset">Sunset</label>
                    <br />
                    <input type="checkbox" id="moonrise" class="checkBoxFilter" />
                    <label for="moonrise">Moonrise</label>
                    <br />
                    <input type="checkbox" id="moonset" class="checkBoxFilter" />
                    <label for="moonset">Moonset</label>
                    <br />
                    <input type="checkbox" id="moon_phase" class="checkBoxFilter" />
                    <label for="moon_phase">Moon Phase</label>
                    <br />
                    <input type="checkbox" id="moon_illumination" class="checkBoxFilter" />
                    <label for="moon_illumination">Moon Illumination</label>
                    <br />
                    <input type="checkbox" id="hour_time_epoch" class="checkBoxFilter" />
                    <label for="hour_time_epoch">Hour Time Epoch</label>
                    <br />
                    <input type="checkbox" id="hour_time" class="checkBoxFilter" />
                    <label for="hour_time">Hour Time</label>
                    <br />
                    <input type="checkbox" id="hour_temp" class="checkBoxFilter" />
                    <label for="hour_temp">Hour Temperature</label>
                    <br />
                    <input type="checkbox" id="hour_is_day" class="checkBoxFilter" />
                    <label for="hour_is_day">Hour Is Day</label>
                    <br />
                    <input type="checkbox" id="hour_condition_text" class="checkBoxFilter" />
                    <label for="hour_condition_text">Hour Condition Text</label>
                    <br />
                    <input type="checkbox" id="hour_condition_icon" class="checkBoxFilter" />
                    <label for="hour_condition_icon">Hour Condition Icon</label>
                    <br />
                    <input type="checkbox" id="hour_condition_code" class="checkBoxFilter" />
                    <label for="hour_condition_code">Hour Condition Code</label>
                    <br />
                    <input type="checkbox" id="hour_wind" class="checkBoxFilter" />
                    <label for="hour_wind">Hour Wind</label>
                    <br />
                    <input type="checkbox" id="hour_wind_degree" class="checkBoxFilter" />
                    <label for="hour_wind_degree">Hour Wind Degree</label>
                    <br />
                    <input type="checkbox" id="hour_wind_dir" class="checkBoxFilter" />
                    <label for="hour_wind_dir">Hour Wind Direction</label>
                    <br />
                    <input type="checkbox" id="hour_pressure" class="checkBoxFilter" />
                    <label for="hour_pressure">Hour Pressure</label>
                    <br />
                    <input type="checkbox" id="hour_precip" class="checkBoxFilter" />
                    <label for="hour_precip">Hour Precipitation</label>
                    <br />
                    <input type="checkbox" id="hour_humidity" class="checkBoxFilter" />
                    <label for="hour_humidity">Hour Humidity</label>
                    <br />
                    <input type="checkbox" id="hour_cloud" class="checkBoxFilter" />
                    <label for="hour_cloud">Hour Cloud</label>
                    <br />
                    <input type="checkbox" id="hour_feelslike" class="checkBoxFilter" />
                    <label for="hour_feelslike">Hour Feels Like</label>
                    <br />
                    <input type="checkbox" id="hour_windchill" class="checkBoxFilter" />
                    <label for="hour_windchill">Hour Wind Chill</label>
                    <br />
                    <input type="checkbox" id="hour_heatindex" class="checkBoxFilter" />
                    <label for="hour_heatindex">Hour Heat Index</label>
                    <br />
                    <input type="checkbox" id="hour_dewpoint" class="checkBoxFilter" />
                    <label for="hour_dewpoint">Hour Dew Point</label>
                    <br />
                    <input type="checkbox" id="hour_vis" class="checkBoxFilter" />
                    <label for="hour_vis">Hour Visibility</label>
                    <br />
                    <input type="checkbox" id="hour_gust" class="checkBoxFilter" />
                    <label for="hour_gust">Hour Gust</label>
                    <br />
                    <input type="checkbox" id="hour_uv" class="checkBoxFilter" />
                    <label for="hour_uv">Hour UV</label>
                    <br />
                <br />
Weiser's avatar
yippie    
Weiser committed
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
                <div>
              <button className="thq-button-filled" onClick={getData}>
                Generate
              </button>
            </div>
            <br />
            <div class="output">
              <h2>Output:</h2>
              <br />
              <pre id="weatherData"></pre>
            </div>
            <div id="apiUrl">
              <label>API URL:</label>
              <br />
              <input className="input" type="text" id="apiUrloutput" readOnly />
Weiser's avatar
asdf  
Weiser committed
218
            </div>
Weiser's avatar
yippie    
Weiser committed
219
220
221
222
223
            <button className="APIButton" onClick={searchAPI}>
              City api
            </button>
            <br />
            <br />
Weiser's avatar
asdf  
Weiser committed
224
225
          </div>
        </div>
Weiser's avatar
yippie    
Weiser committed
226
227
228
      </div>
    </div>
    </div>
Weiser's avatar
asdf  
Weiser committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
      );

  function getData() {
    const city = document.getElementById("city").value;
    const region = document.getElementById("region").value;
    const country = document.getElementById("country").value;
    const latitude = document.getElementById("latitude").value;
    const longitude = document.getElementById("longitude").value;
    const temperature = document.getElementById("temperature").checked;
    const isDay = document.getElementById("isDay").checked;
    const condition = document.getElementById("condition").checked;
    const pressure = document.getElementById("pressure").checked;
    const precipitation = document.getElementById("precipitation").checked;
    const humidity = document.getElementById("humidity").checked;
    const cloud = document.getElementById("cloud").checked;
    const feelslikeTemp = document.getElementById("feelslikeTemp").checked;
    const visibility = document.getElementById("visibility").checked;
    const uv = document.getElementById("uv").checked;
    const gust = document.getElementById("gust").checked;
    const airquality = boolToWord(
      document.getElementById("airquality").checked
    );
    const unitTemperature = document.getElementById("unitTemperature").value;
    const unitWindSpeed = document.getElementById("unitWindSpeed").value;
    const unitPressure = document.getElementById("unitPressure").value;
    const unitPrecipitation =
      document.getElementById("unitPrecipitation").value;
    const output = document.getElementById("output").value;
    const format = document.getElementById("format").value;

    const apiKey = "1244099aeaee4b179e6111803241304";
    const apiUrl = `https://api.weatherapi.com/v1/current.${format}?key=${apiKey}&q=${city}&aqi=${airquality}`;

    fetch(apiUrl)
      .then((response) => {
        if (!response.ok) {
          throw new Error("Network response was not ok");
        }
        return response.json();
      })
      .then((data) => {
        // Wetterdaten anzeigen
        document.getElementById("weatherData").innerText = JSON.stringify(
          data,
          null,
          2
        );
        document.getElementById("apiUrloutput").value = apiUrl;
      })
      .catch((error) => {
        console.error("There was a problem with the fetch operation:", error);
      });
  }
  function searchAPI() {
    const cityInput = document.getElementById("city").value;

    const apiKey = "1244099aeaee4b179e6111803241304";
    const apiUrl = `https://api.weatherapi.com/v1/search.json?key=${apiKey}&q=${cityInput}`;

    fetch(apiUrl)
      .then((response) => {
        if (!response.ok) {
          throw new Error("Network response was not ok");
        }

        return response.json();
      })
      .then((data) => {
        // Wetterdaten anzeigen
        document.getElementById("weatherData").innerText = JSON.stringify(
          data,
          null,
          2
        );
      })
      .catch((error) => {
        console.error("There was a problem with the fetch operation:", error);
      });
  }

  function boolToWord(bool) {
    return bool ? "yes" : "no";
  }

};

export default WeatherForecastData;