Add Docker support and fix rating change extraction
- Add Dockerfile with optimized Puppeteer configuration for containers - Add .dockerignore for efficient builds - Fix rating change regex to match actual PDGA format (no brackets) - Update Puppeteer launch args for Docker compatibility - Use new headless mode to resolve deprecation warning 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,18 @@ async function scrapePDGARating(pdgaNumber) {
|
||||
return cached.data;
|
||||
}
|
||||
|
||||
const browser = await puppeteer.launch({ headless: true });
|
||||
const browser = await puppeteer.launch({
|
||||
headless: "new",
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-accelerated-2d-canvas',
|
||||
'--no-first-run',
|
||||
'--no-zygote',
|
||||
'--disable-gpu'
|
||||
]
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
|
||||
try {
|
||||
@@ -37,29 +48,14 @@ async function scrapePDGARating(pdgaNumber) {
|
||||
for (const el of elements) {
|
||||
const text = el.innerText || el.textContent;
|
||||
if (text.includes('Current Rating:')) {
|
||||
console.log('Found rating text:', text);
|
||||
const ratingMatch = text.match(/Current Rating:\s*(\d+)/);
|
||||
|
||||
// Try different patterns for rating change
|
||||
const changePatterns = [
|
||||
/\[(\+\d+)\]/,
|
||||
/\[(\-\d+)\]/,
|
||||
/(\+\d+)/,
|
||||
/(\-\d+)/
|
||||
];
|
||||
|
||||
let change = null;
|
||||
for (const pattern of changePatterns) {
|
||||
const match = text.match(pattern);
|
||||
if (match) {
|
||||
change = match[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Look for rating change pattern: "Current Rating: 911 +6 (as of..."
|
||||
const changeMatch = text.match(/Current Rating:\s*\d+\s+([+\-]\d+)\s+\(as of/);
|
||||
|
||||
return {
|
||||
rating: ratingMatch ? ratingMatch[1] : null,
|
||||
change: change
|
||||
change: changeMatch ? changeMatch[1] : null
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -318,7 +314,18 @@ app.get('/api/ratings', async (req, res) => {
|
||||
app.post('/api/predicted-rating/:pdgaNumber', async (req, res) => {
|
||||
try {
|
||||
const { pdgaNumber } = req.params;
|
||||
const browser = await puppeteer.launch({ headless: true });
|
||||
const browser = await puppeteer.launch({
|
||||
headless: "new",
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-accelerated-2d-canvas',
|
||||
'--no-first-run',
|
||||
'--no-zygote',
|
||||
'--disable-gpu'
|
||||
]
|
||||
});
|
||||
|
||||
console.log(`Calculating predicted rating for PDGA ${pdgaNumber}...`);
|
||||
const predictedRating = await getPredictedRating(browser, pdgaNumber);
|
||||
|
||||
Reference in New Issue
Block a user