Skip to content

Commit 7e811f9

Browse files
committed
Fixed #214: Creator usage now copy-pastable
Usage was informative and if copy-pasted without a change would lead to an error creating a broken ZIM file.
1 parent 9c76b7b commit 7e811f9

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ print(list(suggestion.getResults(0, suggestion_count)))
7676
### Write a ZIM file
7777

7878
```py
79+
import base64
80+
import pathlib
81+
7982
from libzim.writer import Creator, Item, StringProvider, FileProvider, Hint
8083

8184

8285
class MyItem(Item):
83-
def __init__(self, title, path, content = "", fpath = None):
86+
def __init__(self, title, path, content="", fpath=None):
8487
super().__init__()
8588
self.path = path
8689
self.title = title
@@ -108,14 +111,26 @@ class MyItem(Item):
108111
content = """<html><head><meta charset="UTF-8"><title>Web Page Title</title></head>
109112
<body><h1>Welcome to this ZIM</h1><p>Kiwix</p></body></html>"""
110113

114+
pathlib.Path("home-fr.html").write_text(
115+
"""<html><head><meta charset="UTF-8">
116+
<title>Bonjour</title></head>
117+
<body><h1>this is home-fr</h1></body></html>"""
118+
)
119+
111120
item = MyItem("Hello Kiwix", "home", content)
112121
item2 = MyItem("Bonjour Kiwix", "home/fr", None, "home-fr.html")
113122

123+
# illustration = pathlib.Path("icon48x48.png").read_bytes()
124+
illustration = base64.b64decode(
125+
"iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAAGXRFWHRTb2Z0d2FyZQBB"
126+
"ZG9iZSBJbWFnZVJlYWR5ccllPAAAAANQTFRFR3BMgvrS0gAAAAF0Uk5TAEDm2GYAAAAN"
127+
"SURBVBjTY2AYBdQEAAFQAAGn4toWAAAAAElFTkSuQmCC"
128+
)
129+
114130
with Creator("test.zim").config_indexing(True, "eng") as creator:
115131
creator.set_mainpath("home")
116132
creator.add_item(item)
117133
creator.add_item(item2)
118-
illustration = pathlib.Path("icon48x48.png").read_bytes()
119134
creator.add_illustration(48, illustration)
120135
for name, value in {
121136
"creator": "python-libzim",
@@ -124,7 +139,7 @@ with Creator("test.zim").config_indexing(True, "eng") as creator:
124139
"publisher": "You",
125140
"title": "Test ZIM",
126141
"language": "eng",
127-
"date": "2024-06-30"
142+
"date": "2024-06-30",
128143
}.items():
129144

130145
creator.add_metadata(name.title(), value)

0 commit comments

Comments
 (0)