import requests import logging from config import config logger = logging.getLogger(__name__) def check_website_status(): """ Check if the FeedHire website is accessible Returns: tuple: (icon, status_text, color) """ try: logger.debug("Checking FeedHire website status") response = requests.get("https://feedhire.me/", timeout=10) if response.status_code == 200: logger.info("FeedHire website is online") return "🟢", "Online", "#10b981" else: logger.warning(f"FeedHire website returned status {response.status_code}") return "🟡", f"Status {response.status_code}", "#f59e0b" except requests.exceptions.RequestException as e: logger.error(f"FeedHire website check failed: {e}") return "🔴", "Offline", "#ef4444" def check_api_status(): """ Check if the LinkedIn API is accessible and token is valid Returns: tuple: (icon, status_text, color) """ if not config.token or not config.organisation_number: logger.warning("LinkedIn API credentials not configured") return "🔴", "No Credentials", "#ef4444" try: logger.debug("Checking LinkedIn API status") headers = { "Authorization": f"Bearer {config.token}", "LinkedIn-Version": "202510", "X-Restli-Protocol-Version": "2.0.0" } response = requests.get( f"https://api.linkedin.com/rest/organizations/{config.organisation_number}", headers=headers, timeout=10 ) if response.status_code == 200: logger.info("LinkedIn API connection successful") return "🟢", "Connected", "#10b981" elif response.status_code == 401: logger.error("LinkedIn API authentication failed") return "🔴", "Auth Failed", "#ef4444" elif response.status_code == 403: logger.error("LinkedIn API access denied") return "🟡", "Access Denied", "#f59e0b" else: logger.warning(f"LinkedIn API returned status {response.status_code}") return "🟡", f"Error {response.status_code}", "#f59e0b" except requests.exceptions.RequestException as e: logger.error(f"LinkedIn API connection failed: {e}") return "🔴", "Connection Failed", "#ef4444" def get_status_display(): """ Get formatted HTML status display for both services Returns: str: HTML string with status information """ logger.debug("Generating status display") web_icon, web_status, web_color = check_website_status() api_icon, api_status, api_color = check_api_status() html = f"""