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 { createParserError, createAppLogger } = require('./utils')
|
||||||
|
|
||||||
const parseHTMLString = (html, { verbose }) => {
|
const parseHTMLString = (html, { verbose }) => {
|
||||||
const dev = process.env.NODE_ENV === 'development'
|
const logger = verbose ?
|
||||||
const logger = createAppLogger({ dev })
|
createAppLogger({ dev: true }) :
|
||||||
|
null
|
||||||
if (!verbose) {
|
|
||||||
logger.transports.forEach((transport) => (transport.silent = true))
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const LDJSONEventData = parseUsingLDJSONData(html, { logger })
|
const LDJSONEventData = parseUsingLDJSONData(html, { logger })
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
const request = require('request')
|
const request = require('request')
|
||||||
|
|
||||||
const crawl = async (url, { logger }) => {
|
const crawl = async (url, { logger }) => {
|
||||||
logger.log({
|
if (logger) {
|
||||||
message: `Crawl started for url: ${url}`,
|
logger.log({
|
||||||
level: 'info',
|
message: `Crawl started for url: ${url}`,
|
||||||
service: 'parser',
|
level: 'info',
|
||||||
})
|
service: 'parser',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
request({
|
request({
|
||||||
url,
|
url,
|
||||||
|
|
|
@ -37,11 +37,14 @@ const createLocationData = (streetText, areaText) => {
|
||||||
// NOTE: Fallback parser
|
// NOTE: Fallback parser
|
||||||
// Attempt reading event data directly from DOM
|
// Attempt reading event data directly from DOM
|
||||||
const parseUsingDOM = (html, url, { logger }) => {
|
const parseUsingDOM = (html, url, { logger }) => {
|
||||||
logger.log({
|
if (logger) {
|
||||||
message: 'Using fallback DOM parser',
|
logger.log({
|
||||||
level: 'info',
|
message: 'Using fallback DOM parser',
|
||||||
service: 'parser',
|
level: 'info',
|
||||||
})
|
service: 'parser',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const $ = cheerio.load(html)
|
const $ = cheerio.load(html)
|
||||||
const title = $('title').text()
|
const title = $('title').text()
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,14 @@ const parseEventData = (eventData) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseUsingLDJSONData = (html, { logger }) => {
|
const parseUsingLDJSONData = (html, { logger }) => {
|
||||||
logger.log({
|
if (logger) {
|
||||||
message: 'Parsing using LDJSON parser',
|
logger.log({
|
||||||
level: 'info',
|
message: 'Parsing using LDJSON parser',
|
||||||
service: 'parser',
|
level: 'info',
|
||||||
})
|
service: 'parser',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// NOTE: Mobile web should have serialized
|
// NOTE: Mobile web should have serialized
|
||||||
// event info in one of the script tags
|
// event info in one of the script tags
|
||||||
|
|
Loading…
Reference in New Issue