From c6b833afa5dc661a9c3f13aa65518f80256c9079 Mon Sep 17 00:00:00 2001 From: "Chad.March" Date: Fri, 16 Oct 2020 15:02:58 -0700 Subject: [PATCH] Improved parsing * Added example --- example.js | 2 ++ index.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/example.js b/example.js index ce66818..e566e97 100644 --- a/example.js +++ b/example.js @@ -2,6 +2,8 @@ const terminalProcedures = require('./') terminalProcedures.fetchCurrentCycle().then(r => console.log(r)) +terminalProcedures.currentCycleEffectiveDates().then(console.log) + // Also try updateing the Flag property to include one or more of the following: // A for only those that were Added since the last effective date // C for only those that were Changed since the last effective date diff --git a/index.js b/index.js index 069d239..c16f9eb 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,9 @@ terminalProcedures.currentCycleEffectiveDates = async () => { .get(BASE_URL) .set('Accept', ACCEPT) - return extractEffectiveDates(cheerio.load(response.text)) + const $ = cheerio.load(response.text) + var currentCycle = $('select#cycle > option:contains(Current)').text() + return parseEffectiveDates(currentCycle.replace(/(\n|\t)/gm, '')) } /** @@ -213,7 +215,14 @@ const extractEffectiveDates = $ => { .split('<')[0] .trim() - const [ startMonthDay, remainder ] = baseEffectiveDateString.split('-') + return parseEffectiveDates(baseEffectiveDateString) +} + +const parseEffectiveDates = str => { + if (!str) { + return null + } + const [ startMonthDay, remainder ] = str.split('-') const [ endMonthDay, yearAndCycle ] = remainder.split(',') const [ year, _ ] = yearAndCycle.split('[') return {