From ed4e4b74859ce76e109e5a28a09cbdab6a913258 Mon Sep 17 00:00:00 2001 From: Virnaliz Cruz Date: Wed, 18 May 2022 16:38:29 -0400 Subject: [PATCH 1/2] Parse Python link from home page --- offlinedatasci/main.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/offlinedatasci/main.py b/offlinedatasci/main.py index daf2379..ef1ccfd 100644 --- a/offlinedatasci/main.py +++ b/offlinedatasci/main.py @@ -11,18 +11,6 @@ import pkg_resources import pypi_mirror -def get_ods_dir(directory=Path.home()): - """Get path to save downloads, create if it does not exist. - - Keyword arguments: - directory -- Path to save downloads (defaults to user home path) - """ - folder_path = Path(directory) - if not folder_path.is_dir(): - print("\nCreating ods folder in " + str(directory)) - Path.mkdir(folder_path, parents=True) - return str(folder_path) - def download_and_save_installer(latest_version_url, destination_path): """Download and save installer in user given path. @@ -99,7 +87,7 @@ def download_software(ods_dir,software): hrefcolnum=1 key="osver" elif software=="Python": - url = 'https://www.python.org/downloads/release/python-3104/' + url = get_python_link() download_table_num=0 oscolnum=1 hrefcolnum=0 @@ -160,6 +148,31 @@ def download_r_most_current_ver(url, ods_dir): print("****Downloading file: ", destination_path2) urllib.request.urlretrieve(download_path, destination_path2) break +def get_ods_dir(directory=Path.home()): + """Get path to save downloads, create if it does not exist. + + Keyword arguments: + directory -- Path to save downloads (defaults to user home path) + """ + folder_path = Path(directory) + if not folder_path.is_dir(): + print("\nCreating ods folder in " + str(directory)) + Path.mkdir(folder_path, parents=True) + return str(folder_path) + +def get_python_link (): + """Get download page from Python homepage.""" + url="https://www.python.org" + fp = urllib.request.urlopen(url) + web_content = fp.read() + soup = bs.BeautifulSoup(web_content, "html.parser") + w = soup.find("a", href=lambda href: href and "release" in href) + hrefurl=w["href"] + path1= url + hrefurl + return(path1) + + +get_python_link() def table_parse_version_info(row,oscolnum,hrefcolnum): """Parse and return software information from table. From e06cee35be118379ada77412ac085e339337efc4 Mon Sep 17 00:00:00 2001 From: Virnaliz Cruz Date: Thu, 19 May 2022 11:05:47 -0400 Subject: [PATCH 2/2] Improve variable names --- offlinedatasci/main.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/offlinedatasci/main.py b/offlinedatasci/main.py index ef1ccfd..4d342b2 100644 --- a/offlinedatasci/main.py +++ b/offlinedatasci/main.py @@ -87,7 +87,7 @@ def download_software(ods_dir,software): hrefcolnum=1 key="osver" elif software=="Python": - url = get_python_link() + url = get_python_download_page() download_table_num=0 oscolnum=1 hrefcolnum=0 @@ -128,7 +128,6 @@ def download_r_most_current_ver(url, ods_dir): urlfile = urllib.request.urlopen(url) for line in urlfile: decoded = line.decode("utf-8") - match = re.findall(version_regex, decoded) if (match): r_current_version = match @@ -160,19 +159,16 @@ def get_ods_dir(directory=Path.home()): Path.mkdir(folder_path, parents=True) return str(folder_path) -def get_python_link (): +def get_python_download_page(): """Get download page from Python homepage.""" - url="https://www.python.org" - fp = urllib.request.urlopen(url) + base_url="https://www.python.org" + fp = urllib.request.urlopen(base_url) web_content = fp.read() soup = bs.BeautifulSoup(web_content, "html.parser") - w = soup.find("a", href=lambda href: href and "release" in href) - hrefurl=w["href"] - path1= url + hrefurl - return(path1) - - -get_python_link() + release_a_tag = soup.find("a", href=lambda href: href and "release" in href) + current_release_path = release_a_tag["href"] + current_release_url = base_url + current_release_path + return(current_release_url) def table_parse_version_info(row,oscolnum,hrefcolnum): """Parse and return software information from table.