Commit 811241e3 authored by EnesKarakas's avatar EnesKarakas
Browse files

xml done

parent 26508673
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",
"react-helmet": "^6.1.0", "react-helmet": "^6.1.0",
"react-router-dom": "^5.2.0" "react-router-dom": "^5.2.0",
"xml-js": "^1.6.11"
}, },
"devDependencies": { "devDependencies": {
"@craco/craco": "^7.1.0", "@craco/craco": "^7.1.0",
...@@ -16509,8 +16510,7 @@ ...@@ -16509,8 +16510,7 @@
"node_modules/sax": { "node_modules/sax": {
"version": "1.2.4", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
"dev": true
}, },
"node_modules/saxes": { "node_modules/saxes": {
"version": "5.0.1", "version": "5.0.1",
...@@ -19459,6 +19459,17 @@ ...@@ -19459,6 +19459,17 @@
} }
} }
}, },
"node_modules/xml-js": {
"version": "1.6.11",
"resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz",
"integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==",
"dependencies": {
"sax": "^1.2.4"
},
"bin": {
"xml-js": "bin/cli.js"
}
},
"node_modules/xml-name-validator": { "node_modules/xml-name-validator": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz",
...@@ -31387,8 +31398,7 @@ ...@@ -31387,8 +31398,7 @@
"sax": { "sax": {
"version": "1.2.4", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
"dev": true
}, },
"saxes": { "saxes": {
"version": "5.0.1", "version": "5.0.1",
...@@ -33680,6 +33690,14 @@ ...@@ -33680,6 +33690,14 @@
"dev": true, "dev": true,
"requires": {} "requires": {}
}, },
"xml-js": {
"version": "1.6.11",
"resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz",
"integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==",
"requires": {
"sax": "^1.2.4"
}
},
"xml-name-validator": { "xml-name-validator": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz",
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",
"react-helmet": "^6.1.0", "react-helmet": "^6.1.0",
"react-router-dom": "^5.2.0" "react-router-dom": "^5.2.0",
"xml-js": "^1.6.11"
}, },
"scripts": { "scripts": {
"start": "craco start", "start": "craco start",
......
...@@ -38,7 +38,11 @@ const Currentdata = (props) => { ...@@ -38,7 +38,11 @@ const Currentdata = (props) => {
}; };
const downloadXml = (weatherdata) => { const downloadXml = (weatherdata) => {
const xml = jsonToXml(weatherdata); var xml = jsonToXml(weatherdata);
xml =
"<?xml version='1.0' encoding='UTF-8' ?><weatherdata>" +
xml +
"</weatherdata>";
const blob = new Blob([xml], { type: "application/xml" }); const blob = new Blob([xml], { type: "application/xml" });
saveAs(blob, "weatherdata.xml"); saveAs(blob, "weatherdata.xml");
}; };
...@@ -49,12 +53,26 @@ const Currentdata = (props) => { ...@@ -49,12 +53,26 @@ const Currentdata = (props) => {
saveAs(blob, "weatherdata.csv"); saveAs(blob, "weatherdata.csv");
}; };
const jsonToXml = (json) => { const jsonToXml = (obj) => {
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n'; var xml = "";
for (let prop in json) { for (var prop in obj) {
xml += ` <${prop}>${json[prop]}</${prop}>\n`; xml += "<" + prop + ">";
if (Array.isArray(obj[prop])) {
for (var array of obj[prop]) {
// A real botch fix here
xml += "</" + prop + ">";
xml += "<" + prop + ">";
xml += jsonToXml(new Object(array));
}
} else if (typeof obj[prop] == "object") {
xml += jsonToXml(new Object(obj[prop]));
} else {
xml += obj[prop];
}
xml += "</" + prop + ">";
} }
xml += "</root>"; var xml = xml.replace(/<\/?[0-9]{1,}>/g, "");
return xml; return xml;
}; };
...@@ -63,6 +81,7 @@ const Currentdata = (props) => { ...@@ -63,6 +81,7 @@ const Currentdata = (props) => {
const values = Object.values(json); const values = Object.values(json);
return `${keys.join(",")}\n${values.join(",")}`; return `${keys.join(",")}\n${values.join(",")}`;
}; };
return ( return (
<div className="home-container"> <div className="home-container">
<div className="thq-grid-5"> <div className="thq-grid-5">
...@@ -536,6 +555,18 @@ const Currentdata = (props) => { ...@@ -536,6 +555,18 @@ const Currentdata = (props) => {
filterArray.push("gust_mph"); filterArray.push("gust_mph");
} }
} }
if (
air_quality_co ||
air_quality_no2 ||
air_quality_o3 ||
air_quality_so2 ||
air_quality_pm2_5 ||
air_quality_pm10 ||
air_quality_us_epa_index ||
air_quality_gb_defra_index
) {
filterArray.push("air_quality");
}
if (air_quality_co) { if (air_quality_co) {
filterArray.push("co"); filterArray.push("co");
} }
...@@ -606,10 +637,6 @@ const Currentdata = (props) => { ...@@ -606,10 +637,6 @@ const Currentdata = (props) => {
console.error("There was a problem with the fetch operation:", error); console.error("There was a problem with the fetch operation:", error);
}); });
} }
function boolToWord(bool) {
return bool ? "yes" : "no";
}
}; };
const ListItem = ({ name, country, region, lat, lon }) => { const ListItem = ({ name, country, region, lat, lon }) => {
......
...@@ -40,7 +40,11 @@ const HistoricalWeatherData = (props) => { ...@@ -40,7 +40,11 @@ const HistoricalWeatherData = (props) => {
}; };
const downloadXml = (weatherdata) => { const downloadXml = (weatherdata) => {
const xml = jsonToXml(weatherdata); var xml = jsonToXml(weatherdata);
xml =
"<?xml version='1.0' encoding='UTF-8' ?><weatherdata>" +
xml +
"</weatherdata>";
const blob = new Blob([xml], { type: "application/xml" }); const blob = new Blob([xml], { type: "application/xml" });
saveAs(blob, "weatherdata.xml"); saveAs(blob, "weatherdata.xml");
}; };
...@@ -51,12 +55,26 @@ const HistoricalWeatherData = (props) => { ...@@ -51,12 +55,26 @@ const HistoricalWeatherData = (props) => {
saveAs(blob, "weatherdata.csv"); saveAs(blob, "weatherdata.csv");
}; };
const jsonToXml = (json) => { const jsonToXml = (obj) => {
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n'; var xml = "";
for (let prop in json) { for (var prop in obj) {
xml += ` <${prop}>${json[prop]}</${prop}>\n`; xml += "<" + prop + ">";
if (Array.isArray(obj[prop])) {
for (var array of obj[prop]) {
// A real botch fix here
xml += "</" + prop + ">";
xml += "<" + prop + ">";
xml += jsonToXml(new Object(array));
}
} else if (typeof obj[prop] == "object") {
xml += jsonToXml(new Object(obj[prop]));
} else {
xml += obj[prop];
}
xml += "</" + prop + ">";
} }
xml += "</root>"; var xml = xml.replace(/<\/?[0-9]{1,}>/g, "");
return xml; return xml;
}; };
......
...@@ -38,7 +38,11 @@ const WeatherForecastData = (props) => { ...@@ -38,7 +38,11 @@ const WeatherForecastData = (props) => {
}; };
const downloadXml = (weatherdata) => { const downloadXml = (weatherdata) => {
const xml = jsonToXml(weatherdata); var xml = jsonToXml(weatherdata);
xml =
"<?xml version='1.0' encoding='UTF-8' ?><weatherdata>" +
xml +
"</weatherdata>";
const blob = new Blob([xml], { type: "application/xml" }); const blob = new Blob([xml], { type: "application/xml" });
saveAs(blob, "weatherdata.xml"); saveAs(blob, "weatherdata.xml");
}; };
...@@ -49,12 +53,26 @@ const WeatherForecastData = (props) => { ...@@ -49,12 +53,26 @@ const WeatherForecastData = (props) => {
saveAs(blob, "weatherdata.csv"); saveAs(blob, "weatherdata.csv");
}; };
const jsonToXml = (json) => { const jsonToXml = (obj) => {
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n'; var xml = "";
for (let prop in json) { for (var prop in obj) {
xml += ` <${prop}>${json[prop]}</${prop}>\n`; xml += "<" + prop + ">";
if (Array.isArray(obj[prop])) {
for (var array of obj[prop]) {
// A real botch fix here
xml += "</" + prop + ">";
xml += "<" + prop + ">";
xml += jsonToXml(new Object(array));
}
} else if (typeof obj[prop] == "object") {
xml += jsonToXml(new Object(obj[prop]));
} else {
xml += obj[prop];
} }
xml += "</root>"; xml += "</" + prop + ">";
}
var xml = xml.replace(/<\/?[0-9]{1,}>/g, "");
return xml; return xml;
}; };
...@@ -162,11 +180,7 @@ const WeatherForecastData = (props) => { ...@@ -162,11 +180,7 @@ const WeatherForecastData = (props) => {
/> />
<label> Localtime Epoch</label> <label> Localtime Epoch</label>
<br /> <br />
<input <input type="checkbox" id="localtime" className="checkBoxFilter" />
type="checkbox"
id="localtime"
className="checkBoxFilter"
/>
<label> Localtime</label> <label> Localtime</label>
<br /> <br />
<input <input
...@@ -282,7 +296,6 @@ const WeatherForecastData = (props) => { ...@@ -282,7 +296,6 @@ const WeatherForecastData = (props) => {
class="checkBoxFilter" class="checkBoxFilter"
/> />
<label for="hour_time_epoch">Hour Time Epoch</label> <label for="hour_time_epoch">Hour Time Epoch</label>
</div> </div>
<div class="data"> <div class="data">
<div class="h3"> <div class="h3">
...@@ -307,59 +320,31 @@ const WeatherForecastData = (props) => { ...@@ -307,59 +320,31 @@ const WeatherForecastData = (props) => {
/> />
<label for="hour_wind_degree">Hour Wind Degree</label> <label for="hour_wind_degree">Hour Wind Degree</label>
<br /> <br />
<input <input type="checkbox" id="hour_wind_dir" class="checkBoxFilter" />
type="checkbox"
id="hour_wind_dir"
class="checkBoxFilter"
/>
<label for="hour_wind_dir">Hour Wind Direction</label> <label for="hour_wind_dir">Hour Wind Direction</label>
<br /> <br />
<input <input type="checkbox" id="hour_pressure" class="checkBoxFilter" />
type="checkbox"
id="hour_pressure"
class="checkBoxFilter"
/>
<label for="hour_pressure">Hour Pressure</label> <label for="hour_pressure">Hour Pressure</label>
<br /> <br />
<input type="checkbox" id="hour_precip" class="checkBoxFilter" /> <input type="checkbox" id="hour_precip" class="checkBoxFilter" />
<label for="hour_precip">Hour Precipitation</label> <label for="hour_precip">Hour Precipitation</label>
<br /> <br />
<input <input type="checkbox" id="hour_humidity" class="checkBoxFilter" />
type="checkbox"
id="hour_humidity"
class="checkBoxFilter"
/>
<label for="hour_humidity">Hour Humidity</label> <label for="hour_humidity">Hour Humidity</label>
<br /> <br />
<input type="checkbox" id="hour_cloud" class="checkBoxFilter" /> <input type="checkbox" id="hour_cloud" class="checkBoxFilter" />
<label for="hour_cloud">Hour Cloud</label> <label for="hour_cloud">Hour Cloud</label>
<br /> <br />
<input <input type="checkbox" id="hour_feelslike" class="checkBoxFilter" />
type="checkbox"
id="hour_feelslike"
class="checkBoxFilter"
/>
<label for="hour_feelslike">Hour Feels Like</label> <label for="hour_feelslike">Hour Feels Like</label>
<br /> <br />
<input <input type="checkbox" id="hour_windchill" class="checkBoxFilter" />
type="checkbox"
id="hour_windchill"
class="checkBoxFilter"
/>
<label for="hour_windchill">Hour Wind Chill</label> <label for="hour_windchill">Hour Wind Chill</label>
<br /> <br />
<input <input type="checkbox" id="hour_heatindex" class="checkBoxFilter" />
type="checkbox"
id="hour_heatindex"
class="checkBoxFilter"
/>
<label for="hour_heatindex">Hour Heat Index</label> <label for="hour_heatindex">Hour Heat Index</label>
<br /> <br />
<input <input type="checkbox" id="hour_dewpoint" class="checkBoxFilter" />
type="checkbox"
id="hour_dewpoint"
class="checkBoxFilter"
/>
<label for="hour_dewpoint">Hour Dew Point</label> <label for="hour_dewpoint">Hour Dew Point</label>
<br /> <br />
<input <input
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment