utils
This module provides utility functions for the NMR FAIR DOs project.
fetch_data
async
¶
fetch_data(url: str, forceFresh: bool = False) -> dict
Fetches data from the specified URL. The data is cached in the CACHE_DIR. If the data is already cached, it is used instead of fetching fresh data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL to fetch data from |
required |
forceFresh |
bool
|
Whether to force fetching fresh data. This tells the function to ignore cached data. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The fetched data |
Raises:
Type | Description |
---|---|
ValueError
|
If the URL is invalid or the data cannot be fetched |
Source code in src/nmr_FAIR_DOs/utils.py
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 |
|
fetch_multiple
async
¶
fetch_multiple(
urls: list[str], forceFresh: bool = False
) -> list[dict]
Fetches data from multiple URLs. This function is a wrapper around fetch_data that fetches data from multiple URLs concurrently.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urls |
List[str]
|
A list of URLs to fetch data from |
required |
forceFresh |
bool
|
Whether to force fetching fresh data. This tells the function to ignore cached data. |
False
|
Returns:
Type | Description |
---|---|
list[dict]
|
List[dict]: A list of fetched data |
Raises:
Type | Description |
---|---|
ValueError
|
If the URLs are invalid or the data cannot be fetched |
Source code in src/nmr_FAIR_DOs/utils.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
encodeInBase64 ¶
encodeInBase64(data: str) -> str
Encodes the given data in Base64.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
str
|
The data to encode |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The Base64 encoded data |
Raises:
Type | Description |
---|---|
ValueError
|
If the data is None or empty |
Source code in src/nmr_FAIR_DOs/utils.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
decodeFromBase64 ¶
decodeFromBase64(data: str) -> str
Decodes the given Base64 encoded data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
str
|
The Base64 encoded data to decode |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The decoded data |
Raises:
Type | Description |
---|---|
ValueError
|
If the data is None or empty |
Source code in src/nmr_FAIR_DOs/utils.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
parseDateTime ¶
parseDateTime(text: str) -> datetime
Parses a datetime from an arbitrary string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The string to parse |
required |
Returns:
Name | Type | Description |
---|---|---|
datetime |
datetime
|
The parsed datetime |
Raises:
Type | Description |
---|---|
ValueError
|
If the text is None or empty or the datetime cannot be parsed |
Source code in src/nmr_FAIR_DOs/utils.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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
parseSPDXLicenseURL
async
¶
parseSPDXLicenseURL(input_str: str) -> str
This function takes a string input and searches for a matching SPDX license URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_str |
str
|
The input string to search for. This can be a license name, SPDX ID, URL, etc. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The SPDX license URL |
Source code in src/nmr_FAIR_DOs/utils.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 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 |
|
checkTextIsSimilar ¶
checkTextIsSimilar(
original: str, target: list[str] | str
) -> bool
Checks if the original text is similar to the target text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original |
str
|
The original text |
required |
target |
list[str] | str
|
The target text or a list of target texts |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Whether the original text is similar to the target text |
Source code in src/nmr_FAIR_DOs/utils.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|