Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ---- Python ----
__pycache__/
*.pyc
*.pyo
*.pyd
*.pdb
*.log

# ---- Virtual Environment ----
venv/
.venv/
ENV/
env/

# ---- VSCode ----
.vscode/

# ---- macOS / Linux ----
.DS_Store
Thumbs.db

# ---- Project-specific ----
data/*.log
data/*_cache.json
data/*.csv

# Don't ignore config.ini (important)
!config/config.ini

# ---- Build / Packaging ----
build/
dist/
*.egg-info/

# ---- Jupyter ----
.ipynb_checkpoints/
Binary file modified __pycache__/alerts.cpython-314.pyc
Binary file not shown.
Binary file modified __pycache__/cache.cpython-314.pyc
Binary file not shown.
Binary file modified __pycache__/cli.cpython-314.pyc
Binary file not shown.
Binary file modified __pycache__/config.cpython-314.pyc
Binary file not shown.
Binary file modified __pycache__/fetcher.cpython-314.pyc
Binary file not shown.
Binary file modified __pycache__/logging_system.cpython-314.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import platform
from colorama import Fore, Style, init


init(autoreset=True)

def check_alert(weather: dict, alert_temp: float):
Expand Down Expand Up @@ -37,3 +38,11 @@ def play_alert_sound():

except Exception as e:
logging.error(f"Failed to play sound alert: {e}")

def detect_trend(prev_temp, new_temp):
if new_temp > prev_temp:
return "rising"
elif new_temp < prev_temp:
return "dropping"
else:
return "stable"
156 changes: 107 additions & 49 deletions cli.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,122 @@
# cli.py
import argparse
# # cli.py
# import argparse

def get_args():
parser = argparse.ArgumentParser(description="Weather Harvester CLI")
# def get_args():
# parser = argparse.ArgumentParser(description="Weather Harvester CLI")

# Multiple cities: -c Delhi -c Pune
parser.add_argument(
"-c", "--city",
action="append",
help="City name (can be given multiple times: -c Delhi -c Pune)"
)
# # Multiple cities: -c Delhi -c Pune
# parser.add_argument(
# "-c", "--city",
# action="append",
# help="City name (can be given multiple times: -c Delhi -c Pune)"
# )

# Alternative: comma-separated cities
parser.add_argument(
"-C", "--cities",
type=str,
help="Comma-separated list of cities: --cities Delhi,Mumbai"
)
# # Alternative: comma-separated cities
# parser.add_argument(
# "-C", "--cities",
# type=str,
# help="Comma-separated list of cities: --cities Delhi,Mumbai"
# )

# Coordinate override (used as fallback if city not in known list)
parser.add_argument(
"--lat",
type=float,
help="Latitude value (used if city has no predefined coordinates)"
)
# # Coordinate override (used as fallback if city not in known list)
# parser.add_argument(
# "--lat",
# type=float,
# help="Latitude value (used if city has no predefined coordinates)"
# )

parser.add_argument(
"--lon",
type=float,
help="Longitude value (used if city has no predefined coordinates)"
)
# parser.add_argument(
# "--lon",
# type=float,
# help="Longitude value (used if city has no predefined coordinates)"
# )

# Cache toggle
parser.add_argument(
"--use-cache",
action="store_true",
help="Use cached data if available"
)
# # Cache toggle
# parser.add_argument(
# "--use-cache",
# action="store_true",
# help="Use cached data if available"
# )

# Logging level
parser.add_argument(
"--log-level",
type=str,
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
help="Logging level"
)
# # Logging level
# parser.add_argument(
# "--log-level",
# type=str,
# choices=["DEBUG", "INFO", "WARNING", "ERROR"],
# help="Logging level"
# )

# # Alert threshold
# parser.add_argument(
# "--alert-temp",
# type=float,
# help="Temperature threshold to trigger alert (°C)"
# )

# Alert threshold
# # Config path
# parser.add_argument(
# "--config",
# type=str,
# default="config/config.ini",
# help="Path to configuration file"
# )

# return parser.parse_args()


# import argparse

# def get_args(arg_list=None):
# parser = argparse.ArgumentParser(description="Weather Harvester CLI")

# parser.add_argument("-c", "--city", dest="cities", action="append",
# help="City name", default=[])

# parser.add_argument("--alert-temp", type=float, default=None,
# help="Temperature threshold for alerts")

# parser.add_argument("--log-level", type=str, default="INFO",
# help="Logging level")

# parser.add_argument("--config", type=str, default="config/config.ini",
# help="Path to config file")

# parser.add_argument("--lat", type=float, default=None)
# parser.add_argument("--lon", type=float, default=None)
# parser.add_argument("--use-cache", action="store_true")

# if arg_list is not None:
# return parser.parse_args(arg_list)

# return parser.parse_args()
import argparse

def get_args(arg_list=None):
parser = argparse.ArgumentParser(description="Weather Harvester CLI")

# POSitional argument (optional)
parser.add_argument(
"--alert-temp",
type=float,
help="Temperature threshold to trigger alert (°C)"
"positional_city",
nargs="*",
help="City name(s) (optional if using -c)"
)

# Config path
# Optional flag -c
parser.add_argument(
"--config",
type=str,
default="config/config.ini",
help="Path to configuration file"
"-c", "--city", dest="cities", action="append",
help="City name"
)

parser.add_argument("--alert-temp", type=float, default=None)
parser.add_argument("--log-level", type=str, default="INFO")
parser.add_argument("--config", type=str, default="config/config.ini")
parser.add_argument("--lat", type=float, default=None)
parser.add_argument("--lon", type=float, default=None)
parser.add_argument("--use-cache", action="store_true")

# For tests
if arg_list is not None:
return parser.parse_args(arg_list)

return parser.parse_args()

110 changes: 110 additions & 0 deletions data/app.log
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,113 @@
2025-11-26 18:52:07,771 [INFO] No alert. Temperature 24.7�C is below threshold 35.0�C
2025-11-26 18:52:08,443 [INFO] No alert. Temperature 18.2�C is below threshold 35.0�C
2025-11-26 18:52:08,452 [INFO] All cities processed.
2025-11-28 00:31:56,419 [INFO] Logging initialized with level: INFO
2025-11-28 00:31:56,420 [INFO] Cities to process: ['Delhi']
2025-11-28 00:31:56,420 [INFO] Caching enabled: True
2025-11-28 00:31:56,421 [INFO] Alert temperature threshold: 35.0�C
2025-11-28 00:31:56,422 [INFO] Processing city: Delhi
2025-11-28 00:31:56,422 [INFO] Coordinates for Delhi: 28.6, 77.2
2025-11-28 00:31:56,433 [INFO] Fetching new weather data for Delhi
2025-11-28 00:32:20,488 [ERROR] Network error: <urlopen error timed out>
2025-11-28 00:32:20,488 [ERROR] Failed to fetch weather for Delhi
2025-11-28 00:33:00,910 [INFO] Logging initialized with level: INFO
2025-11-28 00:33:00,911 [INFO] Cities to process: ['Delhi']
2025-11-28 00:33:00,911 [INFO] Caching enabled: True
2025-11-28 00:33:00,912 [INFO] Alert temperature threshold: 35.0�C
2025-11-28 00:33:00,924 [INFO] Processing city: Delhi
2025-11-28 00:33:00,925 [INFO] Coordinates for Delhi: 28.6, 77.2
2025-11-28 00:33:00,926 [INFO] Fetching new weather data for Delhi
2025-11-28 00:33:20,993 [ERROR] Network error: <urlopen error timed out>
2025-11-28 00:33:20,994 [ERROR] Failed to fetch weather for Delhi
2025-11-28 00:33:20,995 [INFO] All cities processed.
2025-11-28 00:34:02,062 [INFO] Logging initialized with level: INFO
2025-11-28 00:34:02,063 [INFO] Cities to process: ['Pune', 'Ranchi']
2025-11-28 00:34:02,063 [INFO] Caching enabled: True
2025-11-28 00:34:02,064 [INFO] Alert temperature threshold: 35.0�C
2025-11-28 00:34:02,066 [INFO] Processing city: Pune
2025-11-28 00:34:02,066 [INFO] Coordinates for Pune: 18.52, 73.86
2025-11-28 00:34:02,067 [INFO] Processing city: Ranchi
2025-11-28 00:34:02,067 [WARNING] No predefined coordinates for city 'Ranchi', using default lat/lon
2025-11-28 00:34:02,067 [INFO] Coordinates for Ranchi: 28.6, 77.2
2025-11-28 00:34:02,068 [INFO] Fetching new weather data for Ranchi
2025-11-28 00:34:02,095 [INFO] Fetching new weather data for Pune
2025-11-28 00:34:22,110 [ERROR] Network error: <urlopen error timed out>
2025-11-28 00:34:22,111 [ERROR] Network error: <urlopen error timed out>
2025-11-28 00:34:22,111 [ERROR] Failed to fetch weather for Ranchi
2025-11-28 00:34:22,112 [ERROR] Failed to fetch weather for Pune
2025-11-28 00:34:22,112 [INFO] All cities processed.
2025-11-28 00:37:45,143 [INFO] Logging initialized with level: INFO
2025-11-28 00:37:45,144 [INFO] Cities to process: ['Pune', 'Ranchi']
2025-11-28 00:37:45,144 [INFO] Caching enabled: True
2025-11-28 00:37:45,144 [INFO] Alert temperature threshold: 35.0�C
2025-11-28 00:37:45,147 [INFO] Processing city: Pune
2025-11-28 00:37:45,148 [INFO] Processing city: Ranchi
2025-11-28 00:37:45,148 [INFO] Coordinates for Pune: 18.52, 73.86
2025-11-28 00:37:45,148 [WARNING] No predefined coordinates for city 'Ranchi', using default lat/lon
2025-11-28 00:37:45,149 [INFO] Coordinates for Ranchi: 28.6, 77.2
2025-11-28 00:37:45,149 [INFO] Fetching new weather data for Ranchi
2025-11-28 00:37:45,150 [INFO] Fetching new weather data for Pune
2025-11-28 00:37:46,525 [INFO] No alert. Temperature 21.2�C is below threshold 35.0�C
2025-11-28 00:37:46,525 [INFO] No alert. Temperature 15.7�C is below threshold 35.0�C
2025-11-28 00:37:46,526 [INFO] All cities processed.
2025-11-28 00:39:50,029 [INFO] Logging initialized with level: INFO
2025-11-28 00:39:50,029 [INFO] Cities to process: ['Pune', 'Ranchi']
2025-11-28 00:39:50,029 [INFO] Caching enabled: True
2025-11-28 00:39:50,029 [INFO] Alert temperature threshold: 35.0�C
2025-11-28 00:39:50,031 [INFO] Processing city: Pune
2025-11-28 00:39:50,032 [INFO] Processing city: Ranchi
2025-11-28 00:39:50,032 [INFO] Coordinates for Pune: 18.52, 73.86
2025-11-28 00:39:50,032 [WARNING] No predefined coordinates for city 'Ranchi', using default lat/lon
2025-11-28 00:39:50,033 [INFO] Coordinates for Ranchi: 28.6, 77.2
2025-11-28 00:39:50,052 [INFO] No alert. Temperature 21.2�C is below threshold 35.0�C
2025-11-28 00:39:50,052 [INFO] No alert. Temperature 15.7�C is below threshold 35.0�C
2025-11-28 00:39:50,053 [INFO] All cities processed.
2025-12-03 23:15:11,599 [INFO] Logging initialized with level: INFO
2025-12-03 23:15:42,457 [INFO] Logging initialized with level: INFO
2025-12-03 23:16:03,772 [INFO] Logging initialized with level: INFO
2025-12-03 23:17:13,518 [INFO] Logging initialized with level: INFO
2025-12-03 23:17:32,998 [INFO] Logging initialized with level: INFO
2025-12-03 23:27:19,707 [INFO] Logging initialized with level: INFO
2025-12-03 23:27:19,708 [INFO] Cities to process: ['Mumbai']
2025-12-03 23:27:19,708 [INFO] Caching enabled: True
2025-12-03 23:27:19,717 [INFO] Alert temperature threshold: 35.0�C
2025-12-03 23:27:19,720 [INFO] Processing city: Mumbai
2025-12-03 23:27:19,720 [INFO] Coordinates for Mumbai: 19.07, 72.88
2025-12-03 23:27:19,720 [INFO] Fetching new weather data for Mumbai
2025-12-03 23:27:20,815 [INFO] No alert. Temperature 26.6�C is below threshold 35.0�C
2025-12-03 23:27:20,817 [INFO] All cities processed.
2025-12-03 23:27:59,961 [INFO] Logging initialized with level: INFO
2025-12-03 23:27:59,962 [INFO] Cities to process: ['Pune']
2025-12-03 23:27:59,962 [INFO] Caching enabled: True
2025-12-03 23:27:59,963 [INFO] Alert temperature threshold: 35.0�C
2025-12-03 23:27:59,964 [INFO] Processing city: Pune
2025-12-03 23:27:59,964 [INFO] Coordinates for Pune: 18.52, 73.86
2025-12-03 23:27:59,982 [INFO] Fetching new weather data for Pune
2025-12-03 23:28:00,935 [INFO] No alert. Temperature 17.8�C is below threshold 35.0�C
2025-12-03 23:28:00,936 [INFO] All cities processed.
2025-12-04 02:35:46,275 [INFO] Logging initialized with level: INFO
2025-12-04 02:35:46,276 [INFO] Cities to process: ['Delhi']
2025-12-04 02:35:46,276 [INFO] Caching enabled: True
2025-12-04 02:35:46,277 [INFO] Alert temperature threshold: 35.0�C
2025-12-04 02:35:46,280 [INFO] Processing city: Delhi
2025-12-04 02:35:46,280 [INFO] Coordinates for Delhi: 28.6, 77.2
2025-12-04 02:35:46,301 [INFO] Fetching new weather data for Delhi
2025-12-04 02:35:47,287 [INFO] No alert. Temperature 10.1�C is below threshold 35.0�C
2025-12-04 02:35:47,288 [INFO] All cities processed.
2025-12-04 02:47:33,463 [INFO] Logging initialized with level: INFO
2025-12-04 02:47:33,464 [INFO] Cities to process: ['Delhi']
2025-12-04 02:47:33,464 [INFO] Caching enabled: True
2025-12-04 02:47:33,465 [INFO] Alert temperature threshold: 35.0�C
2025-12-04 02:47:33,466 [INFO] Processing city: Delhi
2025-12-04 02:47:33,467 [INFO] Coordinates for Delhi: 28.6, 77.2
2025-12-04 02:47:33,483 [INFO] No alert. Temperature 10.1�C is below threshold 35.0�C
2025-12-04 02:47:33,484 [INFO] All cities processed.
2025-12-04 02:48:16,630 [INFO] Logging initialized with level: INFO
2025-12-04 02:48:16,631 [INFO] Cities to process: ['Delhi']
2025-12-04 02:48:16,632 [INFO] Caching enabled: True
2025-12-04 02:48:16,632 [INFO] Alert temperature threshold: 35.0�C
2025-12-04 02:48:16,634 [INFO] Processing city: Delhi
2025-12-04 02:48:16,634 [INFO] Coordinates for Delhi: 28.6, 77.2
2025-12-04 02:48:16,635 [INFO] No alert. Temperature 10.1�C is below threshold 35.0�C
2025-12-04 02:48:16,636 [INFO] All cities processed.
2025-12-04 02:48:28,343 [INFO] Logging initialized with level: INFO
14 changes: 7 additions & 7 deletions data/delhi_cache.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"timestamp": "2025-11-26T18:52:08.442330",
"timestamp": "2025-12-04T02:35:47.286649",
"payload": {
"time": "2025-11-26T13:15",
"time": "2025-12-03T21:00",
"interval": 900,
"temperature": 18.2,
"windspeed": 3.6,
"winddirection": 354,
"temperature": 10.1,
"windspeed": 4.1,
"winddirection": 285,
"is_day": 0,
"weathercode": 0
"weathercode": 1
},
"previous": 18.2
"previous": 10.1
}
12 changes: 6 additions & 6 deletions data/pune_cache.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"timestamp": "2025-11-26T18:52:07.770751",
"timestamp": "2025-12-03T23:28:00.933597",
"payload": {
"time": "2025-11-26T13:15",
"time": "2025-12-03T17:45",
"interval": 900,
"temperature": 24.7,
"windspeed": 4.1,
"winddirection": 105,
"temperature": 17.8,
"windspeed": 3.3,
"winddirection": 84,
"is_day": 0,
"weathercode": 0
},
"previous": 24.7
"previous": 17.8
}
Loading