currentData.js 5.75 KB
Newer Older
Weiser's avatar
Weiser committed
1
2
import React from "react";

Weiser's avatar
fusion    
Weiser committed
3
import "./currentData.css";
Weiser's avatar
Weiser committed
4

Weiser's avatar
fusion    
Weiser committed
5
const Currentdata = (props) => {
Weiser's avatar
Weiser committed
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
    return (
        <div className="home-container">
          <div>
            <div className="thq-grid-5">
              <div class="filter">
                <label for="location">Location:</label>
                <input type="text" id="location" placeholder="Location" />
                <br />
                <label for="region">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="location" className="checkBoxFilter" />
                <label> Location</label>
                <br />
                <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 />
Weiser's avatar
fusion    
Weiser committed
54
55
56
57
58
59
60
                <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>
                <br />
                <br />
Weiser's avatar
Weiser committed
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
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
                <br />
              </div>
            </div>
          </div>
        </div>
      );

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

};

Weiser's avatar
fusion    
Weiser committed
152
export default Currentdata;