Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions airflow/dags/ashp/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from time import sleep

import requests
import cloudscraper
from bs4 import BeautifulSoup
import pandas as pd

Expand Down Expand Up @@ -45,11 +46,22 @@
def extract_load_shortage_list():
logging.basicConfig(level=logging.INFO, format='%(asctime)s : %(levelname)s : %(message)s')

# Use cloudscraper to bypass Cloudflare protection
scraper = cloudscraper.create_scraper(
browser={
'browser': 'chrome',
'platform': 'windows',
'mobile': False
}
)

logging.info('Checking ASHP website for updates')
shortage_list = requests.get(landing_url)
shortage_list = scraper.get(landing_url)

if shortage_list.status_code != 200:
logging.error('ASHP website unreachable')
logging.error(f'Status code: {shortage_list.status_code}')
logging.error(f'Response: {shortage_list.text}')
exit()

ashp_drugs = []
Expand All @@ -64,7 +76,7 @@ def extract_load_shortage_list():
available_ndcs = []

for shortage in ashp_drugs:
shortage_detail_data = requests.get(base_url + shortage['detail_url'])
shortage_detail_data = scraper.get(base_url + shortage['detail_url'])
soup = BeautifulSoup(shortage_detail_data.content, 'html.parser')

# Get shortage reasons
Expand Down
1 change: 1 addition & 0 deletions airflow/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ apache-airflow[google]
bs4
openpyxl
xlrd==1.2.0
cloudscraper