Filter available measurements for is_being_processed and is_queued parameters

Tue, 26 Sep 2023 16:56:35 +0200

author
Claudio Dema <claudio.dema@imaa.cnr.it>
date
Tue, 26 Sep 2023 16:56:35 +0200
changeset 70
4ef6f2102a61
parent 69
cd8bc07f8419
child 71
bf545d90784d

Filter available measurements for is_being_processed and is_queued parameters

.hgignore file | annotate | diff | comparison | revisions
scc_access/scc_access.py file | annotate | diff | comparison | revisions
--- a/.hgignore	Wed Sep 28 11:10:08 2022 +0200
+++ b/.hgignore	Tue Sep 26 16:56:35 2023 +0200
@@ -8,4 +8,5 @@
 re:^\.pytest_cache/
 dist/
 settings.yaml
+venv
 
--- a/scc_access/scc_access.py	Wed Sep 28 11:10:08 2022 +0200
+++ b/scc_access/scc_access.py	Tue Sep 26 16:56:35 2023 +0200
@@ -498,7 +498,7 @@
         return measurement
 
     def download_products(self, measurement, dir_name):
-        """ Download all the products of a measurement id (used only for E-SHAPE"""
+        """ Download all the products of a measurement id (used only for E-SHAPE)"""
         measurement_id = measurement.id
         base_output_dir = self.output_dir
         self.output_dir = self.output_dir + dir_name + "/"
@@ -616,7 +616,7 @@
         logger.info("Deleted measurement {0}".format(measurement_id))
         return True
 
-    def available_measurements(self, start_gte=None, stop_lte=None):
+    def available_measurements(self, start_gte=None, stop_lte=None, is_being_processed=None, is_queued=None):
         """ Get a list of available measurement on the SCC.
 
         The methods is currently not used, could be merged with list_measurements.
@@ -627,6 +627,11 @@
             params['start__gte'] = start_gte
         if stop_lte is not None:
             params['stop__lte'] = stop_lte
+        if is_being_processed is not None:
+            params['is_being_processed'] = is_being_processed
+        if is_queued is not None:
+            params['is_queued'] = is_queued
+
 
         response = self.session.get(self.api_measurements_url, params=params)
         response_dict = response.json()
@@ -1012,6 +1017,23 @@
                 scc.logout()
 
 
+def automatic_upload(settings):
+    date_time_start = datetime.datetime.now() - datetime.timedelta(days=1)
+    start_parameter = date_time_start.strftime("%Y-%m-%dT%H:%M:%S")
+    date_time_stop = datetime.datetime.now()
+    stop_parameter = date_time_stop.strftime("%Y-%m-%dT%H:%M:%S")
+
+    with SCC(settings['basic_credentials'], settings['output_dir'], settings['base_url']) as scc:
+        scc.login(settings['website_credentials'])
+
+        measurements = scc.available_measurements(start_gte=start_parameter, stop_lte=stop_parameter, is_queued=False, is_being_processed=False)
+        if measurements is not None:
+            for meas in measurements:
+                scc.download_products(meas, "")
+
+        scc.logout()
+
+
 def settings_from_path(config_file_path):
     """ Read the configuration file.
 
@@ -1155,6 +1177,13 @@
     parser.set_defaults(execute=run_eshape_downloader)
 
 
+def setup_automatic_upload(parser):
+    def run_automatic_upload(parsed):
+        automatic_upload(parsed.config)
+
+    parser.set_defaults(execute=run_automatic_upload)
+
+
 def main():
     # Define the command line arguments.
     parser = argparse.ArgumentParser()
@@ -1170,6 +1199,7 @@
     list_parser = subparsers.add_parser("list", help="List measurements registered on the SCC.")
     download_parser = subparsers.add_parser("download", help="Download selected measurements.")
     eshape_parser = subparsers.add_parser("eshape-downloader", help="Search and download relevant products for E-SHAPE.")
+    automatic_upload_parser = subparsers.add_parser("automatic-upload", help="Select and download products available for the upload to EARLINET db.")
 
     setup_delete(delete_parser)
     setup_rerun_all(rerun_all_parser)
@@ -1179,6 +1209,7 @@
     setup_list_measurements(list_parser)
     setup_download_measurements(download_parser)
     setup_eshape_downloader(eshape_parser)
+    setup_automatic_upload(automatic_upload_parser)
 
     # Verbosity settings from http://stackoverflow.com/a/20663028
     parser.add_argument('-d', '--debug', help="Print debugging information.", action="store_const",

mercurial