File size: 6,544 Bytes
d6d843f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
# Deployment Verification Script
# Run this script to verify the deployment is ready

set -e

echo "╔════════════════════════════════════════════════════════════╗"
echo "β•‘  πŸ” DEPLOYMENT VERIFICATION SCRIPT                         β•‘"
echo "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•"
echo ""

ERRORS=0

# Check 1: Required files exist
echo "πŸ“‹ Check 1: Required files..."
for file in requirements.txt Dockerfile api_server_extended.py provider_fetch_helper.py database.py; do
    if [ -f "$file" ]; then
        echo "  βœ… $file exists"
    else
        echo "  ❌ $file missing"
        ((ERRORS++))
    fi
done
echo ""

# Check 2: Dockerfile configuration
echo "🐳 Check 2: Dockerfile configuration..."
if grep -q "USE_MOCK_DATA=false" Dockerfile; then
    echo "  βœ… USE_MOCK_DATA environment variable set"
else
    echo "  ❌ USE_MOCK_DATA not found in Dockerfile"
    ((ERRORS++))
fi

if grep -q "mkdir -p logs data exports backups" Dockerfile; then
    echo "  βœ… Directory creation configured"
else
    echo "  ❌ Directory creation missing"
    ((ERRORS++))
fi

if grep -q "uvicorn api_server_extended:app" Dockerfile; then
    echo "  βœ… Uvicorn startup command configured"
else
    echo "  ❌ Uvicorn startup command missing"
    ((ERRORS++))
fi
echo ""

# Check 3: Requirements.txt dependencies
echo "πŸ“¦ Check 3: Required dependencies..."
for dep in fastapi uvicorn pydantic sqlalchemy aiohttp; do
    if grep -q "$dep" requirements.txt; then
        echo "  βœ… $dep found in requirements.txt"
    else
        echo "  ❌ $dep missing from requirements.txt"
        ((ERRORS++))
    fi
done
echo ""

# Check 4: USE_MOCK_DATA implementation
echo "πŸ”§ Check 4: USE_MOCK_DATA flag implementation..."
if grep -q 'USE_MOCK_DATA = os.getenv("USE_MOCK_DATA"' api_server_extended.py; then
    echo "  βœ… USE_MOCK_DATA flag implemented"
else
    echo "  ❌ USE_MOCK_DATA flag not found"
    ((ERRORS++))
fi
echo ""

# Check 5: Real data collectors imported
echo "🌐 Check 5: Real data collector imports..."
if grep -q "from collectors.sentiment import get_fear_greed_index" api_server_extended.py; then
    echo "  βœ… Sentiment collector imported"
else
    echo "  ❌ Sentiment collector import missing"
    ((ERRORS++))
fi

if grep -q "from collectors.market_data import get_coingecko_simple_price" api_server_extended.py; then
    echo "  βœ… Market data collector imported"
else
    echo "  ❌ Market data collector import missing"
    ((ERRORS++))
fi

if grep -q "from database import get_database" api_server_extended.py; then
    echo "  βœ… Database import found"
else
    echo "  ❌ Database import missing"
    ((ERRORS++))
fi
echo ""

# Check 6: Mock data removed from endpoints
echo "🚫 Check 6: Mock data handling..."
MOCK_COUNT=$(grep -c "if USE_MOCK_DATA:" api_server_extended.py || echo "0")
if [ "$MOCK_COUNT" -ge 5 ]; then
    echo "  βœ… USE_MOCK_DATA checks found in $MOCK_COUNT locations"
else
    echo "  ⚠️  USE_MOCK_DATA checks found in only $MOCK_COUNT locations (expected 5+)"
    ((ERRORS++))
fi
echo ""

# Check 7: Database integration
echo "πŸ’Ύ Check 7: Database integration..."
if grep -q "db.save_price" api_server_extended.py; then
    echo "  βœ… Database save_price integration found"
else
    echo "  ❌ Database save_price integration missing"
    ((ERRORS++))
fi

if grep -q "db.get_price_history" api_server_extended.py; then
    echo "  βœ… Database get_price_history integration found"
else
    echo "  ❌ Database get_price_history integration missing"
    ((ERRORS++))
fi
echo ""

# Check 8: Error handling for unimplemented endpoints
echo "⚠️  Check 8: Proper error codes for unimplemented endpoints..."
if grep -q "status_code=503" api_server_extended.py; then
    echo "  βœ… HTTP 503 error handling found"
else
    echo "  ❌ HTTP 503 error handling missing"
    ((ERRORS++))
fi

if grep -q "status_code=501" api_server_extended.py; then
    echo "  βœ… HTTP 501 error handling found"
else
    echo "  ❌ HTTP 501 error handling missing"
    ((ERRORS++))
fi
echo ""

# Check 9: Python syntax
echo "🐍 Check 9: Python syntax validation..."
if python3 -m py_compile api_server_extended.py 2>/dev/null; then
    echo "  βœ… api_server_extended.py syntax valid"
else
    echo "  ❌ api_server_extended.py syntax errors"
    ((ERRORS++))
fi

if python3 -m py_compile provider_fetch_helper.py 2>/dev/null; then
    echo "  βœ… provider_fetch_helper.py syntax valid"
else
    echo "  ❌ provider_fetch_helper.py syntax errors"
    ((ERRORS++))
fi
echo ""

# Check 10: Documentation
echo "πŸ“„ Check 10: Documentation..."
if [ -f "DEPLOYMENT_INSTRUCTIONS.md" ]; then
    echo "  βœ… DEPLOYMENT_INSTRUCTIONS.md exists"
else
    echo "  ⚠️  DEPLOYMENT_INSTRUCTIONS.md missing (recommended)"
fi

if [ -f "AUDIT_COMPLETION_REPORT.md" ]; then
    echo "  βœ… AUDIT_COMPLETION_REPORT.md exists"
else
    echo "  ⚠️  AUDIT_COMPLETION_REPORT.md missing (recommended)"
fi
echo ""

# Final verdict
echo "═══════════════════════════════════════════════════════════"
if [ $ERRORS -eq 0 ]; then
    echo "β•‘  βœ… ALL CHECKS PASSED                                    β•‘"
    echo "β•‘  STATUS: READY FOR HUGGINGFACE DEPLOYMENT βœ…            β•‘"
    echo "═══════════════════════════════════════════════════════════"
    echo ""
    echo "πŸš€ Next steps:"
    echo "   1. docker build -t crypto-monitor ."
    echo "   2. docker run -p 7860:7860 crypto-monitor"
    echo "   3. Test: curl http://localhost:7860/health"
    echo "   4. Deploy to HuggingFace Spaces"
    echo ""
    exit 0
else
    echo "β•‘  ❌ FOUND $ERRORS ERROR(S)                                  β•‘"
    echo "β•‘  STATUS: NOT READY FOR DEPLOYMENT ❌                    β•‘"
    echo "═══════════════════════════════════════════════════════════"
    echo ""
    echo "⚠️  Please fix the errors above before deploying."
    echo ""
    exit 1
fi