Mercurial > repos > jay > gaiac_violin_plot
comparison gaiac_pm_data_pulling/datapulling.py @ 1:a555581f014b draft
planemo upload for repository https://github.com/jaidevjoshi83/gaiac.git commit a733fec1915a1f6cf5f07092dc33426f765b6cb3-dirty
| author | jay |
|---|---|
| date | Thu, 15 May 2025 22:51:53 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:abfc2c9779d6 | 1:a555581f014b |
|---|---|
| 1 import requests | |
| 2 import sys | |
| 3 | |
| 4 def download_files_from_server(urls): | |
| 5 """ | |
| 6 Function to download files from a FastAPI server. | |
| 7 | |
| 8 Args: | |
| 9 ip (str): The IP address of the FastAPI server. | |
| 10 file_names (list): List of file names to download. | |
| 11 | |
| 12 Returns: | |
| 13 None | |
| 14 """ | |
| 15 for url in urls: | |
| 16 file_name = url.split('/')[len(url.split('/'))-1] | |
| 17 response = requests.get(url) | |
| 18 if response.status_code == 200: | |
| 19 with open(f"{file_name}", "wb") as f: | |
| 20 f.write(response.content) | |
| 21 print(f"File {file_name} downloaded successfully!") | |
| 22 else: | |
| 23 print(f"Failed to download {file_name}. Status code: {response.status_code}") | |
| 24 | |
| 25 if __name__=="__main__": | |
| 26 | |
| 27 if len(sys.argv) > 1: | |
| 28 files = sys.argv[1].split(',') | |
| 29 download_files_from_server( files) |
