|
8 | 8 | import string
|
9 | 9 | import requests
|
10 | 10 | import warnings
|
| 11 | +import json |
| 12 | +import time |
11 | 13 |
|
12 | 14 | from pkg_resources import resource_filename
|
13 | 15 | from bs4 import BeautifulSoup
|
@@ -333,4 +335,96 @@ def query_async(self, payload, *, get_query_payload=False,
|
333 | 335 | return result
|
334 | 336 |
|
335 | 337 |
|
| 338 | + def _get_data(self, solr_id, email=None): |
| 339 | + """ |
| 340 | + Defining this as a private function for now because it's using an |
| 341 | + unverified API |
| 342 | + """ |
| 343 | + url = f'{self.archive_url}/portal/#/subscanViewer/{solr_id}' |
| 344 | + |
| 345 | + #self._session.headers['User-Agent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" |
| 346 | + |
| 347 | + resp = self._request('GET', url, cache=False) |
| 348 | + resp.raise_for_status() |
| 349 | + |
| 350 | + eb_deets = self._request('GET', |
| 351 | + 'https://data.nrao.edu/archive-service/restapi_get_full_exec_block_details', |
| 352 | + params={'solr_id': solr_id}, |
| 353 | + cache=False |
| 354 | + ) |
| 355 | + eb_deets.raise_for_status() |
| 356 | + assert len(self._session.cookies) > 0 |
| 357 | + |
| 358 | + resp1b = self._request('GET', |
| 359 | + 'https://data.nrao.edu/archive-service/restapi_spw_details_view', |
| 360 | + params={'exec_block_id': solr_id.split(":")[-1]}, |
| 361 | + cache=False |
| 362 | + ) |
| 363 | + resp1b.raise_for_status() |
| 364 | + |
| 365 | + # returned data is doubly json-encoded |
| 366 | + jd = json.loads(eb_deets.json()) |
| 367 | + locator = jd['curr_eb']['sci_prod_locator'] |
| 368 | + project_code = jd['curr_eb']['project_code'] |
| 369 | + |
| 370 | + instrument = ('VLBA' if 'vlba' in solr_id.lower() else |
| 371 | + 'VLA' if 'vla' in solr_id.lower() else |
| 372 | + 'GBT' if 'gbt' in solr_id.lower() else None) |
| 373 | + if instrument is None: |
| 374 | + raise ValueError("Invalid instrument") |
| 375 | + |
| 376 | + post_data = { |
| 377 | + "emailNotification": email, |
| 378 | + "requestDescription": f"{instrument} Download Request", |
| 379 | + "archive": "VLA", |
| 380 | + "p_telescope": instrument, |
| 381 | + "p_project": project_code, |
| 382 | + "productLocator": locator, |
| 383 | + "requestCommand": "startVlaPPIWorkflow", |
| 384 | + "p_workflowEventName": "runDownloadWorkflow", |
| 385 | + "p_downloadDataFormat": f"{instrument}Raw", |
| 386 | + "p_intentsFileName": "intents_hifv.xml", |
| 387 | + "p_proceduresFileName": "procedure_hifv.xml" |
| 388 | + } |
| 389 | + |
| 390 | + presp = self._request('POST', |
| 391 | + 'https://data.nrao.edu/rh/submission', |
| 392 | + data=post_data, |
| 393 | + cache=False |
| 394 | + ) |
| 395 | + presp.raise_for_status() |
| 396 | + |
| 397 | + # DEBUG print(f"presp.url: {presp.url}") |
| 398 | + # DEBUG print(f"cookies: {self._session.cookies}") |
| 399 | + resp2 = self._request('GET', presp.url, cache=False) |
| 400 | + resp2.raise_for_status() |
| 401 | + |
| 402 | + for row in resp2.text.split(): |
| 403 | + if 'window.location.href=' in row: |
| 404 | + subrespurl = row.split("'")[1] |
| 405 | + |
| 406 | + # DEBUG print(f"subrespurl: {subrespurl}") |
| 407 | + # DEBUG print(f"cookies: {self._session.cookies}") |
| 408 | + nextresp = self._request('GET', subrespurl, cache=False) |
| 409 | + wait_url = nextresp.url |
| 410 | + nextresp.raise_for_status() |
| 411 | + |
| 412 | + if 'https://data.nrao.edu/rh/requests/' not in wait_url: |
| 413 | + raise ValueError(f"Got wrong URL from post request: {wait_url}") |
| 414 | + |
| 415 | + not_done = True |
| 416 | + while not_done: |
| 417 | + time.sleep(1) |
| 418 | + print(".", end='') |
| 419 | + resp = self._request('GET', wait_url, cache=False) |
| 420 | + resp.raise_for_status() |
| 421 | + if 'INPROGRESS' in resp.text: |
| 422 | + continue |
| 423 | + elif 'REQUEST COMPLETED' in resp.text: |
| 424 | + not_done = False |
| 425 | + |
| 426 | + return resp |
| 427 | + |
| 428 | + |
| 429 | + |
336 | 430 | Nrao = NraoClass()
|
0 commit comments