File size: 3,470 Bytes
f40d9d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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