Weather Dashboard with Azure Storage 🌦️

Day 1 of 30-Day DevOps Challenge

Β·

3 min read

Introduction

Welcome to Day 1 of the 30-Day DevOps Challenge! πŸš€ Over the next month, I'll be working on real-world projects to enhance my skills in DevOps, automation, cloud computing, and CI/CD practices.

To kick off this journey, I created a Weather Dashboard that integrates real-time weather data from the OpenWeather API with Azure Blob Storage. This project highlights key concepts in API integration, cloud storage management, and Python programming for automation. Let’s dive into the details!


Project Overview

The Azure Weather Dashboard is a Python-based application designed to:

  • Fetch real-time weather data for multiple cities.

  • Store this data in structured JSON format within Azure Blob Storage.

  • Dynamically create Azure Blob Storage containers to organize and manage the data.

This project demonstrates the seamless integration of third-party APIs with cloud services, a crucial skill for modern DevOps workflows.


Prerequisites

1. Environment Setup

Ensure you have the following tools installed:

  • Python 3.8 or later

  • Azure account (for storage setup)

  • OpenWeather API key

2. Required Python Libraries

Install these dependencies using pip install -r requirements.txt:

  • azure-storage-blob

  • requests

  • python-dotenv

3. Environment Variables

Create a .env file in your project directory with the following variables:

# OpenWeather API Key
OPENWEATHER_API_KEY=your_openweather_api_key

# Azure Storage Account Credentials
AZURE_STORAGE_ACCOUNT_NAME=your_storage_account_name
AZURE_STORAGE_ACCOUNT_KEY=your_storage_account_key

How It Works

1. Fetch Weather Data

Using the OpenWeather API, the program retrieves weather details like temperature, humidity, and conditions for specified cities.

def fetch_weather(self, city):
    base_url = "https://api.openweathermap.org/data/2.5/weather"
    params = {"q": city, "appid": self.api_key, "units": "metric"}
    response = requests.get(base_url, params=params)
    return response.json()

2. Create Azure Blob Storage Container

The program dynamically creates a unique container for each execution to store the data.

self.container_name = f"openweather{random.randint(1000, 9999)}"
blob_service_client.create_container(self.container_name)

3. Save Data in Azure

Weather data is uploaded to the container in JSON format. The data is organized into folders by city and timestamp.

timestamp = datetime.now().strftime('%Y%m%d-%H%M%S')
blob_name = f"weather-data/{city}-{timestamp}.json"
blob_client.upload_blob(json.dumps(data), overwrite=True)

Azure Configuration Steps

Follow these simple steps to configure Azure Storage:

  1. Create a Storage Account

    • Log in to the Azure Portal.

    • Navigate to Storage Accounts and click Create.

    • Choose a resource group and provide a unique name for your storage account.

  2. Obtain Access Keys

    • Once the storage account is created, go to Access Keys under the account settings.

    • Copy the Account Name and Key1 for your .env file.

  3. Set Up Blob Storage

    • Go to the Containers section in your storage account.

    • Use the program to dynamically create and manage containers.


Usage Guide

Clone the Repository

git clone https://github.com/peymosiec01/Day-1---Weather-Dashboard-with-Azure-Storage.git
cd Day-1---Weather-Dashboard-with-Azure-Storage

Install Dependencies

pip install -r requirements.txt

Run the Script

Add your .env file and execute the program:

python weather_dashboard.py

Sample Output

When the script runs, you’ll see something like this in the logs:

Processing weather data for London
Container 'openweather8465' created successfully!
Data uploaded to blob 'weather-data/London-20250106-123456.json' in container 'openweather8465'.

Processing weather data for York
Data uploaded to blob 'weather-data/York-20250106-123459.json' in container 'openweather8465'.

Azure Blob Storage will contain JSON files like:

Container: openweather8465
  └── weather-data/
       β”œβ”€β”€ London-20250106-123456.json
       β”œβ”€β”€ York-20250106-123459.json
       └── Liverpool-20250106-123502.json


Key Takeaways

  1. Automation Matters: Automating tasks like data retrieval and storage reduces manual effort and ensures consistency.

  2. DevOps Skills in Action: This project reinforces the importance of integrating APIs with cloud services for scalable solutions.

  3. Learn by Doing: Practical challenges are the best way to master DevOps tools and techniques.


GitHub Repository

The full code is available on GitHub. Feel free to fork, experiment, and contribute!


What’s Next?

This is just the beginning of my 30 Days DevOps Challenge. Follow me as I explore CI/CD pipelines, containerization with Docker, Kubernetes, and more exciting DevOps tools and practices.

Let’s connect and grow together! πŸ’»πŸ’‘

#30DaysDevOpsChallenge #DevOpsAllStarsChallenge #Azure #Automation #CloudComputing

Β