You are on page 1of 4

WEATHER FORECAST & EMAIL

1. For user registration and login(include farmer’s crop location):

https://youtu.be/p1GmFCGuVjw?feature=shared

Code for website’s homepage

<!DOCTYPE html>
<html>
<head>
<title>Agricultural Weather Forecast</title>
</head>
<body>
<h1>Welcome to Agricultural Weather Forecast</h1>
<p>Please log in to access the weather forecast for your region.</p>
<form action="/login" method="post">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Log In">
</form>
</body>
</html>
2. Location Input and Monitoring:

Provide a form for farmers to enter their crop details and geographical locations.

Save this information in a database for future monitoring and weather notifications.

https://youtu.be/qm4Eih_2p-M?feature=shared

3. Code to extract weather data from weather API

<!DOCTYPE html>
<html>
<head>
<title>Agricultural Weather Forecast</title>
</head>
<body>
<h1>Weather Forecast for Agricultural Region</h1>
<div id="weather-data"></div>

<script>
const apiKey = 'YOUR_API_KEY';
const city = 'CITY_NAME'; // Replace with the name of your agricultural region

// Fetch weather data from the OpenWeatherMap API


fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=$
{apiKey}&units=metric`)
.then(response => response.json())
.then(data => {
const weatherData = `
<h2>${data.name}</h2>
<p>Temperature: ${data.main.temp}°C</p>
<p>Weather: ${data.weather[0].main}</p>
`;
document.getElementById('weather-data').innerHTML = weatherData;
})
.catch(error => {
console.error('Error fetching weather data:', error);
});
</script>
</body>
</html>
4. Sending emails to farmer(INCLUDE WEATHER CONDITION AND METHODS OF PRECAUTIONS)
import requests
import smtplib
from email.message import EmailMessage
from apscheduler.schedulers.blocking import BlockingScheduler

# Define the function to check weather and send email


def send_weather_email(farmer_email, location):
# Make an API call to fetch weather data for the specified location
api_key = "YOUR_WEATHER_API_KEY"
url = f"https://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}"
response = requests.get(url)
weather_data = response.json()

# Extract relevant weather information


temperature = weather_data["main"]["temp"]
weather_description = weather_data["weather"][0]["description"]

# Compose the email message


message = EmailMessage()
message.set_content(f"Today's weather for {location}: {weather_description}, Temperature:
{temperature}K")

message['Subject'] = f"Weather Update for {location}"


message['From'] = "your_email@example.com"
message['To'] = farmer_email

# Set up the SMTP server and send the email


with smtplib.SMTP_SSL('smtp.example.com', 465) as smtp:
smtp.login('your_email@example.com', 'your_email_password')
smtp.send_message(message)

# Define the locations and associated farmer emails


farmer_locations = {"Location1": "farmer1@example.com", "Location2": "farmer2@example.com"}

# Set up the scheduler to send weather updates daily


scheduler = BlockingScheduler()
for location, email in farmer_locations.items():
scheduler.add_job(send_weather_email, 'interval', days=1, args=[email, location])

# Start the scheduler


scheduler.start()
5. User interface will include
User information
Location of crops
Temperature
Weather predictions
Data from historical weather patterns
Precautionary measures to be taken

ONCE THE USER LOGS IN HE WILL ACCESS DATA ABOUT HIS CROPS ONLY

You might also like