@@ -7,7 +7,7 @@ docker-compose run libzim /bin/bash
77```
88``` bash
99python setup.py build_ext -i
10- python tests/test_pyzim .py
10+ python tests/test_libzim .py
1111
1212# or
1313
@@ -18,38 +18,63 @@ python tests/test_pyzim.py
1818Example:
1919
2020``` python3
21- import pyzim
21+ from libzim import ZimArticle, ZimBlob, ZimCreator
2222
23- zim_file_path = " /opt/python-libzim/tests/wikipedia_es_physics_mini.zim"
24- zim_reader = pyzim.ZimReader(zim_file_path)
23+ class ZimTestArticle (ZimArticle ):
24+ content = ''' <!DOCTYPE html>
25+ <html class="client-js">
26+ <head><meta charset="UTF-8">
27+ <title>Monadical</title>
28+ <h1> ñññ Hello, it works ñññ </h1></html>'''
2529
26- article = pyzim.ZimArticle()
30+ def __init__ (self ):
31+ ZimArticle.__init__ (self )
2732
28- # article content
33+ def is_redirect (self ):
34+ return False
2935
30- article_title = " Monadical SAS"
31- article_url = " Monadical_SAS"
32- article_longurl = " A/Monadical_SAS"
33- article_mimetype = " text/html"
34- article_content = ''' <!DOCTYPE html> <html class="client-js"><head><meta charset="UTF-8">
35- <title>Monadical SAS</title> <h1> Hello, it works Monadical ñññ </h1></html>'''
36+ @ property
37+ def can_write (self ):
38+ return True
3639
37- article.title = article_title
38- article.url = article_url
39- article.mimetype = article_mimetype
40- article.content = article_content
40+ def get_url (self ):
41+ return " A/Monadical_SAS"
4142
43+ def get_title (self ):
44+ return " Monadical SAS"
45+
46+ def get_mime_type (self ):
47+ return " text/html"
48+
49+ def get_filename (self ):
50+ return " "
51+
52+ def should_compress (self ):
53+ return True
4254
43- import uuid
55+ def should_index (self ):
56+ return True
57+
58+ def get_data (self ):
59+ return ZimBlob(self .content.encode(' UTF-8' ))
60+
61+ # Create a ZimTestArticle article
62+
63+ article = ZimTestArticle()
64+ print (article.content)
4465
66+ # Write the articles
67+ import uuid
4568rnd_str = str (uuid.uuid1())
69+
4670test_zim_file_path = " /opt/python-libzim/tests/kiwix-test"
47- zim_creator = pyzim.ZimCreator(test_zim_file_path + ' -' + rnd_str + ' .zim' ," welcome" ," spa" ,2048 )
4871
72+ zim_creator = ZimCreator(test_zim_file_path + ' -' + rnd_str + ' .zim' ,main_page = " welcome" ,index_language = " eng" , min_chunk_size = 2048 )
4973
74+ # Add article to zim file
75+ zim_creator.add_article(article)
5076
77+ # Write article to zim file
78+ zim_creator.finalize()
5179
52- # Add and write article to second test zim file
53- zim_creator.add_article(article)
54- zim_creator.finalise()
5580```
0 commit comments