-
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.
Merge pull request #9 from surenpoghosian/package-json-script-modific…
…ation modify npm start logic
- Loading branch information
Showing
4 changed files
with
49 additions
and
45 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
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 |
---|---|---|
@@ -1,44 +1,4 @@ | ||
import { v4 as uuid } from 'uuid'; | ||
import ScrapersFactory from './ScrapersFactory'; | ||
import ScrapableFactory from './ScrapableFactory'; | ||
import PathBuilderFactory from './PathBuilderFactory'; | ||
import { ListAmCategory, ListAmGeolocation, PathBuilderVariant, ScrapeValidatorVariant } from "./configs/types"; | ||
import { ScrapeableVariant, ScraperType, ScrapeType } from "./configs/types"; | ||
import { ListAmBaseURL } from './configs/constants'; | ||
import { sleep } from "./utils/sleep"; | ||
import ScrapeValidatorFactory from './ScrapeValidatorFactory'; | ||
import getRandomInterval from './utils/getRandomInterval'; | ||
import Main from "./main"; | ||
|
||
class Main { | ||
run = async () => { | ||
const scraperFactory = ScrapersFactory; | ||
const scrapableFactory = ScrapableFactory; | ||
const pathBuilderFactory = PathBuilderFactory; | ||
const scrapeValidatorFactory = ScrapeValidatorFactory; | ||
|
||
const scraper = scraperFactory.createScraper(ScraperType.PUPPETTER); | ||
const validator = scrapeValidatorFactory.createScrapeValidator(ScrapeValidatorVariant.LISTAM); | ||
const scrapable = scrapableFactory.createScrapable(ScrapeableVariant.LISTAM, scraper, validator); | ||
const pathBuilder = pathBuilderFactory.createPathBuilder(PathBuilderVariant.LISTAM); | ||
|
||
pathBuilder.init('', ListAmCategory.ROOM_FOR_A_RENT); | ||
|
||
const scrapeId = uuid(); | ||
|
||
for (let i = 1; true; i++) { | ||
pathBuilder.reset(); | ||
pathBuilder.addPageNumber(i); | ||
pathBuilder.addGeolocation(ListAmGeolocation.YEREVAN); | ||
|
||
const finalPath = pathBuilder.build(); | ||
console.log(`${ListAmBaseURL}${finalPath}`); | ||
|
||
await scrapable.scrape(scrapeId, finalPath, ScrapeType.LIST); | ||
|
||
const sleepInterval = getRandomInterval(4000, 10000); | ||
await sleep(sleepInterval); | ||
} | ||
} | ||
}; | ||
|
||
export default Main; | ||
const main = new Main(); | ||
main.run(); |
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,44 @@ | ||
import { v4 as uuid } from 'uuid'; | ||
import ScrapersFactory from './ScrapersFactory'; | ||
import ScrapableFactory from './ScrapableFactory'; | ||
import PathBuilderFactory from './PathBuilderFactory'; | ||
import { ListAmCategory, ListAmGeolocation, PathBuilderVariant, ScrapeValidatorVariant } from "./configs/types"; | ||
import { ScrapeableVariant, ScraperType, ScrapeType } from "./configs/types"; | ||
import { ListAmBaseURL } from './configs/constants'; | ||
import { sleep } from "./utils/sleep"; | ||
import ScrapeValidatorFactory from './ScrapeValidatorFactory'; | ||
import getRandomInterval from './utils/getRandomInterval'; | ||
|
||
class Main { | ||
run = async () => { | ||
const scraperFactory = ScrapersFactory; | ||
const scrapableFactory = ScrapableFactory; | ||
const pathBuilderFactory = PathBuilderFactory; | ||
const scrapeValidatorFactory = ScrapeValidatorFactory; | ||
|
||
const scraper = scraperFactory.createScraper(ScraperType.PUPPETTER); | ||
const validator = scrapeValidatorFactory.createScrapeValidator(ScrapeValidatorVariant.LISTAM); | ||
const scrapable = scrapableFactory.createScrapable(ScrapeableVariant.LISTAM, scraper, validator); | ||
const pathBuilder = pathBuilderFactory.createPathBuilder(PathBuilderVariant.LISTAM); | ||
|
||
pathBuilder.init('', ListAmCategory.ROOM_FOR_A_RENT); | ||
|
||
const scrapeId = uuid(); | ||
|
||
for (let i = 1; true; i++) { | ||
pathBuilder.reset(); | ||
pathBuilder.addPageNumber(i); | ||
pathBuilder.addGeolocation(ListAmGeolocation.YEREVAN); | ||
|
||
const finalPath = pathBuilder.build(); | ||
console.log(`${ListAmBaseURL}${finalPath}`); | ||
|
||
await scrapable.scrape(scrapeId, finalPath, ScrapeType.LIST); | ||
|
||
const sleepInterval = getRandomInterval(4000, 10000); | ||
await sleep(sleepInterval); | ||
} | ||
} | ||
}; | ||
|
||
export default Main; |