Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pagination and screener table scraping #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Upgrade packages, fix pagination and code generation
  • Loading branch information
david-schopf committed Mar 1, 2024
commit 3cfba1bd83398049c6bacc4c712dc1f53961434a
156 changes: 150 additions & 6 deletions docs/API.md

Large diffs are not rendered by default.

7,730 changes: 3,713 additions & 4,017 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@
"build": "npm run build:code && npm run build:types && npm run build:docs"
},
"dependencies": {
"axios": "^0.23.0",
"axios": "^1.6.7",
"axios-rate-limit": "^1.3.0",
"cheerio": "^1.0.0-rc.10"
"cheerio": "^1.0.0-rc.12"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"axios-mock-adapter": "^1.20.0",
"@types/jest": "^29.5.12",
"axios-mock-adapter": "^1.22.0",
"change-case": "^4.1.2",
"ejs": "^3.1.6",
"eslint": "^8.0.1",
"eslint-plugin-jsdoc": "^36.1.1",
"htmlparser2": "^7.1.2",
"jest": "^27.2.5",
"jsdoc": "^3.6.7",
"jsdoc-to-markdown": "^7.1.0",
"jsdoc-ts-utils": "^2.0.1",
"ejs": "^3.1.9",
"eslint": "^8.57.0",
"eslint-plugin-jsdoc": "^48.2.0",
"htmlparser2": "^9.1.0",
"jest": "^29.7.0",
"jsdoc": "^4.0.2",
"jsdoc-to-markdown": "^8.0.1",
"jsdoc-ts-utils": "^5.0.0",
"lodash": "^4.17.21"
}
}
31 changes: 21 additions & 10 deletions scripts/code/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const ejs = require('ejs')

/**
* Dump and die helper method
*
* @returns {void}
*/
const dd = function() { // eslint-disable-line
Expand All @@ -19,20 +18,32 @@ const dd = function() { // eslint-disable-line
}

// them files
const htmlCacheFile = path.resolve('scripts/cache/fvPage.cache.html')
const clientTmplFile = path.resolve('scripts/code/templates/client.ejs')
const clientOutFile = path.resolve('src/finviz.js')
const testsTmplFile = path.resolve('scripts/code/templates/tests.ejs')
const testsOutFile = path.resolve('tests/finviz.spec.js')
const htmlCacheFile = path.resolve(__dirname, '../../scripts/cache/fvPage.cache.html')
const clientTmplFile = path.resolve(__dirname, '../../scripts/code/templates/client.ejs')
const clientOutFile = path.resolve(__dirname, '../../src/finviz.js')
const testsTmplFile = path.resolve(__dirname, '../../scripts/code/templates/tests.ejs')
const testsOutFile = path.resolve(__dirname, '../../tests/finviz.spec.js')

/**
*
*/
async function getHtml() {
if (fs.existsSync(htmlCacheFile)) {
return fs.readFileSync(htmlCacheFile, { encoding: 'utf8' })
}

const { data } = await axios.get('https://finviz.com/screener.ashx?v=411&ft=4')
fs.writeFileSync(htmlCacheFile, data, { encoding: 'utf8' })
return data
try {
const { data } = await axios.get('https://finviz.com/screener.ashx?v=411&ft=4', {
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
}
})
fs.writeFileSync(htmlCacheFile, data, { encoding: 'utf8' })
return data
} catch (e) {
console.error(e)
process.exit(1)
}
}

void (async () => {
Expand All @@ -57,7 +68,7 @@ void (async () => {
const e = $(el)
return {
title: e.text(),
desc: e.prop('title').match(/<td class='tooltip_tab'>(.*)<\/td>/)[1],
desc: e.prop('data-boxover').match(/<td class='tooltip_tab'>(.*)<\/td>/)[1],
}
}).get()
$props.each((idx, el) => {
Expand Down
4 changes: 1 addition & 3 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ class FinVizScreener {

// find next page
const $nextPage = $('.screener_pagination').children().last()
nextPage = $nextPage.children().first().text().includes('next')
? $nextPage.prop('href')
: ''
nextPage = $nextPage.hasClass('is-next') ? $nextPage.prop('href') : ''
} while(nextPage && ! cancel)

return tickers
Expand Down
Loading