changeset 1:a2da81d3378b draft

removing dependency
author estrain
date Thu, 18 Jan 2024 03:08:40 +0000
parents 56271dcbc91c
children 1930c02df64e
files data_manager_mlst/data_manager/data_manager_mlst.py
diffstat 1 files changed, 13 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/data_manager_mlst/data_manager/data_manager_mlst.py	Thu Jan 18 02:22:30 2024 +0000
+++ b/data_manager_mlst/data_manager/data_manager_mlst.py	Thu Jan 18 03:08:40 2024 +0000
@@ -4,7 +4,8 @@
 import json
 import argparse
 import datetime
-import requests
+import sys
+from urllib.request import urlopen
 
 def download_pubmlst_databases():
     """Download databases from pubmlst."""
@@ -16,7 +17,6 @@
 
 def make_blast_database(output_directory):
     """Create a BLAST database from downloaded data."""
-    #dir_path = os.path.dirname(os.path.realpath(__file__))
     dir_path = os.getcwd()
     mlst_dir = os.path.join(dir_path, "pubmlst")
     output_directory = os.path.abspath(output_directory)
@@ -81,23 +81,21 @@
     download_pubmlst_databases()
     make_blast_database(output_directory)
 
-    
     url = 'https://raw.githubusercontent.com/tseemann/mlst/master/db/scheme_species_map.tab'
 
-    # Send a GET request to the URL
-    response = requests.get(url)
-
-    # Check if the request was successful
-    if response.status_code == 200:
-      with open('scheme_species_map.tab', 'w') as file:
-        file.write(response.text)
-      print("File downloaded successfully")
-    else:
-      print("Failed to retrieve the file")
+    # Use urllib to send a GET request to the URL
+    try:
+        with urlopen(url) as response:
+            response_content = response.read().decode('utf-8')
+            with open('scheme_species_map.tab', 'w') as file:
+                file.write(response_content)
+            print("File downloaded successfully")
+    except Exception as e:
+        print(f"Failed to retrieve the file: {e}")
 
     stab = "scheme_species_map.tab"
-    shutil.copy(stab,output_directory) 
- 
+    shutil.copy(stab,output_directory)
+
     datetime_str = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
     tablename = f"mlst_database_{datetime_str}"
 
@@ -105,4 +103,3 @@
 
 if __name__ == "__main__":
     main()
-