diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..c554bd61 --- /dev/null +++ b/.env.example @@ -0,0 +1,22 @@ +# API Keys Configuration +# Copy this file to .env and fill in your actual API keys + +# OpenWeatherMap API (for weather and air quality data) +# Get your free API key from: https://openweathermap.org/api +OPENWEATHER_API_KEY=your_openweathermap_api_key_here + +# Visual Crossing API (for monthly weather data) +# Get your free API key from: https://www.visualcrossing.com/weather-api +VISUALCROSSING_API_KEY=your_visualcrossing_api_key_here + +# News API (for crime news) +# Get your free API key from: https://newsapi.org/ +NEWS_API_KEY=your_news_api_key_here + +# Google Custom Search API (for chatbot functionality) +# Get your API key from: https://developers.google.com/custom-search/v1/introduction +GOOGLE_API_KEY=your_google_api_key_here + +# Google Custom Search Engine ID +# Create a custom search engine at: https://cse.google.com/ +CSE_ID=your_custom_search_engine_id_here diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..362d098c --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +# Environment variables +.env +.env.local +.env.*.local + +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +.venv/ + +# Streamlit +.streamlit/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Logs +*.log + +# Temporary files +*.tmp +*.temp + +# API Keys and secrets (additional security) +config/secrets.py +secrets.json diff --git a/README.md b/README.md index bab0a7b2..403441fa 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,51 @@ City Pulse is a sleek, real-time dashboard built with **Streamlit** that provide --- -## 📦 Installation +## 📦 Installation & Setup +### 1. Clone the Repository +```bash +git clone https://github.com/your-username/CITY-PULSE.git +cd CITY-PULSE +``` + +### 2. Install Dependencies ```bash -git clone https://github.com/your-username/city-pulse.git -cd city-pulse pip install -r requirements.txt +``` + +### 3. Set Up Environment Variables +1. Copy the example environment file: + ```bash + cp .env.example .env + ``` + +2. Edit the `.env` file and add your API keys: + ```bash + # Required API Keys + OPENWEATHER_API_KEY=your_openweathermap_api_key_here + VISUALCROSSING_API_KEY=your_visualcrossing_api_key_here + NEWS_API_KEY=your_news_api_key_here + GOOGLE_API_KEY=your_google_api_key_here + CSE_ID=your_custom_search_engine_id_here + ``` + +### 4. Get Your API Keys +- **OpenWeatherMap API**: [Get free API key](https://openweathermap.org/api) +- **Visual Crossing API**: [Get free API key](https://www.visualcrossing.com/weather-api) +- **News API**: [Get free API key](https://newsapi.org/) +- **Google Custom Search API**: [Get API key](https://developers.google.com/custom-search/v1/introduction) +- **Custom Search Engine**: [Create CSE](https://cse.google.com/) + +### 5. Run the Application +```bash streamlit run app.py +``` + +--- + +## 🚨 Security Notice + +This application requires API keys to function properly. **Never commit your `.env` file or expose your API keys publicly**. The `.env` file is already included in `.gitignore` to prevent accidental commits. + +--- diff --git a/utils/chatbot.py b/utils/chatbot.py index 60822764..a43da86a 100644 --- a/utils/chatbot.py +++ b/utils/chatbot.py @@ -1,10 +1,20 @@ # utils/chatbot.py import requests +import os +from dotenv import load_dotenv -# Replace these with env variables or config if you want -GOOGLE_API_KEY = "AIzaSyAIQcBW-1Wmx4Z8vuvyibvrum9dS0HgheI" -CSE_ID = "41a7d2bcb1d014824" +load_dotenv() + +# Load API keys from environment variables +GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") +CSE_ID = os.getenv("CSE_ID") + +# Validate that required environment variables are set +if not GOOGLE_API_KEY: + raise ValueError("Missing required environment variable: GOOGLE_API_KEY") +if not CSE_ID: + raise ValueError("Missing required environment variable: CSE_ID") def search_google(query): try: