-
-
Save samueldy/f087e1c56f691280d2f02d7ce732053b to your computer and use it in GitHub Desktop.
Get latest Decent Sampler release tarball URL automatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Get latest Decentsampler release - Selenium" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import natsort\n", | |
"from selenium import webdriver\n", | |
"from selenium.common.exceptions import NoSuchElementException, WebDriverException" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Start a webdriver\n", | |
"try:\n", | |
" driver = webdriver.Firefox()\n", | |
"except (FileNotFoundError, WebDriverException):\n", | |
" driver = webdriver.Firefox(\n", | |
" executable_path=os.path.expanduser(\n", | |
" r\"~/Miniconda3/envs/selenium/Scripts/geckodriver.exe\"\n", | |
" )\n", | |
" )" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Go to the webpage representing the Dropbox folder\n", | |
"DROPBOX_FOLDER_URL = (\n", | |
" \"https://www.dropbox.com/sh/dwyry6xpy5uut07/AABBJ84bjTTSQWzXGG5TOQpfa?dl=0\"\n", | |
")\n", | |
"\n", | |
"driver.get(DROPBOX_FOLDER_URL)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Now pick out all the links to the specific versions\n", | |
"cells = driver.find_elements_by_css_selector(css_selector=\"td.mc-table-cell\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def get_fname_and_link(cell):\n", | |
" \"\"\"\n", | |
" Easily get the filename and URL from a table cell.\n", | |
" \"\"\"\n", | |
"\n", | |
" try:\n", | |
" fname_wrapper = cell.find_element_by_css_selector(\n", | |
" css_selector=\"div.mc-media-cell-content > div.mc-media-cell-text\"\n", | |
" )\n", | |
" fname = fname_wrapper.text\n", | |
" link_wrapper = cell.find_element_by_css_selector(\"a\")\n", | |
" url = link_wrapper.get_attribute(\"href\")\n", | |
" return {\"name\": fname, \"url\": url}\n", | |
" except NoSuchElementException:\n", | |
" return None" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"file_listing = list(filter(lambda x: x, [get_fname_and_link(cell) for cell in cells]))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"most_recent_version = natsort.natsorted(seq=file_listing, key=lambda x: x[\"name\"])[-1]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"most_recent_version" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"driver.close()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python [conda env:selenium]", | |
"language": "python", | |
"name": "selenium" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then
most_recent_version
will look something like