Skip to content

Rain Alert Notification #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a03afa6
Python code for crypto price checker
vkb20 Oct 14, 2021
2d1e3ca
Add files via upload
vkb20 Oct 14, 2021
49ad542
Create check.py
vkb20 Oct 14, 2021
0e3ba83
Add files via upload
vkb20 Oct 14, 2021
9c89100
Delete check.py
vkb20 Oct 14, 2021
5044487
Update README.md
vkb20 Oct 14, 2021
efcfc8c
Create rain_alert_notification.py
vkb20 Oct 30, 2021
f695371
Add files via upload
vkb20 Oct 30, 2021
f66e7a0
Update README.md
vkb20 Oct 30, 2021
dcd6155
Update README.md
vkb20 Oct 30, 2021
51a33bf
Update README.md
vkb20 Oct 30, 2021
c01793b
Update README.md
vkb20 Oct 30, 2021
fcff1cb
Update README.md
vkb20 Oct 30, 2021
1776518
Add files via upload
vkb20 Oct 30, 2021
c2a4bee
Create rain_alert_notification.py
vkb20 Oct 30, 2021
8898f8f
Add files via upload
vkb20 Oct 30, 2021
474c650
Delete rain_alert_notification.py
vkb20 Oct 30, 2021
a0888d9
Create empty.txt
vkb20 Oct 30, 2021
031882e
Add files via upload
vkb20 Oct 30, 2021
a428fc5
Delete AutomationScripts/Rain Alert Notification/related files directory
vkb20 Oct 30, 2021
ca55f28
Delete AutomationScripts/Rain Alert Notification directory
vkb20 Oct 31, 2021
0a387c7
Create pull_request_template.md
vkb20 Oct 31, 2021
2a1dc5a
Create rain_alert_notification.py
vkb20 Oct 31, 2021
9dfac8e
Add files via upload
vkb20 Oct 31, 2021
ff0d750
Update README.md
vkb20 Oct 31, 2021
fc51212
Add files via upload
vkb20 Oct 31, 2021
dc3319b
Add files via upload
vkb20 Oct 31, 2021
2eb3c36
Create rain_alert_notification.py
vkb20 Oct 31, 2021
e89a780
Add files via upload
vkb20 Oct 31, 2021
1916ed8
Delete rain_alert_notification.py
vkb20 Oct 31, 2021
b23810c
Create pull_request_template.md
vkb20 Oct 31, 2021
d93f393
Delete WebScrapingScripts/crypto_price_checker directory
vkb20 Oct 31, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Related Issue

- Using python script to navigate to https://openweathermap.org/api and then getting 12 hour weather forecast and then emailing the registered user about the weather.

- [x] Hacktoberfest2021 Participant
- [x] Contributor

Closes: #936

### Describe the changes you've made

I did all the tasks from scratch. Created the rain_alert_notification.py file for script. Created README.md file for explaining the project. Added relevant screenshots and added requirement.txt file.

## Type of change

What sort of change have you made:
<!--
Example how to mark a checkbox:-
- [x] My code follows the code style of this project.
-->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Code style update (formatting, local variables)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

## How Has This Been Tested?

I ran the script in the command prompt and received the weather updates on my email ID.

## Checklist:
<!--
Example how to mark a checkbox:-
- [x] My code follows the code style of this project.
-->
- [x] My code follows the guidelines of this project.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly whereever it was hard to understand.
- [x] I have made corresponding changes to the documentation.
- [x] My changes generate no new warnings.
- [x] I have added tests that prove my fix is effective or that my feature works.
- [x] Any dependent changes have been merged and published in downstream modules.

## Screenshots
![rain_alert_notificaiton](https://user-images.githubusercontent.com/88720381/139571873-33958794-206a-4777-9be3-de9cbf8b6df2.png)
44 changes: 44 additions & 0 deletions AutomationScripts/Rain Alert Notification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Rain Alert Notification

## Aim

To take city name, sender's email ID, sender's password, receiver's email ID, API key as input and then emailing the registered user about the 12 hour weather forecast of that city.

## Purpose

We can easily put the code into cloud servers and then it will email us about the 12 hour weather forecast making our lives easy so that we have an idea if it's goind to rain or not.

## Short description of package/script

- The script uses openweathermap.org/api to get weather information and emails the user about the weather forecast of input city.
- Also for accessing full link I have used city_list.json data which contains the latitude and longitude of the input city.
- Libraries : json, requests, smtplib

## Workflow of the Project

- Initally I am taking input city from user. After that I am changing that input city to correct format i.e. first letter of each word has to be capital.
- Then I am taking city data and then looping through that data and then checking if the city is present in the data.
- If the city name is present then I am taking storing its latitude and longitude values.
- Then I am getting data from link : https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude={part}&appid={API key}.
- Here "lat" is latitude and "lon" is longitude which depends on city. Also the link requires an API key.
- Now I have access to the data, so then I am finding weather forecast which is present after "main".
- After that I am sending a message to the registered email ID about 12 hour weather forecast.

## Setup instructions

- First of all, download the city_list.json file and keep it in the same location as python code file.
- For sender, create an account on website : https://openweathermap.org/ and then you'll have deafult API key.
- Sender also has to input the email ID as well as password.
- receiver just need to input email ID.

## Detailed explanation of script, if needed

Explained above.

## Compilation Steps

After arranging all the things as mentioned in "setup instructions". Just run the code in the IDLE or command prompt and then input all the things mentioned in "setup instructions".

## Author(s)

Varun Kumar
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import json
import requests
import smtplib

input_city = str(input("enter city name : "))
sender_email = str(input("enter sender's email ID : "))
sender_pwd = str(input("enter sender's email password : "))
receiver_email = str(input("enter receiver's email ID : "))
API_key = str(input("enter the API key : "))

input_city = input_city.lower()
input_city_list = list(input_city)
input_city_list[0] = input_city_list[0].upper()
for i in range(1, len(input_city_list)):
if(input_city_list[i-1]==' '):
input_city_list[i] = input_city_list[i].upper()

input_city = ''.join(input_city_list)

json1_file = open('city_list.json', encoding="utf8")
json1_str = json1_file.read()
json1_data = json.loads(json1_str)

coord_city_list = []
count_cities = 0
message = ""
for i in range(len(json1_data)):
if(json1_data[i]['name']==input_city):
count_cities = count_cities + 1
coord_dict = json1_data[i]['coord']
coord_list = []
coord_list.append(coord_dict['lon'])
coord_list.append(coord_dict['lat'])
coord_city_list.append(coord_list)
lat = coord_list[1]
lon = coord_list[0]
url = "https://api.openweathermap.org/data/2.5/onecall?lat=" + str(lat) + "&lon=" + str(lon) + "&exclude=current,minutely,daily,alerts&appid=" + API_key
req = requests.get(url)
req_text = req.text
c = 0
start_idx = 0
while(c!=12):
find_idx = req_text.find("main", start_idx)
start_idx = find_idx+1
c = c+1
find_idx = req_text.find("main", start_idx)
find_idx = find_idx+7
weather_condition = ""
while(req_text[find_idx]!=","):
weather_condition = weather_condition + req_text[find_idx]
find_idx = find_idx + 1
weather_condition = weather_condition[0:len(weather_condition)-1]
message = message + "the 12 hour weather forecast of city " + input_city + " with country initials " + json1_data[i]['country'] + " is : " + weather_condition.upper() + "." + "\n"

if(count_cities==0):
message = "unfortunately we did not find your entered city name in our database. Please check for any spelling errors."

elif(count_cities==1):
message = "we found " + str(count_cities) + " city with name " + input_city + "." + "\n" + message

elif(count_cities>1):
message = "we found " + str(count_cities) + " cities with name " + input_city + "." + "\n" + message

server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
server.login(sender_email, sender_pwd)
server.sendmail(sender_email, receiver_email, message)
server.quit()

Binary file not shown.
4 changes: 4 additions & 0 deletions AutomationScripts/Rain Alert Notification/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Libraries used :
1) requests
2) json
3) smtplib