================================================================================ GMAIL CLEANUP - CHALLENGE 1 SOLUTION Chapter 1: Configuration & API Setup Challenge: Project Setup ================================================================================ PROBLEM: Set up the complete project structure: 1. Create gmail-cleanup/ directory 2. Create .env and .env.example files 3. Create requirements.txt with Gmail API dependencies 4. Create credentials.json from Google Cloud Console 5. Create .gitignore with appropriate entries SOLUTION: ================================================================================ STEP 1: Create Project Directory ================================================================================ mkdir gmail-cleanup cd gmail-cleanup STEP 2: Create .env.example (template) ================================================================================ File: .env.example # Gmail account to manage GMAIL_USER=your-email@gmail.com # API settings API_REQUEST_TIMEOUT=10 MAX_RESULTS=100 # Cleanup settings DELETE_OLDER_THAN_DAYS=365 MIN_ATTACHMENT_SIZE_MB=10 STEP 3: Create .env (your actual configuration) ================================================================================ File: .env # Gmail account to manage GMAIL_USER=emubantam@gmail.com # API settings API_REQUEST_TIMEOUT=10 MAX_RESULTS=100 # Cleanup settings DELETE_OLDER_THAN_DAYS=365 MIN_ATTACHMENT_SIZE_MB=10 STEP 4: Create requirements.txt ================================================================================ File: requirements.txt google-auth-oauthlib==1.1.0 google-auth-httplib2==0.2.0 google-api-python-client==2.100.0 python-dotenv==1.0.0 STEP 5: Create .gitignore ================================================================================ File: .gitignore # Environment & Secrets .env token.json credentials.json # Python __pycache__/ *.pyc *.pyo *.egg-info/ dist/ build/ # IDE .vscode/ .idea/ *.swp *.swo # OS .DS_Store Thumbs.db # Project specific *.log .cache/ STEP 6: Get credentials.json from Google Cloud ================================================================================ 1. Go to https://console.cloud.google.com 2. Create a new project: "Gmail Cleanup Utility" 3. Enable Gmail API (APIs & Services → Library → Search "Gmail API") 4. Create OAuth credentials (APIs & Services → Credentials → Create Credentials → OAuth client ID) 5. Select "Desktop application" 6. Download JSON file and save as credentials.json in gmail-cleanup/ FINAL PROJECT STRUCTURE ================================================================================ gmail-cleanup/ ├── .env ← Your configuration (DON'T commit!) ├── .env.example ← Template for others ├── credentials.json ← Google OAuth credentials (DON'T commit!) ├── requirements.txt ← Dependencies └── .gitignore ← Ignore secrets When complete, you should have: - 3 visible files (.env.example, requirements.txt, .gitignore) - 2 secret files that WON'T show up in Git (.env, credentials.json) VERIFICATION CHECKLIST ================================================================================ ✅ gmail-cleanup/ directory created ✅ .env file created with your Gmail address ✅ .env.example created as template ✅ requirements.txt created with Gmail API libs ✅ credentials.json downloaded from Google Cloud ✅ .gitignore prevents committing secrets Key Points: - .env is private (never commit it!) - credentials.json is private (never commit it!) - .env.example is public (shows what variables are needed) - .gitignore prevents accidental commits ================================================================================