Skip to content

saksham-stack/codealpha_tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 CodeAlpha Tasks Repository

A collection of modern Python projects featuring async APIs, real-time financial data, and interactive visualizations.

Python Version License Last Updated


πŸ“ What's Inside

1. 🎲 Task1.py - Random Word & Definition Fetcher

A powerful async Python script that fetches random English words and their definitions from the Datamuse API.

✨ Key Features:

  • ⚑ Async HTTP requests for non-blocking operations
  • πŸ” Fetches random 6-letter English nouns with detailed definitions
  • πŸ›‘οΈ Intelligent fallback mechanism for offline usage
  • πŸŽ›οΈ Customizable word length via wildcard patterns
  • πŸš€ Production-ready error handling

πŸ“‘ API: Datamuse API

Example Output:

πŸ“‘ Connecting to Datamuse API to fetch a secret word...
βœ… Word Found: PYTHON
Definition: A large snake found in tropical regions

2. πŸ“Š Task2.py - Real-Time Portfolio Visualizer

An interactive CLI application that analyzes your investment portfolio with real-time stock prices and generates beautiful charts.

✨ Key Features:

  • πŸ’° Real-time stock price fetching from Yahoo Finance
  • πŸ–₯️ Interactive command-line interface
  • πŸ“ˆ Professional horizontal bar charts
  • πŸ’Ό Automatic portfolio value calculation
  • πŸ’Ύ CSV export functionality
  • 🎨 Customized styling with seaborn

πŸ“‘ API: Yahoo Finance (via yfinance library)

Example Output:

πŸ“Š Launching visual engine window...
[Displays interactive portfolio allocation chart]

3. πŸ“„ visual_portfolio_manifest.csv

Sample portfolio data file demonstrating the expected CSV format.

Contents:

  • NVDA: 45 units @ $209.05 = $9,407.25
  • AAPL: 30 units @ $303.84 = $9,115.20
  • Total Portfolio Value: $18,522.45


οΏ½ Requirements

🐍 Python Version

  • Python 3.7+ (recommended: Python 3.10 or higher)

πŸ“š Dependencies

Package Version Purpose
httpx >= 0.23.0 Async HTTP requests (Task1)
yfinance >= 0.1.70 Yahoo Finance data retrieval (Task2)
matplotlib >= 3.5.0 Data visualization (Task2)

Optional but recommended:

  • pandas - Advanced data manipulation
  • aiohttp - Alternative async HTTP library
  • requests - Synchronous HTTP fallback

πŸ’» System Requirements

  • βœ… Windows, macOS, or Linux
  • βœ… Internet connection (required for live API calls)
  • βœ… Display capability (for matplotlib visualizations)
  • βœ… 50MB+ free disk space

πŸš€ Quick Start

βš™οΈ Installation

  1. Clone or download this repository

    git clone https://github.com/saksham-stack/codealpha-tasks.git
    cd codealpha-tasks
  2. Install dependencies

    pip install httpx yfinance matplotlib

    Or install from requirements file (if available):

    pip install -r requirements.txt
  3. Verify installation

    python -c "import httpx, yfinance, matplotlib; print('βœ… All dependencies installed!')"

πŸ“– Usage Guide

🎲 Running Task1.py - Word Fetcher

python Task1.py

What it does:

  • Connects to Datamuse API
  • Fetches a random 6-letter English noun
  • Displays the word with its definition
  • Falls back to local dictionary if offline

Requirements: Internet connection

Sample Run:

πŸ“‘ Connecting to Datamuse API to fetch a secret word...
βœ… Word Found: WHISPER
Definition: Soft, hushed speech or voice

πŸ“Š Running Task2.py - Portfolio Visualizer

python Task2.py

Step-by-Step Walkthrough:

=========================================
   VISUAL LIVE-TICKING ASSET ANALYTICS   
=========================================
Type 'done' when you have finished entering your positions.

1️⃣  Enter ticker symbol: AAPL
2️⃣  Enter quantity held: 30
3️⃣  Enter unit price (optional, or press Enter for live fetch): [Press Enter]
    βœ… Asset recorded: AAPL @ $303.84 (30 units)

4️⃣  Enter ticker symbol: NVDA
5️⃣  Enter quantity held: 45
6️⃣  Enter unit price (optional, or press Enter for live fetch): [Press Enter]
    βœ… Asset recorded: NVDA @ $209.05 (45 units)

7️⃣  Enter ticker symbol: done
πŸ“Š Launching visual engine window...
πŸ’Ύ Data exported to: visual_portfolio_manifest.csv

Output Files:

  • Interactive chart visualization
  • visual_portfolio_manifest.csv - Portfolio data export

Requirements: Internet connection for real-time prices


οΏ½ Troubleshooting

❌ "API Connection Failed"

Cause: Network connectivity issue or API downtime
Solution:

# Check internet connection
ping google.com

# Verify API is online (Task1)
curl https://api.datamuse.com/words?sp="?????"

# Try again in a few moments

❌ ModuleNotFoundError: No module named 'httpx'

Cause: Dependencies not installed
Solution:

pip install --upgrade httpx yfinance matplotlib

❌ TimeoutError

Cause: API response is slow
Solution:

  • Check your internet speed
  • Try running the script again
  • Increase timeout in code (advanced users)

❌ Matplotlib Display Issues

Cause: Display backend not configured
Solution: Add this to the top of Task2.py:

import matplotlib
matplotlib.use('TkAgg')  # or 'Qt5Agg', 'Agg', etc.

❌ Invalid Ticker Symbol

Cause: Typo in stock symbol
Solution:

  • Verify ticker on Yahoo Finance
  • Use uppercase (e.g., AAPL not aapl)

οΏ½ Common Issues & FAQs

Issue Solution
No internet? Task1 has offline fallback; Task2 requires internet
Charts not showing? Try different matplotlib backend (TkAgg, Qt5Agg, Agg)
Slow API response? Normal during market hours; try off-peak times
CSV not generated? Ensure write permissions in the directory

🎨 Customization

Modify Task1.py Word Length

Change the wildcard pattern in line 15:

"sp": "??????",     # 6-letter words (6 question marks)
"sp": "?????",      # 5-letter words
"sp": "????????",   # 8-letter words

Customize Task2.py Chart Colors

Modify the color scheme in line 24:

bars = ax.barh(tickers, values, color='#2ca02c', edgecolor='#1a611a', height=0.6)
# Change '#2ca02c' to any hex color code

οΏ½ Project Structure

codealpha-tasks/
β”œβ”€β”€ README.md                          # This file
β”œβ”€β”€ Task1.py                           # Word fetcher script
β”œβ”€β”€ Task2.py                           # Portfolio visualizer script
β”œβ”€β”€ visual_portfolio_manifest.csv      # Sample data file
└── requirements.txt                   # (Optional) Dependency file

πŸ’‘ Learning Outcomes

By using these projects, you'll learn:

  • βœ… Async Programming - Understanding asyncio and async/await patterns
  • βœ… REST APIs - Consuming external APIs (Datamuse, Yahoo Finance)
  • βœ… Data Visualization - Creating professional charts with matplotlib
  • βœ… CLI Development - Building interactive command-line applications
  • βœ… Error Handling - Implementing fallbacks and exception handling
  • βœ… CSV Operations - Reading and writing CSV files

🀝 Contributing

We welcome contributions! Here's how to help:

  1. Report Issues - Found a bug? Create an issue
  2. Submit PRs - Have improvements? Send a pull request
  3. Improve Docs - Help us improve this README
  4. Share Ideas - Suggest new features in the discussions

πŸ“„ License

These tasks are part of the CodeAlpha Training Program.
Licensed under the MIT License - see LICENSE file for details.


πŸ™ Acknowledgments

  • Datamuse - For the amazing word/definition API
  • Yahoo Finance - For real-time stock market data
  • Python Community - For incredible libraries like httpx, yfinance, and matplotlib
  • CodeAlpha - For the opportunity to build these projects

πŸ“ž Support & Contact


πŸ“ˆ Project Stats

Metric Value
Language Python 3.7+
Lines of Code ~250 (combined)
External APIs 2
Core Dependencies 3
Last Updated June 2026

⭐ If you find this useful, please star this repository!

Made with ❀️ for the CodeAlpha Community

πŸ” Back to Top

About

Collection of Python applications demonstrating async programming, REST API integration (Datamuse, Yahoo Finance), data visualization, and CLI development. Includes a random word fetcher and real-time portfolio analyzer.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages