17
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
19
19
20
- from libzim import ZimArticle , ZimBlob , ZimCreator
20
+ # Write the article
21
+ import uuid
22
+
23
+ from libzim .writer import Article , Blob , Creator
21
24
22
- class ZimTestArticle (ZimArticle ):
23
25
26
+ class TestArticle (Article ):
24
27
def __init__ (self , url , title , content ):
25
- ZimArticle .__init__ (self )
28
+ Article .__init__ (self )
26
29
self .url = url
27
30
self .title = title
28
31
self .content = content
@@ -35,58 +38,69 @@ def get_url(self):
35
38
36
39
def get_title (self ):
37
40
return f"{ self .title } "
38
-
41
+
39
42
def get_mime_type (self ):
40
43
return "text/html"
41
-
44
+
42
45
def get_filename (self ):
43
46
return ""
44
-
47
+
45
48
def should_compress (self ):
46
49
return True
47
50
48
51
def should_index (self ):
49
52
return True
50
53
51
54
def get_data (self ):
52
- return ZimBlob (self .content )
55
+ return Blob (self .content )
53
56
54
- # Create a ZimTestArticle article
55
57
56
- content = '''<!DOCTYPE html>
58
+ # Create a TestArticle article
59
+
60
+ content = """<!DOCTYPE html>
57
61
<html class="client-js">
58
62
<head><meta charset="UTF-8">
59
63
<title>Monadical</title>
60
64
</head>
61
- <h1> ñññ Hello, it works ñññ </h1></html>'''
65
+ <h1> ñññ Hello, it works ñññ </h1></html>"""
62
66
63
- content2 = ''' <!DOCTYPE html>
67
+ content2 = """ <!DOCTYPE html>
64
68
<html class="client-js">
65
69
<head><meta charset="UTF-8">
66
70
<title>Monadical 2</title>
67
71
</head>
68
- <h1> ñññ Hello, it works 2 ñññ </h1></html>'''
72
+ <h1> ñññ Hello, it works 2 ñññ </h1></html>"""
69
73
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 )
72
76
73
77
print (article .content )
74
78
75
- # Write the article
76
- import uuid
77
- rnd_str = str (uuid .uuid1 ())
79
+
80
+ rnd_str = str (uuid .uuid1 ())
78
81
79
82
test_zim_file_path = "/opt/python-libzim/tests/kiwix-test"
80
83
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
+ )
82
90
83
91
# Add articles to zim file
84
92
zim_creator .add_article (article )
85
93
zim_creator .add_article (article2 )
86
94
87
95
# Set mandatory metadata
88
96
if 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
+ )
90
104
91
105
print (zim_creator ._get_metadata ())
92
106
@@ -98,11 +112,13 @@ def get_data(self):
98
112
99
113
rnd_str = str (uuid .uuid1 ())
100
114
101
- with ZimCreator (test_zim_file_path + '-' + rnd_str + ' .zim' ) as zc :
115
+ with Creator (test_zim_file_path + "-" + rnd_str + " .zim" ) as zc :
102
116
zc .add_article (article )
103
117
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