From ed3de6ee5d4bcf48840201ee9241d8c98bdc6f42 Mon Sep 17 00:00:00 2001 From: Micheal <86540880+MAYKELL07@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:57:11 +0000 Subject: [PATCH] Added Alodokter Scrape --- src/app.module.ts | 9 +++------ src/main.ts | 2 +- src/scraper/scraper.controller.ts | 5 +++++ src/scraper/scraper.service.ts | 11 +++++++++++ src/tasks/task.model.ts | 6 ------ src/tasks/tasks.controller.spec.ts | 18 ------------------ src/tasks/tasks.controller.ts | 23 ----------------------- src/tasks/tasks.module.ts | 4 ---- src/tasks/tasks.service.spec.ts | 18 ------------------ src/tasks/tasks.service.ts | 25 ------------------------- 10 files changed, 20 insertions(+), 101 deletions(-) delete mode 100644 src/tasks/task.model.ts delete mode 100644 src/tasks/tasks.controller.spec.ts delete mode 100644 src/tasks/tasks.controller.ts delete mode 100644 src/tasks/tasks.module.ts delete mode 100644 src/tasks/tasks.service.spec.ts delete mode 100644 src/tasks/tasks.service.ts diff --git a/src/app.module.ts b/src/app.module.ts index 6d359f4..65e5f45 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,16 +1,13 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; -import { TasksService } from './tasks/tasks.service'; -import { TasksModule } from './tasks/tasks.module'; -import { TasksController } from './tasks/tasks.controller'; import { ScraperService } from './scraper/scraper.service'; import { ScraperController } from './scraper/scraper.controller'; import { ScraperModule } from './scraper/scraper.module'; @Module({ - imports: [TasksModule, ScraperModule], - controllers: [AppController, TasksController, ScraperController], - providers: [AppService, TasksService, ScraperService], + imports: [ScraperModule], + controllers: [AppController, ScraperController], + providers: [AppService, ScraperService], }) export class AppModule {} diff --git a/src/main.ts b/src/main.ts index 13cad38..1a20e9a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,6 @@ import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); - await app.listen(3000); + await app.listen(3000) } bootstrap(); diff --git a/src/scraper/scraper.controller.ts b/src/scraper/scraper.controller.ts index 82f981a..2f64bac 100644 --- a/src/scraper/scraper.controller.ts +++ b/src/scraper/scraper.controller.ts @@ -12,4 +12,9 @@ export class ScraperController { ): Promise { return await this.scraperService.AI(prompt, AIName); } + + @Post('alodokter') + async scrapeAlodokter(@Body('inputText') inputText: string): Promise { + return await this.scraperService.scrapeAlodokter(inputText); + } } diff --git a/src/scraper/scraper.service.ts b/src/scraper/scraper.service.ts index 86ee7bd..3129c6d 100644 --- a/src/scraper/scraper.service.ts +++ b/src/scraper/scraper.service.ts @@ -40,4 +40,15 @@ export class ScraperService implements OnModuleInit, OnModuleDestroy { return responseText; } } + + async scrapeAlodokter(inputText: string): Promise { + const context = await this.browser.newContext(); + const page = await context.newPage(); + await page.goto('https://www.alodokter.com'); + await page.fill('#searchinput', inputText); + await page.click('div > div > div > a:nth-child(1)'); + const paragraphText = await page.textContent('#postContent > p:nth-child(1)'); + return paragraphText; + } + } diff --git a/src/tasks/task.model.ts b/src/tasks/task.model.ts deleted file mode 100644 index 870d714..0000000 --- a/src/tasks/task.model.ts +++ /dev/null @@ -1,6 +0,0 @@ -export class Task { - id: string; - title: string; - description: string; - done: boolean; -} diff --git a/src/tasks/tasks.controller.spec.ts b/src/tasks/tasks.controller.spec.ts deleted file mode 100644 index 09d9774..0000000 --- a/src/tasks/tasks.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { TasksController } from './tasks.controller'; - -describe('TasksController', () => { - let controller: TasksController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [TasksController], - }).compile(); - - controller = module.get(TasksController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/src/tasks/tasks.controller.ts b/src/tasks/tasks.controller.ts deleted file mode 100644 index 4d61d5a..0000000 --- a/src/tasks/tasks.controller.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Controller, Get, Post, Body } from '@nestjs/common'; -import { TasksService } from './tasks.service'; -import { Task } from './task.model'; - -@Controller('tasks') -export class TasksController { - constructor(private tasksService: TasksService) {} - - @Get() - getAllTasks(): Task[] { - return this.tasksService.getAllTasks(); - } - - @Post() - createTask( - @Body('title') title: string, - @Body('description') description: string, - ): Task { - return this.tasksService.createTask(title, description); - } - - // Implement other CRUD operations (update, delete) as needed -} diff --git a/src/tasks/tasks.module.ts b/src/tasks/tasks.module.ts deleted file mode 100644 index e4762c4..0000000 --- a/src/tasks/tasks.module.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Module } from '@nestjs/common'; - -@Module({}) -export class TasksModule {} diff --git a/src/tasks/tasks.service.spec.ts b/src/tasks/tasks.service.spec.ts deleted file mode 100644 index cb48230..0000000 --- a/src/tasks/tasks.service.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { TasksService } from './tasks.service'; - -describe('TasksService', () => { - let service: TasksService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [TasksService], - }).compile(); - - service = module.get(TasksService); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); -}); diff --git a/src/tasks/tasks.service.ts b/src/tasks/tasks.service.ts deleted file mode 100644 index 84a347e..0000000 --- a/src/tasks/tasks.service.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { Task } from './task.model'; - -@Injectable() -export class TasksService { - private tasks: Task[] = []; - - getAllTasks(): Task[] { - return this.tasks; - } - - createTask(title: string, description: string): Task { - const task: Task = { - id: new Date().toISOString(), - title, - description, - done: false, - }; - - this.tasks.push(task); - return task; - } - - // Implement other CRUD operations (update, delete) as needed -}