Spaces:
Sleeping
Sleeping
| 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""" | |
| <div class="status-container"> | |
| <div class="status-item"> | |
| <span class="status-icon">{web_icon}</span> | |
| <div> | |
| <div class="status-label">Website</div> | |
| <div class="status-value" style="color: {web_color};">{web_status}</div> | |
| </div> | |
| </div> | |
| <div class="status-divider"></div> | |
| <div class="status-item"> | |
| <span class="status-icon">{api_icon}</span> | |
| <div> | |
| <div class="status-label">API</div> | |
| <div class="status-value" style="color: {api_color};">{api_status}</div> | |
| </div> | |
| </div> | |
| </div> | |
| """ | |
| return html |