mirror of
https://github.com/obskyr/khinsider.git
synced 2025-08-12 16:04:03 +02:00
📄👷 Automatically installs required modules.
I figure it's easier and more convenient this way. Updated readme to inform a bit more about required modules, too.
This commit is contained in:
49
khinsider.py
49
khinsider.py
@@ -3,6 +3,55 @@
|
|||||||
|
|
||||||
# A script to download full soundtracks from khinsider.
|
# A script to download full soundtracks from khinsider.
|
||||||
|
|
||||||
|
# --- Install prerequisites---
|
||||||
|
|
||||||
|
# (This section in `if __name__ == '__main__':` is entirely unrelated to the
|
||||||
|
# rest of the module, and doesn't even run if the module isn't run by itself.)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import imp # To check modules without importing them.
|
||||||
|
|
||||||
|
requiredModules = [
|
||||||
|
['requests', 'requests'], # Some modules don't have the same pypi name as
|
||||||
|
['bs4', 'beautifulsoup4'] # import name. Therefore, two entries per module.
|
||||||
|
]
|
||||||
|
|
||||||
|
def moduleExists(module):
|
||||||
|
try:
|
||||||
|
imp.find_module(module[0])
|
||||||
|
except ImportError:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
def neededInstalls(requiredModules=requiredModules):
|
||||||
|
uninstalledModules = []
|
||||||
|
for module in requiredModules:
|
||||||
|
if not moduleExists(module):
|
||||||
|
uninstalledModules.append(module)
|
||||||
|
return uninstalledModules
|
||||||
|
|
||||||
|
def install(package):
|
||||||
|
pip.main(['install', '--quiet', package])
|
||||||
|
def installModules(modules, verbose=True):
|
||||||
|
for module in modules:
|
||||||
|
if verbose:
|
||||||
|
print "Installing " + module[1] + "..."
|
||||||
|
install(module[1])
|
||||||
|
def installRequiredModules(needed=None, verbose=True):
|
||||||
|
needed = neededInstalls() if needed is None else needed
|
||||||
|
installModules(neededInstalls(), verbose)
|
||||||
|
|
||||||
|
needed = neededInstalls()
|
||||||
|
if needed: # Only import pip if modules are actually missing.
|
||||||
|
try:
|
||||||
|
import pip # To install modules if they're not there.
|
||||||
|
except ImportError:
|
||||||
|
print "You don't seem to have pip installed!"
|
||||||
|
print "Get it from https://pip.readthedocs.org/en/latest/installing.html"
|
||||||
|
|
||||||
|
installRequiredModules(needed)
|
||||||
|
|
||||||
|
# ------
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
@@ -18,9 +18,15 @@ Carefully put together by [@obskyr](http://twitter.com/obskyr)!
|
|||||||
## Usage
|
## Usage
|
||||||
Just run `khinsider.py` from the command line with the sole parameter being the soundtrack you want to download. Easy!
|
Just run `khinsider.py` from the command line with the sole parameter being the soundtrack you want to download. Easy!
|
||||||
|
|
||||||
You're going to need [Python 2](https://www.python.org/downloads/), so install that (and [add it to your path](http://superuser.com/a/143121)) if you haven't already. Download for `khinsider.py` is on the right of this GitHub page - click "Download ZIP"!
|
You're going to need [Python 2](https://www.python.org/downloads/), so install that (and [add it to your path](http://superuser.com/a/143121)) if you haven't already.
|
||||||
|
|
||||||
|
You will also need to have [pip](https://pip.readthedocs.org/en/latest/installing.html) installed (download `get-pip.py` and run it) if you don't already have [requests](https://pypi.python.org/pypi/requests) and [Beautiful Soup 4](https://pypi.python.org/pypi/beautifulsoup4). The first time `khinsider.py` runs, it will install these two for you.
|
||||||
|
|
||||||
|
Download for `khinsider.py` is on the right of this GitHub page - click "Download ZIP"!
|
||||||
|
|
||||||
## As a module
|
## As a module
|
||||||
|
`khinsider.py` requires two non-standard modules: [requests](https://pypi.python.org/pypi/requests) and [beautifulsoup4](https://pypi.python.org/pypi/beautifulsoup4). Just run a `pip install` on them (with [pip](https://pip.readthedocs.org/en/latest/installing.html)), or just run `khinsider.py` on its own once and it'll install them for you.
|
||||||
|
|
||||||
Here are the functions you will be using:
|
Here are the functions you will be using:
|
||||||
|
|
||||||
###`khinsider.download(soundtrackName[, path="", verbose=False])`
|
###`khinsider.download(soundtrackName[, path="", verbose=False])`
|
||||||
|
Reference in New Issue
Block a user