Fetch
This module fetches the data from the web.
Overview
This module contains functions for fetching data from the open data portal or other sources.
It uses async requests if not using the open data portal to speed things up.
build_url(offset, base_url)
Build url for pagination.
Adds resultOffset and resultRecordCount to url.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset
|
int
|
int |
required |
base_url
|
str
|
str |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
url |
Source code in src/opendata_pipeline/fetch.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
cook_county_drug_col(df)
Create composite drug column for Cook County.
Source code in src/opendata_pipeline/fetch.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
export_drug_df(df, config)
Export drug dataframe to csv.
This is a temporary function to export a csv for the drug tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
Drug Output dataframe |
required |
config
|
DataSource
|
DataSource object |
required |
Source code in src/opendata_pipeline/fetch.py
116 117 118 119 120 121 122 123 124 125 126 127 |
|
export_jsonlines_from_df(df, config)
Export jsonlines from dataframe.
Source code in src/opendata_pipeline/fetch.py
130 131 132 133 134 |
|
get_async_records(config, current_index)
async
Get records from url.
This is an async function to get records from a url for each dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DataSource
|
DataSource object |
required |
current_index
|
int
|
int |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
newly updated index |
Source code in src/opendata_pipeline/fetch.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
get_open_data_records(config)
Get records from open data portal.
This is a synchronous request.
It sets the total to 1000 + the data source current total.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DataSource
|
DataSource object |
required |
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, typing.Any]]: list of records |
Source code in src/opendata_pipeline/fetch.py
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 |
|
get_pima_records(config)
Get records from Pima.
We use this function to load the locally saved Pima records.
Source code in src/opendata_pipeline/fetch.py
215 216 217 218 219 220 221 222 223 224 225 |
|
get_record_set(client, url)
async
Get record set from url.
An async function to get a record set from a url.
If fails, retries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
AsyncClient
|
httpx.AsyncClient |
required |
url
|
str
|
str |
required |
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, typing.Any]]: list of records |
Source code in src/opendata_pipeline/fetch.py
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 |
|
get_sacramento_records(config)
Get records from Sacramento.
We use this custom function since we are able to get the records directly via a URL, but we need to parse the structure after and the url is not in the open data portal format.
Source code in src/opendata_pipeline/fetch.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
get_sync_records(config, current_index)
Get records from url synchronously.
This is a synchronous function to get records from a url for each dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DataSource
|
DataSource object |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
newly updated index |
Source code in src/opendata_pipeline/fetch.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
make_df_with_identifier(records, current_index)
Make dataframe with case identifier.
Uses the current index to label records with a global identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records
|
list[dict[str, Any]]
|
list[dict[str, typing.Any]] |
required |
current_index
|
int
|
int |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: dataframe with case identifier |
Source code in src/opendata_pipeline/fetch.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
run(settings, update_remote=False)
async
Fetch records from open data portal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settings
|
Settings
|
Settings object |
required |
update_remote
|
bool
|
whether to update the remote config.json or not |
False
|
Source code in src/opendata_pipeline/fetch.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|