1717# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
1919
20- from libzim import ZimArticle , ZimBlob , ZimCreator
20+ # Write the article
21+ import uuid
22+
23+ from libzim .writer import Article , Blob , Creator
2124
22- class ZimTestArticle (ZimArticle ):
2325
26+ class TestArticle (Article ):
2427 def __init__ (self , url , title , content ):
25- ZimArticle .__init__ (self )
28+ Article .__init__ (self )
2629 self .url = url
2730 self .title = title
2831 self .content = content
@@ -35,58 +38,69 @@ def get_url(self):
3538
3639 def get_title (self ):
3740 return f"{ self .title } "
38-
41+
3942 def get_mime_type (self ):
4043 return "text/html"
41-
44+
4245 def get_filename (self ):
4346 return ""
44-
47+
4548 def should_compress (self ):
4649 return True
4750
4851 def should_index (self ):
4952 return True
5053
5154 def get_data (self ):
52- return ZimBlob (self .content )
55+ return Blob (self .content )
5356
54- # Create a ZimTestArticle article
5557
56- content = '''<!DOCTYPE html>
58+ # Create a TestArticle article
59+
60+ content = """<!DOCTYPE html>
5761 <html class="client-js">
5862 <head><meta charset="UTF-8">
5963 <title>Monadical</title>
6064 </head>
61- <h1> ñññ Hello, it works ñññ </h1></html>'''
65+ <h1> ñññ Hello, it works ñññ </h1></html>"""
6266
63- content2 = ''' <!DOCTYPE html>
67+ content2 = """ <!DOCTYPE html>
6468 <html class="client-js">
6569 <head><meta charset="UTF-8">
6670 <title>Monadical 2</title>
6771 </head>
68- <h1> ñññ Hello, it works 2 ñññ </h1></html>'''
72+ <h1> ñññ Hello, it works 2 ñññ </h1></html>"""
6973
70- article = ZimTestArticle ("Monadical_SAS" , "Monadical" , content )
71- article2 = ZimTestArticle ("Monadical_2" , "Monadical 2" , content2 )
74+ article = TestArticle ("Monadical_SAS" , "Monadical" , content )
75+ article2 = TestArticle ("Monadical_2" , "Monadical 2" , content2 )
7276
7377print (article .content )
7478
75- # Write the article
76- import uuid
77- rnd_str = str (uuid .uuid1 ())
79+
80+ rnd_str = str (uuid .uuid1 ())
7881
7982test_zim_file_path = "/opt/python-libzim/tests/kiwix-test"
8083
81- zim_creator = ZimCreator (test_zim_file_path + '-' + rnd_str + '.zim' ,main_page = "Monadical" ,index_language = "eng" , min_chunk_size = 2048 )
84+ zim_creator = Creator (
85+ test_zim_file_path + "-" + rnd_str + ".zim" ,
86+ main_page = "Monadical" ,
87+ index_language = "eng" ,
88+ min_chunk_size = 2048 ,
89+ )
8290
8391# Add articles to zim file
8492zim_creator .add_article (article )
8593zim_creator .add_article (article2 )
8694
8795# Set mandatory metadata
8896if not zim_creator .mandatory_metadata_ok ():
89- zim_creator .update_metadata (creator = 'python-libzim' ,description = 'Created in python' ,name = 'Hola' ,publisher = 'Monadical' ,title = 'Test Zim' )
97+ zim_creator .update_metadata (
98+ creator = "python-libzim" ,
99+ description = "Created in python" ,
100+ name = "Hola" ,
101+ publisher = "Monadical" ,
102+ title = "Test Zim" ,
103+ )
90104
91105print (zim_creator ._get_metadata ())
92106
@@ -98,11 +112,13 @@ def get_data(self):
98112
99113rnd_str = str (uuid .uuid1 ())
100114
101- with ZimCreator (test_zim_file_path + '-' + rnd_str + ' .zim' ) as zc :
115+ with Creator (test_zim_file_path + "-" + rnd_str + " .zim" ) as zc :
102116 zc .add_article (article )
103117 zc .add_article (article2 )
104- zc .update_metadata (creator = 'python-libzim' ,
105- description = 'Created in python' ,
106- name = 'Hola' ,publisher = 'Monadical' ,
107- title = 'Test Zim' )
108-
118+ zc .update_metadata (
119+ creator = "python-libzim" ,
120+ description = "Created in python" ,
121+ name = "Hola" ,
122+ publisher = "Monadical" ,
123+ title = "Test Zim" ,
124+ )
0 commit comments