cf4b5764b5
1. P1: 合并双 Flask 服务 — web_executor.py 功能整合到 app.py - /fetch → 抓取控制台页面 - /api/fetch/status → 抓取状态查询 - /api/fetch/execute → 触发抓取(后台线程异步) - web_console.html API 路径已更新 2. P1: fetch_data.py 增加重试机制 + 请求间隔 - REQUEST_DELAY=2s, MAX_RETRIES=3, RETRY_DELAY=5s - 修复缩进 bug(try/except 块缩进错误) 3. P0: 修复 Excel 数据格式兼容性 - fetch_data.py: 跳过网页 header 行,使用标准列名保存 - app.py: 新增 load_history_dataframe() 智能加载函数 - 兼容新旧两种 Excel 格式(一行/两行 header) - 统一列名: 开奖时间|期数|号码|开机号|和值特征|奇偶比|大小比|奇偶形态|跨度|其他 4. 运维: 创建 lotto-app.service systemd 单元 5. 修复 .gitignore(排除运行时数据文件和备份) 6. 创建 requirements.txt
324 lines
11 KiB
HTML
324 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>双色球数据抓取 - 执行控制台</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 900px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 12px;
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.header {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 30px;
|
|
text-align: center;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 28px;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.header p {
|
|
opacity: 0.9;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.status-bar {
|
|
background: #f8f9fa;
|
|
padding: 15px 30px;
|
|
border-bottom: 1px solid #e9ecef;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
gap: 10px;
|
|
}
|
|
|
|
.status-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.status-indicator {
|
|
width: 12px;
|
|
height: 12px;
|
|
border-radius: 50%;
|
|
background: #6c757d;
|
|
}
|
|
|
|
.status-indicator.ready { background: #28a745; }
|
|
.status-indicator.running {
|
|
background: #ffc107;
|
|
animation: pulse 1s infinite;
|
|
}
|
|
.status-indicator.completed { background: #28a745; }
|
|
.status-indicator.error { background: #dc3545; }
|
|
|
|
@keyframes pulse {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.5; }
|
|
}
|
|
|
|
.controls {
|
|
padding: 30px;
|
|
text-align: center;
|
|
}
|
|
|
|
.btn {
|
|
display: inline-block;
|
|
padding: 15px 40px;
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
color: white;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
border: none;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.btn:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.btn:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.console {
|
|
padding: 0 30px 30px;
|
|
}
|
|
|
|
.console-output {
|
|
background: #1e1e1e;
|
|
color: #d4d4d4;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
font-family: "Monaco", "Menlo", "Courier New", monospace;
|
|
font-size: 13px;
|
|
line-height: 1.6;
|
|
min-height: 200px;
|
|
max-height: 400px;
|
|
overflow-y: auto;
|
|
white-space: pre-wrap;
|
|
}
|
|
|
|
.console-output .success { color: #6a9955; }
|
|
.console-output .error { color: #f44747; }
|
|
.console-output .info { color: #569cd6; }
|
|
|
|
.last-update {
|
|
padding: 15px 30px;
|
|
background: #f8f9fa;
|
|
border-top: 1px solid #e9ecef;
|
|
text-align: center;
|
|
font-size: 13px;
|
|
color: #6c757d;
|
|
}
|
|
|
|
.info-section {
|
|
padding: 20px 30px;
|
|
background: #fff3cd;
|
|
border-top: 1px solid #ffc107;
|
|
}
|
|
|
|
.info-section h3 {
|
|
font-size: 16px;
|
|
margin-bottom: 10px;
|
|
color: #856404;
|
|
}
|
|
|
|
.info-section ul {
|
|
list-style: none;
|
|
font-size: 14px;
|
|
color: #856404;
|
|
}
|
|
|
|
.info-section li { padding: 5px 0; }
|
|
.info-section code {
|
|
background: rgba(0,0,0,0.1);
|
|
padding: 2px 6px;
|
|
border-radius: 3px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>🎯 双色球数据抓取控制台</h1>
|
|
<p>定时任务执行器 - 实时监控数据抓取状态</p>
|
|
</div>
|
|
|
|
<div class="status-bar">
|
|
<div class="status-item">
|
|
<div class="status-indicator ready" id="statusIndicator"></div>
|
|
<span id="statusText">等待执行</span>
|
|
</div>
|
|
<div class="status-item">
|
|
<strong>数据源:</strong> www.55128.cn
|
|
</div>
|
|
<div class="status-item">
|
|
<strong>上次更新:</strong> <span id="lastUpdate">从未</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="info-section">
|
|
<h3>📋 使用说明</h3>
|
|
<ul>
|
|
<li>✅ 点击「立即执行」按钮抓取最新双色球历史数据</li>
|
|
<li>✅ 数据将保存到:<code>/home/vincent/Studio/lottoData/双色球历史数据.xlsx</code></li>
|
|
<li>✅ 定时任务:每天自动执行一次(通过系统 cron)</li>
|
|
<li>✅ 实时监控:执行日志在此页面实时显示</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="controls">
|
|
<button class="btn" id="executeBtn" onclick="executeScript()">
|
|
🚀 立即执行抓取
|
|
</button>
|
|
</div>
|
|
|
|
<div class="console">
|
|
<h3 style="margin-bottom: 10px; color: #495057; font-size: 16px;">📄 执行日志</h3>
|
|
<div class="console-output" id="consoleOutput">// 等待执行任务...
|
|
// 点击「立即执行抓取」按钮开始任务</div>
|
|
</div>
|
|
|
|
<div class="last-update">
|
|
脚本路径:<code>/home/vincent/Studio/lottoData/fetch_data.py</code> |
|
|
输出文件:<span id="outputFile">双色球历史数据.xlsx</span>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let isExecuting = false;
|
|
|
|
function log(message, type = 'info') {
|
|
const output = document.getElementById('consoleOutput');
|
|
const timestamp = new Date().toLocaleTimeString('zh-CN');
|
|
const className = type === 'success' ? 'success' : type === 'error' ? 'error' : 'info';
|
|
output.innerHTML += `\n<span class="${className}">[${timestamp}] ${message}</span>`;
|
|
output.scrollTop = output.scrollHeight;
|
|
}
|
|
|
|
function updateStatus(status, text) {
|
|
const indicator = document.getElementById('statusIndicator');
|
|
indicator.className = 'status-indicator ' + status;
|
|
document.getElementById('statusText').textContent = text;
|
|
}
|
|
|
|
async function executeScript() {
|
|
if (isExecuting) {
|
|
log('任务正在执行中...', 'error');
|
|
return;
|
|
}
|
|
|
|
isExecuting = true;
|
|
document.getElementById('executeBtn').disabled = true;
|
|
document.getElementById('consoleOutput').innerHTML = '';
|
|
log('开始执行抓取任务...', 'info');
|
|
updateStatus('running', '执行中');
|
|
|
|
try {
|
|
const response = await fetch('/api/fetch/execute', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
log('正在抓取数据,请稍候...', 'info');
|
|
|
|
// 轮询状态直到完成
|
|
const pollInterval = setInterval(async () => {
|
|
try {
|
|
const statusResp = await fetch('/api/fetch/status');
|
|
const status = await statusResp.json();
|
|
|
|
if (!status.isRunning) {
|
|
clearInterval(pollInterval);
|
|
|
|
if (status.lastError) {
|
|
log(`❌ 任务失败:${status.lastError}`, 'error');
|
|
updateStatus('error', '执行失败');
|
|
} else {
|
|
log(`✅ 任务执行成功!`, 'success');
|
|
log(`📊 共抓取 ${status.recordCount} 条数据`, 'success');
|
|
updateStatus('completed', '执行完成');
|
|
document.getElementById('lastUpdate').textContent = new Date(status.lastUpdate).toLocaleString('zh-CN');
|
|
}
|
|
|
|
isExecuting = false;
|
|
document.getElementById('executeBtn').disabled = false;
|
|
}
|
|
} catch (e) {
|
|
console.error('轮询失败:', e);
|
|
}
|
|
}, 2000);
|
|
|
|
} else {
|
|
log(`❌ 任务失败:${data.error}`, 'error');
|
|
updateStatus('error', '执行失败');
|
|
isExecuting = false;
|
|
document.getElementById('executeBtn').disabled = false;
|
|
}
|
|
} catch (error) {
|
|
log(`❌ 请求错误:${error.message}`, 'error');
|
|
updateStatus('error', '执行失败');
|
|
isExecuting = false;
|
|
document.getElementById('executeBtn').disabled = false;
|
|
}
|
|
}
|
|
|
|
async function loadStatus() {
|
|
try {
|
|
const response = await fetch('/api/fetch/status');
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
if (data.lastUpdate) {
|
|
document.getElementById('lastUpdate').textContent = new Date(data.lastUpdate).toLocaleString('zh-CN');
|
|
if (data.recordCount > 0) {
|
|
log(`上次执行:共抓取 ${data.recordCount} 条数据`, 'info');
|
|
}
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error('加载状态失败:', error);
|
|
}
|
|
}
|
|
|
|
loadStatus();
|
|
</script>
|
|
</body>
|
|
</html> |