React Weather Broadcast

Developer
Size
6,708 Kb
Views
8,096

How do I make an react weather broadcast?

This app will detect your location and show the current weather and 4 day broadcast for your location. You can also search other locations. DOES NOT WORK WITH HTTPS. USE HTTP.. What is a react weather broadcast? How do you make a react weather broadcast? This script and codes were developed by Mihkel on 08 December 2022, Thursday.

React Weather Broadcast Previews

React Weather Broadcast - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>React Weather Broadcast</title> <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <meta name="viewport" content="width=device-width, initial-scale=1">
<div id="main"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

React Weather Broadcast - Script Codes CSS Codes

body { background-color: #191919;
}
.input-group-addon:hover { cursor: pointer;
}
input.form-control,
input.form-control:focus { border: none; box-shadow: none; -webkit-box-shadow: none; -moz-box-shadow: none; -moz-transition: none; -webkit-transition: none;
}

React Weather Broadcast - Script Codes JS Codes

"use strict";
// DOES NOT WORK WITH HTTPS
// USE https://codepen.io/Krokodill/full/vLwqpJ/
var HTTP = {	baseUrl: "http://api.openweathermap.org/data/2.5/forecast?q=",	key: "&appid=dbb624c32c7f0d652500552c5ebbde56",	get: function get(city) {	return fetch(this.baseUrl + city + this.key).then(function (response) {	return response.json();	});	}
};
var Form = React.createClass({	displayName: "Form",	getInitialState: function getInitialState() {	return { formValue: "" };	},	onChange: function onChange(e) {	this.setState({ formValue: e.target.value });	},	clear: function clear() {	this.setState({ formValue: "" });	},	render: function render() {	var iconStyle = {	background: "#B91111",	color: "#FFF",	border: 0	};	return React.createElement(	"form",	{ action: "", method: "", onSubmit: this.props.callback },	React.createElement(	"div",	{ className: "col-xs-12 input-group" },	React.createElement(	"div",	{ className: "input-group" },	React.createElement("input", { type: "text", className: "form-control", placeholder: "Location..",	value: this.state.formValue,	onChange: this.onChange	}),	React.createElement(	"span",	{ onClick: this.props.callback, className: "input-group-addon", style: iconStyle },	React.createElement("i", { className: "glyphicon glyphicon-search" })	)	)	)	);	}
});
var Wind = React.createClass({	displayName: "Wind",	windDirection: function windDirection(windDeg) {	var wind = "";	if (windDeg > 340 && windDeg <= 20) {	wind = "North";	} else if (windDeg > 20 && windDeg <= 70) {	wind = "North-East";	} else if (windDeg > 70 && windDeg <= 110) {	wind = "East";	} else if (windDeg > 110 && windDeg <= 160) {	wind = "South-East";	} else if (windDeg > 160 && windDeg <= 200) {	wind = "South";	} else if (windDeg > 200 && windDeg <= 250) {	wind = "South-West";	} else if (windDeg > 250 && windDeg <= 290) {	wind = "West";	} else if (windDeg > 290 && windDeg <= 340) {	wind = "North-West";	}	return wind;	},	render: function render() {	var spanStyle = { float: "right" };	return React.createElement(	"div",	{ className: "row" },	React.createElement(	"div",	{ className: "col-xs-12" },	React.createElement("img", { src: "http://icons.iconarchive.com/icons/handdrawngoods/sunny-weather/128/07-wind-breeze-icon.png", className: "img-responsive", width: "35", height: "35", alt: "wind-icon" }),	React.createElement(	"span",	null,	this.props.wind + " m/s"	),	React.createElement(	"span",	{ style: spanStyle },	this.windDirection(this.props.windDeg)	)	)	);	}
});
var CurrentWeather = React.createClass({	displayName: "CurrentWeather",	convert: function convert(temp) {	return (temp - 273.15).toFixed(1) + "°C";	},	getDate: function getDate(date) {	var d = new Date(date * 1000);	return d.toDateString().slice(0, 10);	},	render: function render() {	var inline = { display: "inline" };	var inlineBlock = { display: "inline-block" };	var mt = { marginTop: 5 };	return React.createElement(	"div",	null,	React.createElement(	"div",	{ className: "row" },	React.createElement("br", null),	React.createElement(	"div",	{ className: "col-xs-12" },	React.createElement(	"h2",	{ style: inline },	this.props.city	),	React.createElement(	"p",	null,	this.getDate(this.props.date)	)	)	),	React.createElement("br", null),	React.createElement(	"div",	{ className: "row" },	React.createElement(	"div",	{ className: "col-xs-6 col-xs-offset-3 text-center" },	React.createElement("img", { style: inlineBlock, src: this.props.weatherIcon, alt: "icon", className: "img-responsive" }),	React.createElement(	"h2",	{ style: mt },	this.convert(this.props.celsius)	),	React.createElement(	"p",	null,	this.props.meta	)	)	),	React.createElement("br", null),	React.createElement(Wind, { wind: this.props.wind, windDeg: this.props.windDeg })	);	}
});
var ForecastCol = React.createClass({	displayName: "ForecastCol",	getDate: function getDate(timestamp) {	var d = new Date(timestamp * 1000);	return d.toDateString().slice(0, 10);	},	convert: function convert(temp) {	var celsius = (temp - 273.15).toFixed(1) + "°C";	var fahrenheit = (parseFloat(celsius, 10) * (9 / 5) + 32).toFixed(2) + "°F";	return celsius + " / " + fahrenheit;	},	setImgUrl: function setImgUrl(icon) {	return "http://openweathermap.org/img/w/" + icon + ".png";	},	render: function render() {	var imgStyle = {	margin: "0 auto"	};	var paraStyle = {	marginTop: 10,	fontWeight: 600	};	return React.createElement(	"div",	{ className: "row" },	React.createElement(	"div",	{ className: "col-xs-4" },	React.createElement(	"p",	{ style: paraStyle },	this.getDate(this.props.forecastDate)	)	),	React.createElement(	"div",	{ className: "col-xs-4" },	React.createElement("img", { src: this.setImgUrl(this.props.forecastIcon), style: imgStyle, className: "img-responsive", alt: "forecast-icon" })	),	React.createElement(	"div",	{ className: "col-xs-4" },	React.createElement(	"p",	{ className: "text-right", style: paraStyle },	this.convert(this.props.forecastTemp)	)	)	);	}
});
var WeatherContainer = React.createClass({	displayName: "WeatherContainer",	getInitialState: function getInitialState() {	return {	city: "",	date: "",	celsius: "",	weatherIcon: "",	wind: "",	windDeg: "",	meta: "",	forecastData: []	};	},	setter: function setter(data) {	this.setState({	city: data.city.name,	date: data.list[0].dt,	celsius: data.list[0].main.temp,	weatherIcon: "http://openweathermap.org/img/w/" + data.list[0].weather[0].icon + ".png",	wind: data.list[0].wind.speed,	windDeg: data.list[0].wind.deg,	meta: data.list[0].weather[0].description,	forecastData: data	});	},	componentWillMount: function componentWillMount() {	$.getJSON("http://ipinfo.io", function (data) {	var coords = data.loc.split(",");	var lat = (Math.floor(parseFloat(coords[0]) * 100) / 100).toFixed(2);	var long = (Math.floor(parseFloat(coords[1]) * 100) / 100).toFixed(2);	var weatherUrl = "http://api.openweathermap.org/data/2.5/forecast?lat=";	weatherUrl += lat + "&lon=" + long + "&appid=dbb624c32c7f0d652500552c5ebbde56";	$.getJSON(weatherUrl, function (data) {	this.setter(data);	}.bind(this));	}.bind(this));	},	onSubmit: function onSubmit(e) {	e.preventDefault();	var location = this.refs.form.state.formValue;	HTTP.get(location).then(function (data) {	this.refs.form.clear();	this.setter(data);	}.bind(this));	},	render: function render() {	if (this.state.forecastData.length === 0) return null;	var colStyle = {	marginTop: 80	};	var panel = {	borderRadius: 7,	border: 0	};	var panelHead = {	background: "#EC4444",	color: "#FFF"	};	var rows = [];	for (var i = 1; i < 40; i++) {	if (i % 8 === 0) {	rows.push(React.createElement(ForecastCol, {	key: i,	forecastDate: this.state.forecastData.list[i].dt,	forecastIcon: this.state.forecastData.list[i].weather[0].icon,	forecastTemp: this.state.forecastData.list[i].main.temp	}));	}	}	return React.createElement(	"div",	{ className: "container" },	React.createElement(	"div",	{ style: colStyle, className: "col-xs-12 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3 col-lg-5 col-lg-offset-3" },	React.createElement(	"div",	{ style: panel, className: "panel panel-default" },	React.createElement(	"div",	{ style: panelHead, className: "panel-heading" },	React.createElement(Form, { callback: this.onSubmit, ref: "form" }),	React.createElement(CurrentWeather, {	city: this.state.city,	date: this.state.date,	celsius: this.state.celsius,	weatherIcon: this.state.weatherIcon,	meta: this.state.meta,	wind: this.state.wind,	windDeg: this.state.windDeg	})	),	React.createElement(	"div",	{ className: "panel-body" },	React.createElement(	"div",	{ className: "col-xs-12" },	React.createElement(	"div",	{ className: "row" },	rows	)	)	)	)	)	);	}
});
ReactDOM.render(React.createElement(WeatherContainer, null), document.getElementById("main"));
React Weather Broadcast - Script Codes
React Weather Broadcast - Script Codes
Home Page Home
Developer Mihkel
Username Krokodill
Uploaded December 08, 2022
Rating 3
Size 6,708 Kb
Views 8,096
Do you need developer help for React Weather Broadcast?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Mihkel (Krokodill) Script Codes
Create amazing love letters with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!