Reputation: 35
I need to download and install Java JDK on various systems using python code. I used the Wget module however, I don't know the directory of the downloaded file, hence there is no result
import platform
import requests
import wget
url_windows='https://download.oracle.com/otn-pub/java/jdk/13.0.1+9/cec27d702aa74d5a8630c65ae61e4305/jdk-13.0.1_windows-x64_bin.exe'
url_mac='https://download.oracle.com/otn-pub/java/jdk/13.0.1+9/cec27d702aa74d5a8630c65ae61e4305/jdk-13.0.1_osx-x64_bin.dmg'
url_linux='https://download.oracle.com/otn-pub/java/jdk/13.0.1+9/cec27d702aa74d5a8630c65ae61e4305/jdk-13.0.1_linux-x64_bin.deb'
if platform.system == 'Windows':
wget.download(url_windows)
if platform.system == 'Linux':
wget.download(url_linux)
if platform.system == 'Mac':
wget.download(url_mac)
what can I do?
Upvotes: 1
Views: 211
Reputation: 765
platform.system
is a function, you should call it to compare it's return value with string, so use platform.system()
instead. For now you are not using wget
anywhere in your code actually because all comparations failed.
Upvotes: 2
Reputation: 29670
By default, it is downloaded in the current directory where you run it.
See help(wget.download)
:
Help on function download in module wget:
download(url, out=None, bar=<function bar_adaptive at 0x100ddcdd0>)
High level function, which downloads URL into tmp file in current
directory and then renames it to filename autodetected from either URL
or HTTP headers.
:param bar: function to track download progress (visualize etc.)
:param out: output filename or directory
:return: filename where URL is downloaded to
It returns the filename of the downloaded file, so you can use os.path.abspath
to get the full path:
>>> import os
>>> import wget
>>> f = wget.download("https://download.oracle.com/otn-pub/java/jdk/13.0.1+9/cec27d702aa74d5a8630c65ae61e4305/jdk-13.0.1_osx-x64_bin.dmg")
100% [................................................................................] 5307 / 5307>>>
>>> f
'jdk-13.0.1_osx-x64_bin.dmg'
>>> os.path.abspath(f)
'/Users/gino/jdk-13.0.1_osx-x64_bin.dmg'
>>>
The function also accepts an out
parameter so that you can explicitly set the download path.
As a side note, as mentioned by @CrazyElf's answer, you should be using platform.system()
to get the string names of the OS ("Windows", "Darwin", etc.) and not platform.system
which is a function:
>>> import platform
>>> platform.system
<function system at 0x100f19170>
>>> platform.system()
'Darwin'
(Notice that it returns "Darwin" on a Mac and not "Mac".)
Upvotes: 2