-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrape_dexcom.py
101 lines (71 loc) · 3.56 KB
/
scrape_dexcom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from config import credentials, rider_mapping, DATA_PATH
import pyderman as dr
from selenium import webdriver
import pandas as pd
import time
path = DATA_PATH+'Dexcom/'
dates = pd.date_range(start='01-01-2014', end='31-12-2021', freq='90D')
athletes = pd.read_csv(path+'dexcom_id.csv', index_col=0, dtype={'US':object, 'EU':object}) # beadle missing
# ------------------------ Dexcom CLARITY US
url_login = 'https://clarity.dexcom.com/professional/'
download_path = path+'export/US/'
driver_path = dr.install(browser=dr.chrome, file_directory='./lib/', verbose=True, chmod=True,
overwrite=False, version='96.0.4664.45', filename=None, return_info=False)
options = webdriver.ChromeOptions()
options.add_experimental_option("prefs", {"download.default_directory":download_path})
driver = webdriver.Chrome(driver_path, options=options)
driver.maximize_window()
driver.get(url_login)
# login
driver.find_element_by_name('username').send_keys(credentials['dexcom']['US']['username'])
driver.find_element_by_name('password').send_keys(credentials['dexcom']['US']['password'])
driver.find_element_by_class_name('btn-sm').click()
time.sleep(5)
for d in range(len(dates)-1):
start_date = dates[d]
end_date = dates[d+1] - pd.to_timedelta('1D')
for name, pid in athletes['US'].dropna().items():
# this is alternative to typing in name in search bar
driver.get(url_login+'patients/'+pid+'/export')
time.sleep(20)
# select date
driver.find_element_by_css_selector('date-range-picker').click()
driver.find_element_by_name('start_date').clear()
driver.find_element_by_name('end_date').clear()
driver.find_element_by_name('start_date').send_keys(start_date.strftime('%m/%d/%Y'))
driver.find_element_by_name('end_date').send_keys(end_date.strftime('%m/%d/%Y'))
driver.find_element_by_class_name('ok').click()
# export file
driver.find_element_by_name('submitExport').click()
driver.close()
# ------------------------ Dexcom CLARITY EU
url_login = 'https://clarity.dexcom.eu/professional/'
download_path = path+'export/EU/'
driver_path = dr.install(browser=dr.chrome, file_directory='./lib/', verbose=True, chmod=True, overwrite=False, version='86.0.4240.22', filename=None, return_info=False)
options = webdriver.ChromeOptions()
options.add_experimental_option("prefs", {"download.default_directory":download_path})
driver = webdriver.Chrome(driver_path, options=options)
driver.maximize_window()
driver.get(url_login)
# login
driver.find_element_by_name('username').send_keys(credentials['dexcom']['EU']['username'])
driver.find_element_by_name('password').send_keys(credentials['dexcom']['EU']['password'])
driver.find_element_by_class_name('btn-sm').click()
time.sleep(5)
for d in range(len(dates)-1):
start_date = dates[d]
end_date = dates[d+1] - pd.to_timedelta('1D')
for name, pid in athletes['EU'].dropna().items():
# this is alternative to typing in name in search bar
driver.get(url_login+'patients/'+pid+'/export')
time.sleep(20)
# select date
driver.find_element_by_css_selector('date-range-picker').click()
driver.find_element_by_name('start_date').clear()
driver.find_element_by_name('end_date').clear()
driver.find_element_by_name('start_date').send_keys(start_date.strftime('%m/%d/%Y'))
driver.find_element_by_name('end_date').send_keys(end_date.strftime('%m/%d/%Y'))
driver.find_element_by_class_name('ok').click()
# export file
driver.find_element_by_name('submitExport').click()
driver.close()