diff gaiac_pm_data_pulling/datapulling.py @ 1:9d28091f26dd draft

planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit a733fec1915a1f6cf5f07092dc33426f765b6cb3-dirty
author jay
date Thu, 15 May 2025 22:50:33 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gaiac_pm_data_pulling/datapulling.py	Thu May 15 22:50:33 2025 +0000
@@ -0,0 +1,29 @@
+import requests
+import sys
+
+def download_files_from_server(urls):
+    """
+    Function to download files from a FastAPI server.
+
+    Args:
+        ip (str): The IP address of the FastAPI server.
+        file_names (list): List of file names to download.
+
+    Returns:
+        None
+    """
+    for url in urls:
+        file_name = url.split('/')[len(url.split('/'))-1]
+        response = requests.get(url)
+        if response.status_code == 200:
+            with open(f"{file_name}", "wb") as f:
+                f.write(response.content)
+            print(f"File {file_name} downloaded successfully!")
+        else:
+            print(f"Failed to download {file_name}. Status code: {response.status_code}")
+
+if __name__=="__main__":
+
+    if len(sys.argv) > 1:
+        files  = sys.argv[1].split(',')
+        download_files_from_server( files)
\ No newline at end of file