data.js 7.94 KB
Newer Older
EnesKarakas's avatar
EnesKarakas committed
1
2
import React from "react";

Weiser's avatar
Weiser committed
3
4
import Navbar4 from "../components/homepage/navbar4";
import Footer15 from "../components/homepage/footer15";
EnesKarakas's avatar
EnesKarakas committed
5
import "./home.css";
EnesKarakas's avatar
EnesKarakas committed
6
import "./data.css";
EnesKarakas's avatar
EnesKarakas committed
7
8

const Data = (props) => {
EnesKarakas's avatar
EnesKarakas committed
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
  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";
  }
EnesKarakas's avatar
EnesKarakas committed
90
91
92
93
94
95
96

  return (
    <div className="home-container">
      <div className="home-navbar1">
        <Navbar4 rootClassName="navbar4-root-class-name"></Navbar4>
      </div>

EnesKarakas's avatar
EnesKarakas committed
97
98
      <div>
        <div className="thq-grid-5">
EnesKarakas's avatar
EnesKarakas committed
99
          <div class="filter">
EnesKarakas's avatar
EnesKarakas committed
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
            <label for="city">City:</label>
            <input type="text" id="city" placeholder="City" />
            <br />
            <label for="city">Region:</label>
            <input type="text" id="region" placeholder="Region" />
            <br />
            <label>Country:</label>
            <input type="text" id="country" placeholder="Country" />
            <br />
            <label>Latitude:</label>
            <input type="text" id="latitude" placeholder="Latitude" />
            <label>Longitude:</label>
            <input type="text" id="longitude" placeholder="Longitude" />
            <br />
          </div>
          <div>
            <input
              type="checkbox"
              id="temperature"
              className="checkBoxFilter"
            />
            <label> Temprature</label>
            <br />
            <input type="checkbox" id="isDay" className="checkBoxFilter" />
            <label> Is it day?</label>
            <br />
            <input type="checkbox" id="condition" className="checkBoxFilter" />
            <label> Condition</label>
            <br />
            <input type="checkbox" id="pressure" className="checkBoxFilter" />
            <label> Pressure</label>
            <br />
            <input
              type="checkbox"
              id="precipitation"
              className="checkBoxFilter"
            />
            <label> Precipitation</label>
            <br />
            <input type="checkbox" id="humidity" className="checkBoxFilter" />
            <label> Humidity</label>
EnesKarakas's avatar
EnesKarakas committed
141
            <br />
EnesKarakas's avatar
EnesKarakas committed
142
143
            <input type="checkbox" id="cloud" className="checkBoxFilter" />
            <label> Cloud</label>
EnesKarakas's avatar
EnesKarakas committed
144
            <br />
EnesKarakas's avatar
EnesKarakas committed
145
146
147
148
149
150
            <input
              type="checkbox"
              id="feelslikeTemp"
              className="checkBoxFilter"
            />
            <label> Feelslike Temp.</label>
EnesKarakas's avatar
EnesKarakas committed
151
            <br />
EnesKarakas's avatar
EnesKarakas committed
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
            <input type="checkbox" id="visibility" className="checkBoxFilter" />
            <label> Visibility</label>
            <br />
            <input type="checkbox" id="uv" className="checkBoxFilter" />
            <label> UV-Index</label>
            <br />
            <input type="checkbox" id="gust" className="checkBoxFilter" />
            <label> Gust</label>
            <br />
            <input type="checkbox" id="airquality" className="checkBoxFilter" />
            <label> Airquality</label>
            <br />
          </div>
          <div class="filter">
            <label>Temperature Unit:</label>
            <select id="unitTemperature">
              <option value="temp_c">Celsius</option>
              <option value="temp_f">Fahrenheit</option>
            </select>
            <label>Wind speed Unit:</label>
            <select id="unitWindSpeed">
              <option value="wind_kph">km/h</option>
              <option value="wind_mph">Mph</option>
            </select>
            <label>Pressure Unit:</label>
            <select id="unitPressure">
              <option value="pressure_mb">Millibar</option>
              <option value="pressure_in">Inch</option>
            </select>
            <label>Precipitation Unit:</label>
            <select id="unitPrecipitation">
              <option value="precip_mm">Millimeter</option>
              <option value="precip_in">Inch</option>
            </select>
          </div>

          <div class="filter">
            <label>Output:</label>
            <select id="output">
              <option value="local">Local</option>
              <option value="database">API</option>
EnesKarakas's avatar
EnesKarakas committed
193
194
            </select>
            <br />
EnesKarakas's avatar
EnesKarakas committed
195
            <label>Data format:</label>
EnesKarakas's avatar
EnesKarakas committed
196
197
198
199
200
201
            <select id="format">
              <option value="json">JSON</option>
              <option value="csv">CSV</option>
              <option value="xml">XML</option>
            </select>
            <br />
Weiser's avatar
Weiser committed
202
            <button className="APIButton" onClick={searchAPI}>City api</button>
EnesKarakas's avatar
EnesKarakas committed
203
204
          </div>
        </div>
EnesKarakas's avatar
EnesKarakas committed
205
206
207
208
209
        <div>
          <button className="thq-button-filled" onClick={getData}>
            Generate
          </button>
        </div>
EnesKarakas's avatar
EnesKarakas committed
210

EnesKarakas's avatar
EnesKarakas committed
211
212
213
        <div class="output">
          <h2>Output:</h2>
          <br />
EnesKarakas's avatar
EnesKarakas committed
214
215
216
          <pre id="weatherData"></pre>
        </div>
      </div>
EnesKarakas's avatar
EnesKarakas committed
217
218
219
220
221
      <div id="apiUrl">
        <label>API URL:</label>
        <br />
        <input className="input" type="text" id="apiUrloutput" readOnly />
      </div>
EnesKarakas's avatar
EnesKarakas committed
222
223
224
225
226
227
228
229
230

      <div className="home-footer11">
        <Footer15></Footer15>
      </div>
    </div>
  );
};

export default Data;