1
- import { v4 as uuid } from 'uuid' ;
2
- import ScrapersFactory from './ScrapersFactory' ;
3
- import ScrapableFactory from './ScrapableFactory' ;
4
- import PathBuilderFactory from './PathBuilderFactory' ;
5
- import { ListAmCategory , ListAmGeolocation , PathBuilderVariant , ScrapeValidatorVariant } from "./configs/types" ;
6
- import { ScrapeableVariant , ScraperType , ScrapeType } from "./configs/types" ;
7
- import { ListAmBaseURL } from './configs/constants' ;
8
- import { sleep } from "./utils/sleep" ;
9
- import ScrapeValidatorFactory from './ScrapeValidatorFactory' ;
10
- import getRandomInterval from './utils/getRandomInterval' ;
1
+ import Main from "./main" ;
11
2
12
- class Main {
13
- run = async ( ) => {
14
- const scraperFactory = ScrapersFactory ;
15
- const scrapableFactory = ScrapableFactory ;
16
- const pathBuilderFactory = PathBuilderFactory ;
17
- const scrapeValidatorFactory = ScrapeValidatorFactory ;
18
-
19
- const scraper = scraperFactory . createScraper ( ScraperType . PUPPETTER ) ;
20
- const validator = scrapeValidatorFactory . createScrapeValidator ( ScrapeValidatorVariant . LISTAM ) ;
21
- const scrapable = scrapableFactory . createScrapable ( ScrapeableVariant . LISTAM , scraper , validator ) ;
22
- const pathBuilder = pathBuilderFactory . createPathBuilder ( PathBuilderVariant . LISTAM ) ;
23
-
24
- pathBuilder . init ( '' , ListAmCategory . ROOM_FOR_A_RENT ) ;
25
-
26
- const scrapeId = uuid ( ) ;
27
-
28
- for ( let i = 1 ; true ; i ++ ) {
29
- pathBuilder . reset ( ) ;
30
- pathBuilder . addPageNumber ( i ) ;
31
- pathBuilder . addGeolocation ( ListAmGeolocation . YEREVAN ) ;
32
-
33
- const finalPath = pathBuilder . build ( ) ;
34
- console . log ( `${ ListAmBaseURL } ${ finalPath } ` ) ;
35
-
36
- await scrapable . scrape ( scrapeId , finalPath , ScrapeType . LIST ) ;
37
-
38
- const sleepInterval = getRandomInterval ( 4000 , 10000 ) ;
39
- await sleep ( sleepInterval ) ;
40
- }
41
- }
42
- } ;
43
-
44
- export default Main ;
3
+ const main = new Main ( ) ;
4
+ main . run ( ) ;
0 commit comments