-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle already processed cars, adding parallel scrappers with rate li…
…miting
- Loading branch information
Showing
10 changed files
with
1,179 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,4 +154,7 @@ dist | |
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
.pnp.* | ||
|
||
# Google cloud | ||
.gcloudignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import playwright from 'playwright'; | ||
import chromium from 'chrome-aws-lambda'; | ||
import { isDev } from './utils.js'; | ||
|
||
export async function launchBrowser() { | ||
const browser = isDev() | ||
? await playwright.chromium.launch({ | ||
headless: false, | ||
}) | ||
: await playwright.chromium.launch({ | ||
args: chromium.args, | ||
executablePath: await chromium.executablePath, | ||
headless: chromium.headless, | ||
}); | ||
|
||
const context = await browser.newContext(); | ||
const page = await context.newPage(); | ||
|
||
return { browser, context, page }; | ||
} | ||
|
||
export async function closeBrowser(browser, context) { | ||
await context.close(); | ||
await browser.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Firestore } from '@google-cloud/firestore'; | ||
|
||
const db = new Firestore({ | ||
projectId: 'auctions-388714', | ||
}); | ||
|
||
export async function addProcessedAuctions(cars) { | ||
console.log('::: adding processed auctions :::'); | ||
const batch = db.batch(); | ||
|
||
for (let car of cars) { | ||
const carRef = db.collection('processedAuctions').doc(`${car.auctionId}`); | ||
batch.set(carRef, { auctionId: car.auctionId }); | ||
} | ||
|
||
return batch.commit(); | ||
} | ||
|
||
export async function addPotentialCars(cars) { | ||
console.log('::: adding processed potential cars :::'); | ||
const batch = db.batch(); | ||
|
||
for (let car of cars) { | ||
const carRef = db.collection('potentialCars').doc(`${car.auctionId}`); | ||
batch.set(carRef, car); | ||
} | ||
|
||
return batch.commit(); | ||
} | ||
|
||
export async function getProcessedAuction(auctionId) { | ||
console.log(`::: get processed auction ${auctionId} :::`); | ||
const processedAuctionRef = db | ||
.collection('processedAuctions') | ||
.doc(`${auctionId}`); | ||
const doc = await processedAuctionRef.get(); | ||
|
||
if (doc.exists) { | ||
return doc.data(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
export async function getAllProcessedAuctions() { | ||
console.log('::: get all processed auctions :::'); | ||
const processedAuctionsRef = db.collection('processedAuctions'); | ||
const snapshot = await processedAuctionsRef.get(); | ||
|
||
return snapshot.docs.map((doc) => doc.data()); | ||
} | ||
|
||
export async function getAllPotentialCars() { | ||
console.log('::: get all potential cars :::'); | ||
const potentialCarsRef = db.collection('potentialCars'); | ||
const snapshot = await potentialCarsRef.get(); | ||
|
||
return snapshot.docs.map((doc) => doc.data()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.