Skip to content

Commit

Permalink
added internet connectivity check for downloading files
Browse files Browse the repository at this point in the history
  • Loading branch information
rahil-makadia committed Sep 20, 2024
1 parent ffc8868 commit 83018e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions grss/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import time
import gzip
import requests

__all__ = [ 'default_kernel_path',
'grss_path',
Expand All @@ -11,6 +12,14 @@
grss_path = os.path.dirname(os.path.abspath(__file__))
default_kernel_path = f'{grss_path}/kernels/'

def _connected_to_internet(url='http://www.google.com/', timeout=5):
try:
_ = requests.head(url, timeout=timeout)
return True
except requests.ConnectionError:
print("No internet connection available.")
return False

def _download_ades_files(file):
"""
Download a text file of the observatory code info from the Minor Planet Center.
Expand Down Expand Up @@ -66,6 +75,10 @@ def initialize():
None : NoneType
None
"""
internet = _connected_to_internet()
if not internet:
print("Please connect to the internet to download/update the necessary data files.")
return None
# run the get_debiasing_data.py script
os.system(f'python {grss_path}/debias/get_debiasing_data.py')
# run the get_kernels.py script
Expand Down
2 changes: 1 addition & 1 deletion grss/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.0
4.3.1

0 comments on commit 83018e2

Please sign in to comment.