Skip to content

Commit 0b50533

Browse files
Merge pull request #1070 from vkb20/second
Rain Alert Notification
2 parents d660980 + d93f393 commit 0b50533

File tree

10 files changed

+119
-92
lines changed

10 files changed

+119
-92
lines changed

WebScrapingScripts/crypto_price_checker/.github/pull_request_template.md renamed to AutomationScripts/Rain Alert Notification/.github/pull_request_template.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
## Related Issue
22

3-
- Using python script to fetch the top 100 cryptocurrencies from https://www.cointracker.io/ and then displaying cryptocurrency name and price.
3+
- 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.
44

55
- [x] Hacktoberfest2021 Participant
66
- [x] Contributor
77

8-
Closes: #957
8+
Closes: #936
99

1010
### Describe the changes you've made
1111

12-
I did all the tasks from scratch. Created the crypto_price_checker.py file for script. Created README.md file for explaining the project. Added relevant screenshots and added requirement.txt file.
12+
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.
1313

1414
## Type of change
1515

@@ -26,7 +26,7 @@ Example how to mark a checkbox:-
2626

2727
## How Has This Been Tested?
2828

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

3131
## Checklist:
3232
<!--
@@ -42,6 +42,4 @@ Example how to mark a checkbox:-
4242
- [x] Any dependent changes have been merged and published in downstream modules.
4343

4444
## Screenshots
45-
![crypto_output_1](https://user-images.githubusercontent.com/88720381/139568849-d6de7888-4c5b-4b54-b708-6f4ae52b71cf.png)
46-
47-
![crypto_output_2](https://user-images.githubusercontent.com/88720381/139568851-ed73bd55-fce9-43eb-9c52-d72806347d58.png)
45+
![rain_alert_notificaiton](https://user-images.githubusercontent.com/88720381/139571873-33958794-206a-4777-9be3-de9cbf8b6df2.png)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Rain Alert Notification
2+
3+
## Aim
4+
5+
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.
6+
7+
## Purpose
8+
9+
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.
10+
11+
## Short description of package/script
12+
13+
- The script uses openweathermap.org/api to get weather information and emails the user about the weather forecast of input city.
14+
- Also for accessing full link I have used city_list.json data which contains the latitude and longitude of the input city.
15+
- Libraries : json, requests, smtplib
16+
17+
## Workflow of the Project
18+
19+
- 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.
20+
- Then I am taking city data and then looping through that data and then checking if the city is present in the data.
21+
- If the city name is present then I am taking storing its latitude and longitude values.
22+
- Then I am getting data from link : https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude={part}&appid={API key}.
23+
- Here "lat" is latitude and "lon" is longitude which depends on city. Also the link requires an API key.
24+
- Now I have access to the data, so then I am finding weather forecast which is present after "main".
25+
- After that I am sending a message to the registered email ID about 12 hour weather forecast.
26+
27+
## Setup instructions
28+
29+
- First of all, download the city_list.json file and keep it in the same location as python code file.
30+
- For sender, create an account on website : https://openweathermap.org/ and then you'll have deafult API key.
31+
- Sender also has to input the email ID as well as password.
32+
- receiver just need to input email ID.
33+
34+
## Detailed explanation of script, if needed
35+
36+
Explained above.
37+
38+
## Compilation Steps
39+
40+
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".
41+
42+
## Author(s)
43+
44+
Varun Kumar
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import json
2+
import requests
3+
import smtplib
4+
5+
input_city = str(input("enter city name : "))
6+
sender_email = str(input("enter sender's email ID : "))
7+
sender_pwd = str(input("enter sender's email password : "))
8+
receiver_email = str(input("enter receiver's email ID : "))
9+
API_key = str(input("enter the API key : "))
10+
11+
input_city = input_city.lower()
12+
input_city_list = list(input_city)
13+
input_city_list[0] = input_city_list[0].upper()
14+
for i in range(1, len(input_city_list)):
15+
if(input_city_list[i-1]==' '):
16+
input_city_list[i] = input_city_list[i].upper()
17+
18+
input_city = ''.join(input_city_list)
19+
20+
json1_file = open('city_list.json', encoding="utf8")
21+
json1_str = json1_file.read()
22+
json1_data = json.loads(json1_str)
23+
24+
coord_city_list = []
25+
count_cities = 0
26+
message = ""
27+
for i in range(len(json1_data)):
28+
if(json1_data[i]['name']==input_city):
29+
count_cities = count_cities + 1
30+
coord_dict = json1_data[i]['coord']
31+
coord_list = []
32+
coord_list.append(coord_dict['lon'])
33+
coord_list.append(coord_dict['lat'])
34+
coord_city_list.append(coord_list)
35+
lat = coord_list[1]
36+
lon = coord_list[0]
37+
url = "https://api.openweathermap.org/data/2.5/onecall?lat=" + str(lat) + "&lon=" + str(lon) + "&exclude=current,minutely,daily,alerts&appid=" + API_key
38+
req = requests.get(url)
39+
req_text = req.text
40+
c = 0
41+
start_idx = 0
42+
while(c!=12):
43+
find_idx = req_text.find("main", start_idx)
44+
start_idx = find_idx+1
45+
c = c+1
46+
find_idx = req_text.find("main", start_idx)
47+
find_idx = find_idx+7
48+
weather_condition = ""
49+
while(req_text[find_idx]!=","):
50+
weather_condition = weather_condition + req_text[find_idx]
51+
find_idx = find_idx + 1
52+
weather_condition = weather_condition[0:len(weather_condition)-1]
53+
message = message + "the 12 hour weather forecast of city " + input_city + " with country initials " + json1_data[i]['country'] + " is : " + weather_condition.upper() + "." + "\n"
54+
55+
if(count_cities==0):
56+
message = "unfortunately we did not find your entered city name in our database. Please check for any spelling errors."
57+
58+
elif(count_cities==1):
59+
message = "we found " + str(count_cities) + " city with name " + input_city + "." + "\n" + message
60+
61+
elif(count_cities>1):
62+
message = "we found " + str(count_cities) + " cities with name " + input_city + "." + "\n" + message
63+
64+
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
65+
server.login(sender_email, sender_pwd)
66+
server.sendmail(sender_email, receiver_email, message)
67+
server.quit()
68+
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Libraries used :
22
1) requests
3-
2) Beautiful Soup
3+
2) json
4+
3) smtplib

WebScrapingScripts/crypto_price_checker/README.md

-48
This file was deleted.

WebScrapingScripts/crypto_price_checker/crypto_price_checker.py

-36
This file was deleted.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)