Skip to content

Commit

Permalink
Add quantity, notice
Browse files Browse the repository at this point in the history
  • Loading branch information
TaYaKi71751 committed Jan 5, 2022
1 parent 22ef05e commit fa50004
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/Example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { config } from 'dotenv';
import { randomNumber } from './util/Random';
import { getVaccinesFromResponseBody } from './util/Response';
config();
console.log(standbyRequest);
async function followRedirect ({
res
}: {
Expand Down Expand Up @@ -61,7 +60,7 @@ async function vaccineQuantity () {
});
const filterAvailable:Function = function (r:any):any {
const _r = r;
_r.vaccine = _r.vaccines.filter((_: any) => (!_.disabled));
_r.vaccines = _r.vaccines.filter((_: any) => (!_.disabled));
return _r;
};
result = filterAvailable(result);
Expand Down
14 changes: 10 additions & 4 deletions src/util/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,30 @@ export function getVaccinesFromResponseBody ({
vaccines: any
} {
const infoCheerio: CheerioAPI = loadCheerio(body);
const vaccineInputs = infoCheerio('ul > li.radio_item > input');
const vaccines: any = ov(vaccineInputs).filter((_) =>
(typeof _.attribs != 'undefined')).map((vaccineInput): {
const vaccineRadioItems = infoCheerio('ul > li.radio_item');
const vaccines: any = ov(vaccineRadioItems).filter((_) =>
(typeof _.attribs != 'undefined')).map((vaccineRadioItem): {
[x: string]: string | {
[x: string]: string
}
} => {
const vaccineRadioItemCheerio = loadCheerio(vaccineRadioItem);
const vaccineInput = vaccineRadioItemCheerio('input')[0];
const vaccineInputAttribs = vaccineInput.attribs;
let vaccine: {
[x: string]: string
} = { '': '' };
const cd = vaccineInputAttribs['data-cd'];
const name = vaccineInputAttribs['data-name'];
const quantity = vaccineRadioItemCheerio('label > .num_box > .num').text().trim();
const notice = vaccineRadioItemCheerio('label > .num_box > .notice').text().trim();
const { disabled } = vaccineInputAttribs;
vaccine = {
cd,
name,
disabled
disabled,
quantity,
notice
};
console.log(vaccine);
return vaccine;
Expand Down

0 comments on commit fa50004

Please sign in to comment.