The Basic Project (Mini Project) is the culmination of everything you've learned in the Python course. The goal of a mini-project is to transition from writing isolated snippets of code to building a cohesive, functional application that solves a specific problem.
Building a project follows a structured process often called the Software Development Life Cycle (SDLC). Even for a mini-project, following these steps ensures clean, bug-free code.
Requirements Gathering: Define what the app does. (e.g., "It should fetch weather data and save it to a file.")
Logic Planning: Decide which tools to use. Will you need requests for APIs? json for data? try-except for errors?
Modular Coding: Write small, reusable functions rather than one giant block of code.
Error Handling: Anticipate where the user might provide bad input or where the internet might fail.
Documentation: Comment your code so others (and your future self) understand the logic.
This project combines APIs, File Handling, Dictionaries, and Exception Handling. It fetches real-time weather and saves a search history log.
import requests import json from datetime import datetime def get_weather(city): """Fetches real-time weather data from a public API.""" # Using a sample Open-Meteo API (No key required for this demo) # Note: In a real project, you'd use the 'requests' logic learned in the API lesson. base_url = "https://api.open-meteo.com/v1/forecast" params = { "latitude": 30.3165, # Dehradun coordinates "longitude": 78.0322, "current_weather": True } try: response = requests.get(base_url, params=params) response.raise_for_status() # Check for HTTP errors data = response.json() return data['current_weather'] except Exception as e: print(f"Error fetching data: {e}") return None def save_to_log(city, weather_data): """Saves the search result into a text file.""" timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") log_entry = f"[{timestamp}] City: {city} | Temp: {weather_data['temperature']}°C | Wind: {weather_data['windspeed']} km/h\n" with open("weather_history.txt", "a") as file: file.write(log_entry) def main(): print("--- Welcome to the EMBLAb Weather Logger ---") city = input("Enter the city name to log: ") print(f"Fetching data for {city}...") weather = get_weather(city) if weather: print(f"\nSuccess! Current Temp: {weather['temperature']}°C") save_to_log(city, weather) print("Data saved to weather_history.txt") else: print("Could not retrieve weather data.") if __name__ == "__main__": main()
| Concept Used | Purpose in Project |
| Modules (requests, datetime) | Importing external functionality to handle web requests and time. |
| Functions | Breaking the app into get_weather, save_to_log, and main. |
| Exception Handling | Using try-except to catch network failures without crashing. |
| File Handling | Using open(..., "a") to append search history to a text file. |
| String Formatting | Using f-strings to create clean log entries and print statements. |
Once you finish this mini-project, you can make it "Advanced" by adding:
Classes & Objects: Create a WeatherReport class to manage the data.
Virtual Environment: Ensure requests is installed in a local venv.
NumPy/Pandas: Use Pandas to analyze the weather_history.txt and find the average temperature.
Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION