make logger optional so code can be re-used for CLI interface
This commit is contained in:
parent
bf36383bff
commit
59eb0191bf
|
@ -5,12 +5,9 @@ const parseUsingDOM = require('./services/dom-parser')
|
|||
const { createParserError, createAppLogger } = require('./utils')
|
||||
|
||||
const parseHTMLString = (html, { verbose }) => {
|
||||
const dev = process.env.NODE_ENV === 'development'
|
||||
const logger = createAppLogger({ dev })
|
||||
|
||||
if (!verbose) {
|
||||
logger.transports.forEach((transport) => (transport.silent = true))
|
||||
}
|
||||
const logger = verbose ?
|
||||
createAppLogger({ dev: true }) :
|
||||
null
|
||||
|
||||
try {
|
||||
const LDJSONEventData = parseUsingLDJSONData(html, { logger })
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
const request = require('request')
|
||||
|
||||
const crawl = async (url, { logger }) => {
|
||||
logger.log({
|
||||
message: `Crawl started for url: ${url}`,
|
||||
level: 'info',
|
||||
service: 'parser',
|
||||
})
|
||||
if (logger) {
|
||||
logger.log({
|
||||
message: `Crawl started for url: ${url}`,
|
||||
level: 'info',
|
||||
service: 'parser',
|
||||
})
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url,
|
||||
|
|
|
@ -37,11 +37,14 @@ const createLocationData = (streetText, areaText) => {
|
|||
// NOTE: Fallback parser
|
||||
// Attempt reading event data directly from DOM
|
||||
const parseUsingDOM = (html, url, { logger }) => {
|
||||
logger.log({
|
||||
message: 'Using fallback DOM parser',
|
||||
level: 'info',
|
||||
service: 'parser',
|
||||
})
|
||||
if (logger) {
|
||||
logger.log({
|
||||
message: 'Using fallback DOM parser',
|
||||
level: 'info',
|
||||
service: 'parser',
|
||||
})
|
||||
}
|
||||
|
||||
const $ = cheerio.load(html)
|
||||
const title = $('title').text()
|
||||
|
||||
|
|
|
@ -38,11 +38,14 @@ const parseEventData = (eventData) => {
|
|||
}
|
||||
|
||||
const parseUsingLDJSONData = (html, { logger }) => {
|
||||
logger.log({
|
||||
message: 'Parsing using LDJSON parser',
|
||||
level: 'info',
|
||||
service: 'parser',
|
||||
})
|
||||
if (logger) {
|
||||
logger.log({
|
||||
message: 'Parsing using LDJSON parser',
|
||||
level: 'info',
|
||||
service: 'parser',
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
// NOTE: Mobile web should have serialized
|
||||
// event info in one of the script tags
|
||||
|
|
Loading…
Reference in New Issue