Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions sofa_deriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def download_sofa(url=None, dlloc='.', verbose=True):
from six.moves.urllib.request import urlretrieve

if url is None:
url = _find_sofa_url_on_web_page()
url = "https://www.iausofa.org/s/sofa_c-20231011tar.gz"

fn = url.split('/')[-1]
if not os.path.isdir(dlloc):
Expand All @@ -396,41 +396,6 @@ def download_sofa(url=None, dlloc='.', verbose=True):
return retfn


def _find_sofa_url_on_web_page(url='http://www.iausofa.org/current_C.html'):
"""
Finds and returns the download URL for the latest C SOFA.
"""
from urllib.request import urlopen
from html.parser import HTMLParser

# Create a subclass to override the handler methods.
class SOFAParser(HTMLParser):
def __init__(self):
self.matched_urls = []
super().__init__()

def handle_starttag(self, tag, attrs):
if tag == 'a' and attrs[-1][-1].endswith('.tar.gz'):
self.matched_urls.append(attrs[-1][-1])

parser = SOFAParser()
u = urlopen(url)
try:
for ln in u:
parser.feed(ln.decode())
finally:
u.close()

baseurl = '/'.join(url.split('/')[:-1])
fullurls = [(baseurl + m) for m in parser.matched_urls]

if len(fullurls) != 1:
raise ValueError('Found *multiple* possible downloads: ' +
str(fullurls))

return fullurls[0]


if __name__ == '__main__':
import glob
import tarfile
Expand Down