<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://samridhadhital.com.np</link><generator>RSS for Node</generator><lastBuildDate>Wed, 13 May 2026 18:56:16 GMT</lastBuildDate><atom:link href="https://samridhadhital.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Build a Weather Notifier App Using Python and a Public API]]></title><description><![CDATA[Whether you're a developer trying to stay dry or just looking for a fun Python project, a Weather Notifier App is a great choice. In this blog, we’ll build a simple weather notification tool using Python and the OpenWeatherMap API. You’ll learn about...]]></description><link>https://samridhadhital.com.np/how-to-build-a-weather-notifier-app-using-python-and-a-public-api</link><guid isPermaLink="true">https://samridhadhital.com.np/how-to-build-a-weather-notifier-app-using-python-and-a-public-api</guid><category><![CDATA[Python]]></category><category><![CDATA[python projects]]></category><dc:creator><![CDATA[Samridha Dhital]]></dc:creator><pubDate>Tue, 01 Jul 2025 18:15:00 GMT</pubDate><content:encoded><![CDATA[<p>Whether you're a developer trying to stay dry or just looking for a fun Python project, a Weather Notifier App is a great choice. In this blog, we’ll build a simple weather notification tool using Python and the OpenWeatherMap API. You’ll learn about API integration, notifications, and simple scheduling — all in under 100 lines of code.</p>
<p><strong>What You’ll Need:</strong></p>
<ul>
<li><p>Python 3 installed</p>
</li>
<li><p><code>requests</code> library (for API calls)</p>
</li>
<li><p><code>plyer</code> library (for desktop notifications)</p>
</li>
<li><p>A free API key from <a target="_blank" href="https://openweathermap.org/api">OpenWeatherMap</a></p>
</li>
</ul>
<p><strong>Step 1: Get an API Key from OpenWeatherMap</strong></p>
<ol>
<li><p>Visit <a target="_blank" href="https://openweathermap.org/api">https://openweathermap.org/api.</a></p>
</li>
<li><p>Sign up and log in.</p>
</li>
<li><p>Go to the "API keys" section in your account and generate a new key.</p>
</li>
<li><p>Use the “Current Weather Data” API.</p>
</li>
</ol>
<p><strong>Step 2: Install Required Libraries</strong></p>
<p>Open your terminal and install the necessary Python libraries:<br /><code>pip install requests plyer</code></p>
<p><strong>Step 3: Fetch Weather Data Using Python</strong></p>
<p>Create a new file called <code>weather_</code><a target="_blank" href="http://notifier.py"><code>notifier.py</code></a> and start by writing a function to fetch weather data:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> requests

API_KEY = <span class="hljs-string">'your_api_key_here'</span>

CITY = <span class="hljs-string">'London'</span>

BASE_URL = <span class="hljs-string">"http://api.openweathermap.org/data/2.5/weather?"</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_weather</span>(<span class="hljs-params">city</span>):</span>
url = <span class="hljs-string">f"<span class="hljs-subst">{BASE_URL}</span>appid=<span class="hljs-subst">{API_KEY}</span>&amp;q=<span class="hljs-subst">{city}</span>&amp;units=metric"</span>
response = requests.get(url)
data = response.json()

<span class="hljs-keyword">if</span> data[<span class="hljs-string">"cod"</span>] != <span class="hljs-number">200</span>:
<span class="hljs-keyword">return</span> <span class="hljs-string">f"Error: <span class="hljs-subst">{data[<span class="hljs-string">'message'</span>]}</span>"</span>

main = data[<span class="hljs-string">"main"</span>]
weather_desc = data[<span class="hljs-string">"weather"</span>][<span class="hljs-number">0</span>][<span class="hljs-string">"description"</span>]
temp = main[<span class="hljs-string">"temp"</span>]

<span class="hljs-keyword">return</span> <span class="hljs-string">f"Weather in <span class="hljs-subst">{city}</span>:\n<span class="hljs-subst">{weather_desc.capitalize()}</span>, <span class="hljs-subst">{temp}</span>°C"</span>
</code></pre>
<p><strong>Step 4: Show the Notification</strong></p>
<p>Now let’s display the weather using a desktop notification with the <code>plyer</code> library:  </p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> plyer <span class="hljs-keyword">import</span> notification

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">notify_user</span>(<span class="hljs-params">message</span>):</span>
notification.notify(
title=<span class="hljs-string">"Weather Update"</span>,
message=message,
timeout=<span class="hljs-number">10</span> <span class="hljs-comment"># seconds )</span>
</code></pre>
<p><strong>Step 5: Combine Everything</strong></p>
<p>Put everything together in your <code>main</code> block:  </p>
<pre><code class="lang-python"><span class="hljs-keyword">if</span> name == <span class="hljs-string">"main"</span>:
weather_report = get_weather(CITY)
notify_user(weather_report)
</code></pre>
<p>Now run the script:<br /><code>python weather_</code><a target="_blank" href="http://notifier.py"><code>notifier.py</code></a><br />You’ll see a system notification pop up with the current weather.</p>
<p><strong>Optional: Add Automatic Scheduling</strong></p>
<p>If you want the app to check the weather every few hours, install the <code>schedule</code> library:<br /><code>pip install schedule</code><br />Then add this to your script:  </p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> schedule
<span class="hljs-keyword">import</span> time

schedule.every(<span class="hljs-number">3</span>).hours.do(<span class="hljs-keyword">lambda</span>: notify_user(get_weather(CITY)))

<span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>: schedule.run_pending()
time.sleep(<span class="hljs-number">1</span>)
</code></pre>
<p><strong>Bonus Ideas:</strong></p>
<ul>
<li><p>Add a GUI using Tkinter or PyQt</p>
</li>
<li><p>Fetch weather for multiple cities</p>
</li>
<li><p>Use geolocation to get weather automatically</p>
</li>
<li><p>Send weather via email or SMS using Twilio or SMTP</p>
</li>
</ul>
<p><strong>Conclusion:</strong></p>
<p>You’ve just built a simple, useful Weather Notifier App in Python using real-time data from OpenWeatherMap. This project is a great introduction to working with APIs and automation in Python. It's easily extendable and can be personalized in countless ways.</p>
<p>Now you’ll never be caught without an umbrella again!</p>
]]></content:encoded></item></channel></rss>