Skip to content

Commit

Permalink
Improved parsing
Browse files Browse the repository at this point in the history
* Added example
  • Loading branch information
marchchad committed Oct 16, 2020
1 parent 6501f7c commit c6b833a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ''))
}

/**
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c6b833a

Please sign in to comment.