Skip to content

Commit

Permalink
add settings to vscode in locally and add prop id in jobs
Browse files Browse the repository at this point in the history
- create new function to get id of job
- change types
- allow .vscode/settings in gitignore
- add dynamic head in collection thunder-client
  • Loading branch information
EdixonAlberto committed Mar 12, 2023
1 parent 3c96bab commit eeca560
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.husky/
.vscode/*
!.vscode/extensions
!.vscode/settings

# FILES
.env*
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"deno.enable": true,
"deno.unstable": false,
"deno.config": "./deno.json",
"deno.lint": true,
"deno.importMap": "./import_map.json"
}
12 changes: 3 additions & 9 deletions jobs-dev.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
],
"settings": {
"discord.enabled": true,
"deno.enable": true,
"deno.unstable": false,
"deno.config": "./deno.json",
"deno.lint": true,
"deno.importMap": "./import_map.json",
"deno.enablePaths": ["."],
"editor.formatOnSave": true,
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down Expand Up @@ -54,7 +48,7 @@
"runtimeArgs": [
"run",
"--config",
"./deno.jsonc",
"./deno.json",
"--inspect-wait",
"--allow-env",
"--allow-read",
Expand All @@ -64,15 +58,15 @@
},
{
"request": "launch",
"name": "Start Scraping",
"name": "Prepare DB",
"type": "node",
"program": "${workspaceFolder}/src/scraping/jobs.ts",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "/home/edixon/.deno/bin/deno",
"runtimeArgs": [
"run",
"--config",
"./deno.jsonc",
"./deno.json",
"--inspect-wait",
"--allow-env",
"--allow-read",
Expand Down
47 changes: 36 additions & 11 deletions src/scraping/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function getJobPartialList(jobsResultList: Cheerio<Element>, $: CheerioAPI): TJo
.hasClass('fa-money')

return {
id: generateIdfromUrl(url),
title,
role,
time,
Expand Down Expand Up @@ -170,21 +171,38 @@ function getJobDetails($: CheerioAPI): TJobDetails {
.children('.gb-rich-txt')
.has('ol').text() !== ''

const liList = isOl
? gbContainer
.children('div:nth-child(3)')
.children('.gb-rich-txt')
.children('ol')
.children('li')
: gbContainer
const isUl = gbContainer
.children('div:nth-child(3)')
.children('.gb-rich-txt')
.has('ul').text() !== ''

const isList = isOl || isUl
let language = 'spanish'
let requestList: string[] = []

if (isList) {
const liList = isOl
? gbContainer
.children('div:nth-child(3)')
.children('.gb-rich-txt')
.children('ol')
.children('li')
: gbContainer
.children('div:nth-child(3)')
.children('.gb-rich-txt')
.children('ul')
.children('li')

requestList = liList.map((_i, el) => $(el).text()).toArray()
} else {
const paragraphs = gbContainer
.children('div:nth-child(3)')
.children('.gb-rich-txt')
.children('ul')
.children('li')
.children('p')

const requestList = liList.map((_i, el) => $(el).text()).toArray()
requestList = paragraphs.html()?.split('<br>') || [paragraphs.text()]
}

let language = 'spanish'
for (const request of requestList) {
const hasEnglish: boolean = request.toLowerCase().search(/english|inglés/) > -1
if (hasEnglish) {
Expand All @@ -210,4 +228,11 @@ function getJobDetails($: CheerioAPI): TJobDetails {
}
}

function generateIdfromUrl(url: string): string {
const name = url.split('/').pop() as string
const text = btoa(name)
const id = text.substring(0, (text.length / 2) - 1)
return id
}

scrapeJobs()
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface IJob extends TJobPartial {
}

export type TJobPartial = {
id: string
title: string
role: string
time: string
Expand Down
5 changes: 2 additions & 3 deletions thunder-tests/thunderclient.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
"method": "GET",
"sortNum": 10000,
"created": "2023-01-07T22:54:29.601Z",
"modified": "2023-02-15T02:51:00.817Z",
"modified": "2023-03-07T16:09:43.207Z",
"headers": [
{
"name": "Origin",
"value": "http://localhost:8000",
"isDisabled": true
"value": "{{WHITE_LIST}}"
}
],
"params": [],
Expand Down

0 comments on commit eeca560

Please sign in to comment.