Skip to content

Commit

Permalink
Fix Walgreens cookie issue. Add cities for CVS search
Browse files Browse the repository at this point in the history
  • Loading branch information
vanakema committed Mar 10, 2021
1 parent 84cf8ce commit 83f5393
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/sites/cvs.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import logger from '../utils/logger.js'
import { getInnerTexts } from '../utils/page.js'

const NAME = 'CVS'
const URL = 'https://www.cvs.com/immunizations/covid-19-vaccine'
const AVAILABLE_STATUS = 'Available'

// Selectors
const STATUS_SPANS = '.covid-updates span.status'

/*
* param {Puppeteer Page} page
* param {Object} search config with state abbreviation
* returns Promise<Boolean | null> - appointment availability
*/
const checker = async (page, { state }) => {
const checker = async (page, { state, cities }) => {
await page.goto(URL)

const stateLink = `a[data-modal='vaccineinfo-${state}']`
await page.click(stateLink)
const results = page.waitForResponse(`https://www.cvs.com/immunizations/covid-19-vaccine.vaccine-status.${state}.json?vaccineinfo`)
const click = page.click(stateLink)
const [finishedResults] = await Promise.all([results, click])
let resultsJson = await finishedResults.json();
let cityData = resultsJson['responsePayloadData'].data[`${state}`]
let availableCities = cityData.filter((cityObj) => cities.includes(cityObj.city) && cityObj.status === AVAILABLE_STATUS);
logger.log('Available Cities for CVS', availableCities);

try {
const innerTexts = await getInnerTexts(page, STATUS_SPANS)
return innerTexts.some(t => t === AVAILABLE_STATUS)
return availableCities.length > 0;
} catch (err) {
logger.error('CVS checker error:', err)
return null // status unknown
Expand Down
4 changes: 3 additions & 1 deletion src/sites/walgreens.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { hasInnertText } from '../utils/page.js'

const NAME = 'Walgreens'
const introURL = 'https://www.walgreens.com/findcare/vaccination/covid-19'
const URL = 'https://www.walgreens.com/findcare/vaccination/covid-19/location-screening'

const HAPPY_TEXT = 'Appointments available!'
Expand Down Expand Up @@ -45,6 +46,7 @@ const checkBanners = async (page) => {
* returns Promise<boolean> - appointment availability
*/
const checker = async (page, { zipCode }) => {
await page.goto(introURL)
await page.goto(URL)
const zipCodeInputField = await page.$(ZIP_CODE_INPUT_FIELD)

Expand All @@ -69,5 +71,5 @@ const checker = async (page, { zipCode }) => {
export default {
name: NAME,
checker,
url: URL,
url: introURL,
}

0 comments on commit 83f5393

Please sign in to comment.