scc_access/scc_access.py

changeset 70
4ef6f2102a61
parent 69
cd8bc07f8419
child 71
bf545d90784d
equal deleted inserted replaced
69:cd8bc07f8419 70:4ef6f2102a61
496 logger.info("--- Processing finished. ---") 496 logger.info("--- Processing finished. ---")
497 497
498 return measurement 498 return measurement
499 499
500 def download_products(self, measurement, dir_name): 500 def download_products(self, measurement, dir_name):
501 """ Download all the products of a measurement id (used only for E-SHAPE""" 501 """ Download all the products of a measurement id (used only for E-SHAPE)"""
502 measurement_id = measurement.id 502 measurement_id = measurement.id
503 base_output_dir = self.output_dir 503 base_output_dir = self.output_dir
504 self.output_dir = self.output_dir + dir_name + "/" 504 self.output_dir = self.output_dir + dir_name + "/"
505 505
506 if measurement.hirelpp == 127: 506 if measurement.hirelpp == 127:
614 return None 614 return None
615 615
616 logger.info("Deleted measurement {0}".format(measurement_id)) 616 logger.info("Deleted measurement {0}".format(measurement_id))
617 return True 617 return True
618 618
619 def available_measurements(self, start_gte=None, stop_lte=None): 619 def available_measurements(self, start_gte=None, stop_lte=None, is_being_processed=None, is_queued=None):
620 """ Get a list of available measurement on the SCC. 620 """ Get a list of available measurement on the SCC.
621 621
622 The methods is currently not used, could be merged with list_measurements. 622 The methods is currently not used, could be merged with list_measurements.
623 """ 623 """
624 624
625 params = {} 625 params = {}
626 if start_gte is not None: 626 if start_gte is not None:
627 params['start__gte'] = start_gte 627 params['start__gte'] = start_gte
628 if stop_lte is not None: 628 if stop_lte is not None:
629 params['stop__lte'] = stop_lte 629 params['stop__lte'] = stop_lte
630 if is_being_processed is not None:
631 params['is_being_processed'] = is_being_processed
632 if is_queued is not None:
633 params['is_queued'] = is_queued
634
630 635
631 response = self.session.get(self.api_measurements_url, params=params) 636 response = self.session.get(self.api_measurements_url, params=params)
632 response_dict = response.json() 637 response_dict = response.json()
633 638
634 if response_dict: 639 if response_dict:
1010 scc.download_products(meas, dir_name) 1015 scc.download_products(meas, dir_name)
1011 1016
1012 scc.logout() 1017 scc.logout()
1013 1018
1014 1019
1020 def automatic_upload(settings):
1021 date_time_start = datetime.datetime.now() - datetime.timedelta(days=1)
1022 start_parameter = date_time_start.strftime("%Y-%m-%dT%H:%M:%S")
1023 date_time_stop = datetime.datetime.now()
1024 stop_parameter = date_time_stop.strftime("%Y-%m-%dT%H:%M:%S")
1025
1026 with SCC(settings['basic_credentials'], settings['output_dir'], settings['base_url']) as scc:
1027 scc.login(settings['website_credentials'])
1028
1029 measurements = scc.available_measurements(start_gte=start_parameter, stop_lte=stop_parameter, is_queued=False, is_being_processed=False)
1030 if measurements is not None:
1031 for meas in measurements:
1032 scc.download_products(meas, "")
1033
1034 scc.logout()
1035
1036
1015 def settings_from_path(config_file_path): 1037 def settings_from_path(config_file_path):
1016 """ Read the configuration file. 1038 """ Read the configuration file.
1017 1039
1018 The file should be in YAML syntax.""" 1040 The file should be in YAML syntax."""
1019 1041
1153 eshape_downloader(parsed.config) 1175 eshape_downloader(parsed.config)
1154 1176
1155 parser.set_defaults(execute=run_eshape_downloader) 1177 parser.set_defaults(execute=run_eshape_downloader)
1156 1178
1157 1179
1180 def setup_automatic_upload(parser):
1181 def run_automatic_upload(parsed):
1182 automatic_upload(parsed.config)
1183
1184 parser.set_defaults(execute=run_automatic_upload)
1185
1186
1158 def main(): 1187 def main():
1159 # Define the command line arguments. 1188 # Define the command line arguments.
1160 parser = argparse.ArgumentParser() 1189 parser = argparse.ArgumentParser()
1161 subparsers = parser.add_subparsers() 1190 subparsers = parser.add_subparsers()
1162 1191
1168 upload_file_parser = subparsers.add_parser("upload-file", 1197 upload_file_parser = subparsers.add_parser("upload-file",
1169 help="Submit a file and, optionally, download the output products.") 1198 help="Submit a file and, optionally, download the output products.")
1170 list_parser = subparsers.add_parser("list", help="List measurements registered on the SCC.") 1199 list_parser = subparsers.add_parser("list", help="List measurements registered on the SCC.")
1171 download_parser = subparsers.add_parser("download", help="Download selected measurements.") 1200 download_parser = subparsers.add_parser("download", help="Download selected measurements.")
1172 eshape_parser = subparsers.add_parser("eshape-downloader", help="Search and download relevant products for E-SHAPE.") 1201 eshape_parser = subparsers.add_parser("eshape-downloader", help="Search and download relevant products for E-SHAPE.")
1202 automatic_upload_parser = subparsers.add_parser("automatic-upload", help="Select and download products available for the upload to EARLINET db.")
1173 1203
1174 setup_delete(delete_parser) 1204 setup_delete(delete_parser)
1175 setup_rerun_all(rerun_all_parser) 1205 setup_rerun_all(rerun_all_parser)
1176 setup_rerun_elpp(rerun_processing_parser) 1206 setup_rerun_elpp(rerun_processing_parser)
1177 1207
1178 setup_upload_file(upload_file_parser) 1208 setup_upload_file(upload_file_parser)
1179 setup_list_measurements(list_parser) 1209 setup_list_measurements(list_parser)
1180 setup_download_measurements(download_parser) 1210 setup_download_measurements(download_parser)
1181 setup_eshape_downloader(eshape_parser) 1211 setup_eshape_downloader(eshape_parser)
1212 setup_automatic_upload(automatic_upload_parser)
1182 1213
1183 # Verbosity settings from http://stackoverflow.com/a/20663028 1214 # Verbosity settings from http://stackoverflow.com/a/20663028
1184 parser.add_argument('-d', '--debug', help="Print debugging information.", action="store_const", 1215 parser.add_argument('-d', '--debug', help="Print debugging information.", action="store_const",
1185 dest="loglevel", const=logging.DEBUG, default=logging.INFO, 1216 dest="loglevel", const=logging.DEBUG, default=logging.INFO,
1186 ) 1217 )

mercurial