Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__pycache__
build
libzim_wrapper.*.so
libzim/libzim_wrapper.cpp
libzim/libzim_wrapper.h
libzim/libzim_wrapper_api.h
*.egg-info
23 changes: 23 additions & 0 deletions libzim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is part of python-libzim
# (see https://github.com/libzim/python-libzim)
#
# Copyright (c) 2020 Juan Diego Caballero <jdc@monadical.com>
# Copyright (c) 2020 Matthieu Gautier <mgautier@kymeria.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


from libzim_wrapper import Blob

__all__ = ["Blob"]
66 changes: 41 additions & 25 deletions libzim/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.


from libzim import ZimArticle, ZimBlob, ZimCreator
# Write the article
import uuid

from libzim.writer import Article, Blob, Creator

class ZimTestArticle(ZimArticle):

class TestArticle(Article):
def __init__(self, url, title, content):
ZimArticle.__init__(self)
Article.__init__(self)
self.url = url
self.title = title
self.content = content
Expand All @@ -35,58 +38,69 @@ def get_url(self):

def get_title(self):
return f"{self.title}"

def get_mime_type(self):
return "text/html"

def get_filename(self):
return ""

def should_compress(self):
return True

def should_index(self):
return True

def get_data(self):
return ZimBlob(self.content)
return Blob(self.content)

# Create a ZimTestArticle article

content = '''<!DOCTYPE html>
# Create a TestArticle article

content = """<!DOCTYPE html>
<html class="client-js">
<head><meta charset="UTF-8">
<title>Monadical</title>
</head>
<h1> ñññ Hello, it works ñññ </h1></html>'''
<h1> ñññ Hello, it works ñññ </h1></html>"""

content2 = '''<!DOCTYPE html>
content2 = """<!DOCTYPE html>
<html class="client-js">
<head><meta charset="UTF-8">
<title>Monadical 2</title>
</head>
<h1> ñññ Hello, it works 2 ñññ </h1></html>'''
<h1> ñññ Hello, it works 2 ñññ </h1></html>"""

article = ZimTestArticle("Monadical_SAS", "Monadical", content)
article2 = ZimTestArticle("Monadical_2", "Monadical 2", content2)
article = TestArticle("Monadical_SAS", "Monadical", content)
article2 = TestArticle("Monadical_2", "Monadical 2", content2)

print(article.content)

# Write the article
import uuid
rnd_str = str(uuid.uuid1())

rnd_str = str(uuid.uuid1())

test_zim_file_path = "/opt/python-libzim/tests/kiwix-test"

zim_creator = ZimCreator(test_zim_file_path + '-' + rnd_str + '.zim',main_page = "Monadical",index_language= "eng", min_chunk_size= 2048)
zim_creator = Creator(
test_zim_file_path + "-" + rnd_str + ".zim",
main_page="Monadical",
index_language="eng",
min_chunk_size=2048,
)

# Add articles to zim file
zim_creator.add_article(article)
zim_creator.add_article(article2)

# Set mandatory metadata
if not zim_creator.mandatory_metadata_ok():
zim_creator.update_metadata(creator='python-libzim',description='Created in python',name='Hola',publisher='Monadical',title='Test Zim')
zim_creator.update_metadata(
creator="python-libzim",
description="Created in python",
name="Hola",
publisher="Monadical",
title="Test Zim",
)

print(zim_creator._get_metadata())

Expand All @@ -98,11 +112,13 @@ def get_data(self):

rnd_str = str(uuid.uuid1())

with ZimCreator(test_zim_file_path + '-' + rnd_str + '.zim') as zc:
with Creator(test_zim_file_path + "-" + rnd_str + ".zim") as zc:
zc.add_article(article)
zc.add_article(article2)
zc.update_metadata(creator='python-libzim',
description='Created in python',
name='Hola',publisher='Monadical',
title='Test Zim')

zc.update_metadata(
creator="python-libzim",
description="Created in python",
name="Hola",
publisher="Monadical",
title="Test Zim",
)
4 changes: 2 additions & 2 deletions libzim/lib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <Python.h>
#include "lib.h"

#include "libzim_api.h"
#include "libzim_wrapper_api.h"

#include <iostream>
#include <zim/writer/url.h>
Expand All @@ -38,7 +38,7 @@

ZimArticleWrapper::ZimArticleWrapper(PyObject *obj) : m_obj(obj)
{
if (import_libzim())
if (import_libzim_wrapper())
{
std::cerr << "Error executing import_libzim!\n";
throw std::runtime_error("Error executing import_libzim");
Expand Down
Loading