Add a few options to HTTrack

This commit is contained in:
Alexis Métaireau 2016-06-21 15:47:15 +02:00
parent eee3447fd1
commit 6b10be5557
No known key found for this signature in database
GPG Key ID: 1EDF5A7A485D4A11
4 changed files with 40 additions and 12 deletions

View File

@ -46,13 +46,9 @@
</p>
</form>
<p>
This is a <a href="http://www.openzim.org/wiki/OpenZIM">Zim</a> creator. Enter the <em>url</em> of the website you want ton turn in a zim file, a <em>title</em> and the <em>language</em> and click on <em>Create zim File</em>
</p>
<p>
If needed, you can also add a description, the name of the origanl author
of the content and your email if you want to be notified when the zim is
ready. Enjoy !
This is a <a href="http://www.openzim.org/wiki/OpenZIM">Zim</a> creator. Enter the <em>url</em> of the website you want ton turn in a zim file, a <em>title</em> and click on <em>Create zim File</em>
</p>
<p>Enjoy !</p>
</div>
<script src="./assets/alertify.js"></script>
<script type="text/javascript">

View File

@ -23,12 +23,13 @@ class ZimCreator(object):
def __init__(self, zimwriterfs_bin, output_location,
author=DEFAULT_AUTHOR, httrack_bin=HTTRACK_BIN,
log_file=None):
log_file=None, max_download_speed=25000):
self.output_location = output_location
self.author = author
self.zimwriterfs_bin = zimwriterfs_bin
self.httrack_bin = httrack_bin
self.log_file = log_file
self.max_download_speed = max_download_speed
utils.ensure_paths_exists(
self.zimwriterfs_bin,
@ -48,8 +49,15 @@ class ZimCreator(object):
:param destination_path:
The absolute location of a folder where the files will be written.
"""
options = (self.httrack_bin, destination_path, url)
self._spawn("%s --path %s %s" % options)
options = {
"path": destination_path,
"max-rate": self.max_download_speed,
"keep-alive": None,
"robots": 0,
"near": None,
}
self._spawn(utils.get_command(self.httrack_bin, url, **options))
def prepare_website_folder(self, url, input_location):
"""Prepare the website files to make them ready to be embedded in a zim
@ -58,10 +66,11 @@ class ZimCreator(object):
:returns:
the absolute location of the website folder, ready to be embedded.
"""
netloc = urlparse.urlparse(url).netloc
netloc = urlparse.urlparse(url).netloc.replace(":", "_")
website_folder = os.path.join(input_location, netloc)
if not os.path.isdir(website_folder):
raise Exception("Unable to find the website folder!")
message = "Unable to find the website folder! %s" % website_folder
raise Exception(message)
shutil.copy('./favicon.ico', website_folder)
return website_folder

View File

@ -21,7 +21,18 @@ class ZimReadyMessage(Message):
def __init__(self, email, zim_link):
subject = "[ZimIt!] Your zimfile is ready!"
bdata = "{zim_link}".format(zim_link=zim_link)
bdata = """
Hi,
You have asked for the creation of a zim file, and it is now ready !
You can access it at the following URL:
{zim_link}
Cheers,
ZimIt.
""".format(zim_link=zim_link)
hdata = bdata
body = Attachment(data=bdata, transfer_encoding="quoted-printable")

View File

@ -21,3 +21,15 @@ def ensure_paths_exists(*paths):
if not os.path.exists(path):
msg = '%s does not exist.' % path
raise OSError(msg)
def get_command(cmd, *params, **options):
prepared_options = []
for key, value in options.items():
if value is None:
opt = "--%s" % key
else:
opt = "--%s=%s" % (key, value)
prepared_options.append(opt)
return " ".join((cmd, " ".join(params), " ".join(prepared_options)))