scc_access/scc_access.py

changeset 40
8acea12976c4
parent 38
1b6786e9865d
child 45
6574da43a481
equal deleted inserted replaced
39:7f9605b75689 40:8acea12976c4
11 import os 11 import os
12 import re 12 import re
13 from io import BytesIO 13 from io import BytesIO
14 import sys 14 import sys
15 import time 15 import time
16 import urlparse 16
17 from zipfile import ZipFile 17 from zipfile import ZipFile
18 18
19 import yaml 19 import yaml
20 20
21 requests.packages.urllib3.disable_warnings() 21 requests.packages.urllib3.disable_warnings()
470 measurement_number = measurement_number + 1 470 measurement_number = measurement_number + 1
471 measurement_id = "%s%02i" % (base_id, measurement_number) 471 measurement_id = "%s%02i" % (base_id, measurement_number)
472 472
473 return measurement_id 473 return measurement_id
474 474
475 def get_ancillary(self, filename, file_type): 475 def get_ancillary(self, file_path, file_type):
476 """ 476 """
477 Try to get the ancillary file data from the SCC API. 477 Try to get the ancillary file data from the SCC API.
478 478
479 The result will always be an API object. If the file does not exist, the .exists property is set to False. 479 The result will always be an API object. If the file does not exist, the .exists property is set to False.
480 480
481 Parameters 481 Parameters
482 ---------- 482 ----------
483 filename : str 483 file_path : str
484 Filename of the uploaded file. 484 Path of the uploaded file.
485 file_type : str 485 file_type : str
486 Type of ancillary file. One of 'sounding', 'overlap', 'lidarratio'. 486 Type of ancillary file. One of 'sounding', 'overlap', 'lidarratio'.
487 487
488 Returns 488 Returns
489 : AncillaryFile 489 : AncillaryFile
490 The api object. 490 The api object.
491 """ 491 """
492 assert file_type in ['sounding', 'overlap', 'lidarratio'] 492 assert file_type in ['sounding', 'overlap', 'lidarratio']
493
494 filename = os.path.basename(file_path)
493 495
494 if file_type == 'sounding': 496 if file_type == 'sounding':
495 file_url = self.api_sounding_search_pattern.format(filename) 497 file_url = self.api_sounding_search_pattern.format(filename)
496 elif file_type == 'overlap': 498 elif file_type == 'overlap':
497 file_url = self.api_overlap_search_pattern.format(filename) 499 file_url = self.api_overlap_search_pattern.format(filename)

mercurial