From 7bb344d9cb7d5719c19bc7e74ceb61460fd505b3 Mon Sep 17 00:00:00 2001 From: Arjun Kumar Date: Sun, 2 Nov 2025 14:30:11 +0530 Subject: [PATCH 1/3] Add simple weather CLI using Open-Meteo API for @hacktoberfest program2025 This script fetches and displays the current weather for a specified city using Open-Meteo and OpenStreetMap APIs. --- weather_cli.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 weather_cli.py diff --git a/weather_cli.py b/weather_cli.py new file mode 100644 index 0000000..6949e99 --- /dev/null +++ b/weather_cli.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +""" +weather_cli.py +Simple Weather CLI using Open-Meteo and OpenStreetMap APIs. + +Usage: + python weather_cli.py "New Delhi" + python weather_cli.py "San Francisco" +""" + +import requests +import sys + +def get_coordinates(city): + """Get latitude and longitude for a city using Nominatim API.""" + url = "https://nominatim.openstreetmap.org/search" + params = {"q": city, "format": "json", "limit": 1} + resp = requests.get(url, params=params, headers={"User-Agent": "WeatherCLI/1.0"}) + resp.raise_for_status() + data = resp.json() + if not data: + raise ValueError(f"City '{city}' not found.") + return float(data[0]["lat"]), float(data[0]["lon"]) + +def get_weather(lat, lon): + """Fetch current weather from Open-Meteo API.""" + url = "https://api.open-meteo.com/v1/forecast" + params = { + "latitude": lat, + "longitude": lon, + "current_weather": True, + } + resp = requests.get(url, params=params) + resp.raise_for_status() + return resp.json()["current_weather"] + +def show_weather(city): + """Display weather info for a city.""" + try: + lat, lon = get_coordinates(city) + weather = get_weather(lat, lon) + print(f"🌍 Weather for {city}") + print(f"📍 Lat: {lat:.2f}, Lon: {lon:.2f}") + print(f"🌡️ Temperature: {weather['temperature']}°C") + print(f"💨 Windspeed: {weather['windspeed']} km/h") + print(f"🕒 Time: {weather['time']}") + except Exception as e: + print("Error:", e) + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python weather_cli.py ") + sys.exit(1) + city_name = " ".join(sys.argv[1:]) + show_weather(city_name) From 544d81a1035b094a0103c02aba5dd201e0939512 Mon Sep 17 00:00:00 2001 From: Arjun Kumar Date: Sun, 2 Nov 2025 15:02:50 +0530 Subject: [PATCH 2/3] Add Simple interactive audio recorder script # Audio Recorder (crypto.py) Simple interactive audio recorder script that uses sounddevice and wavio to record microphone input and save as a WAV file. ## Features - List available audio input devices - Record audio for a user-specified duration - Configure device index, sample rate, channels and output filename - Saves recording as a .wav file --- .../Simple _interactive_audio_recorder.py | 58 +++++++++++++++++++ VOICE_RECORDER/voice_recorder.py | 14 ----- 2 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 VOICE_RECORDER/Simple _interactive_audio_recorder.py delete mode 100644 VOICE_RECORDER/voice_recorder.py diff --git a/VOICE_RECORDER/Simple _interactive_audio_recorder.py b/VOICE_RECORDER/Simple _interactive_audio_recorder.py new file mode 100644 index 0000000..caa61bc --- /dev/null +++ b/VOICE_RECORDER/Simple _interactive_audio_recorder.py @@ -0,0 +1,58 @@ +import sounddevice as sd +import wavio +import os +import time + +def list_input_devices(): + try: + devices = sd.query_devices() + print("Available audio devices:") + for i, dev in enumerate(devices): + print(f"{i}: {dev['name']} (max input channels: {dev.get('max_input_channels', 0)})") + except Exception as e: + print("Could not query devices:", e) + +def record_audio(duration, filename, samplerate=44100, channels=2, dtype='int16', device=None): + if not filename.lower().endswith('.wav'): + filename += '.wav' + try: + frames = int(duration * samplerate) + print(f"Recording for {duration} seconds (samplerate={samplerate}, channels={channels})...") + start = time.time() + audio = sd.rec(frames, samplerate=samplerate, channels=channels, dtype=dtype, device=device) + sd.wait() + elapsed = time.time() - start + # Ensure output directory exists + out_dir = os.path.dirname(os.path.abspath(filename)) + if out_dir and not os.path.exists(out_dir): + os.makedirs(out_dir, exist_ok=True) + wavio.write(filename, audio, samplerate, sampwidth=2) + print(f"Recording saved as '{filename}' ({elapsed:.2f}s)") + except KeyboardInterrupt: + print("\nRecording cancelled by user.") + except Exception as e: + print("Recording failed:", e) + +if __name__ == "__main__": + try: + print("Press Enter to see available input devices or type 'skip' to continue with default device.") + if input().strip().lower() != 'skip': + list_input_devices() + + device_input = input("Enter device index to use (or press Enter for default): ").strip() + device = int(device_input) if device_input != '' else None + + record_duration = float(input("Enter duration in seconds: ").strip()) + file_name = input("Enter filename (with or without .wav extension) [default: recording.wav]: ").strip() or "recording.wav" + + sr_input = input("Enter sample rate (default 44100): ").strip() + samplerate = int(sr_input) if sr_input else 44100 + + ch_input = input("Enter number of channels (1=mono,2=stereo) (default 2): ").strip() + channels = int(ch_input) if ch_input else 2 + + record_audio(record_duration, file_name, samplerate=samplerate, channels=channels, device=device) + except ValueError: + print("Invalid numeric input. Exiting.") + except Exception as e: + print("Error:", e) diff --git a/VOICE_RECORDER/voice_recorder.py b/VOICE_RECORDER/voice_recorder.py deleted file mode 100644 index 774cf66..0000000 --- a/VOICE_RECORDER/voice_recorder.py +++ /dev/null @@ -1,14 +0,0 @@ -import sounddevice as sd -import wavio - -def record_audio(duration, filename): - print("Recording...") - audio = sd.rec(int(duration * 44100), samplerate=44100, channels=2, dtype='int16') - sd.wait() # Wait until the recording is finished - wavio.write(filename, audio, 44100, sampwidth=2) # Save as WAV file - print(f"Recording saved as '{filename}'") - -if __name__ == "__main__": - record_duration = float(input("Enter duration in seconds: ")) - file_name = input("Enter filename (with .wav extension): ") - record_audio(record_duration, file_name) From 0f5b71b2bd3bd5908901de37c31e802322bffa22 Mon Sep 17 00:00:00 2001 From: Arjun Kumar Date: Sun, 2 Nov 2025 15:26:08 +0530 Subject: [PATCH 3/3] Add Number Guesser CLI game MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR title: Add Number Guesser CLI game One-line description: Simple CLI number-guessing game (1–100) with input validation, quit ('q'), and replay prompt. --- .../Number-guesser/Number_guesser.py | 54 +++++++++++++++++++ Number_Guessing/Number-guesser/README.md | 1 + 2 files changed, 55 insertions(+) create mode 100644 Number_Guessing/Number-guesser/Number_guesser.py create mode 100644 Number_Guessing/Number-guesser/README.md diff --git a/Number_Guessing/Number-guesser/Number_guesser.py b/Number_Guessing/Number-guesser/Number_guesser.py new file mode 100644 index 0000000..a4ee459 --- /dev/null +++ b/Number_Guessing/Number-guesser/Number_guesser.py @@ -0,0 +1,54 @@ +import random + +def play_game(): + random_num = random.randint(1, 100) + guesses = 0 + while True: + try: + user = input(f"Guess #{guesses + 1} (1-100) or 'q' to quit: ").strip() + except (EOFError, KeyboardInterrupt): + print("\nExiting game.") + return False + + if user.lower() == 'q': + print("Quitting current game.") + return False + + try: + guess = int(user) + except ValueError: + print("Please enter a valid integer between 1 and 100, or 'q' to quit.") + continue + + if not 1 <= guess <= 100: + print("Please guess a number between 1 and 100.") + continue + + guesses += 1 + + if guess == random_num: + plural = "guess" if guesses == 1 else "guesses" + print(f"You won in {guesses} {plural}! The number was {random_num}.") + return True + elif guess > random_num: + print("Your guess is too high.") + else: + print("Your guess is too low.") + +def main(): + while True: + play_game() + try: + answer = input("Would you like to play again? (Y/N): ").strip().lower() + except (EOFError, KeyboardInterrupt): + print("\nGoodbye.") + return + if answer in ('n', 'no'): + print("Thanks for playing. Goodbye.") + return + if answer in ('y', 'yes'): + continue + print("Please answer Y or N.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/Number_Guessing/Number-guesser/README.md b/Number_Guessing/Number-guesser/README.md new file mode 100644 index 0000000..3d99f4f --- /dev/null +++ b/Number_Guessing/Number-guesser/README.md @@ -0,0 +1 @@ +Simple CLI game: guess a random number (1–100), get feedback (too high/low), type `q` to quit. \ No newline at end of file