File tree Expand file tree Collapse file tree 5 files changed +20
-1
lines changed Expand file tree Collapse file tree 5 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,7 @@ class Archive : public Wrapper<zim::Archive>
144144 FORWARD (wrapper::Entry, getEntryByPath)
145145 FORWARD (wrapper::Entry, getEntryByTitle)
146146 FORWARD (wrapper::Entry, getMainEntry)
147+ FORWARD (wrapper::Entry, getRandomEntry)
147148 FORWARD (wrapper::Item, getIllustrationItem)
148149 FORWARD (std::set<unsigned int >, getIllustrationSizes)
149150 std::string getUuid () const
Original file line number Diff line number Diff line change @@ -1101,6 +1101,14 @@ cdef class Archive:
11011101 raise KeyError(str(e))
11021102 return Entry.from_entry(move(entry))
11031103
1104+ def get_random_entry(self) -> Entry:
1105+ """ Get a random `Entry`.
1106+
1107+ Returns:
1108+ A random entry.
1109+ """
1110+ return Entry.from_entry(move(self.c_archive.getRandomEntry()))
1111+
11041112 @property
11051113 def metadata_keys(self) -> List[str]:
11061114 """ List of Metadata keys present in this archive.
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ class Archive:
4141 def get_entry_by_path (self , path : str ) -> Entry : ...
4242 def has_entry_by_title (self , title : str ) -> bool : ...
4343 def get_entry_by_title (self , title : str ) -> Entry : ...
44+ def get_random_entry (self ) -> Entry : ...
4445 @property
4546 def metadata_keys (self ) -> list [str ]: ...
4647 def get_metadata_item (self , name : str ) -> Item : ...
Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ cdef extern from "libwrapper.h" namespace "wrapper":
153153 vector[string] getMetadataKeys() except +
154154
155155 Entry getMainEntry() except +
156+ Entry getRandomEntry() except +
156157 Item getIllustrationItem() except +
157158 Item getIllustrationItem(int size) except +
158159 size_type getEntryCount() except +
Original file line number Diff line number Diff line change 99import pytest
1010
1111import libzim .writer # pyright: ignore [reportMissingModuleSource]
12- from libzim .reader import Archive # pyright: ignore [reportMissingModuleSource]
12+ from libzim .reader import Archive , Entry # pyright: ignore [reportMissingModuleSource]
1313from libzim .search import Query , Searcher # pyright: ignore [reportMissingModuleSource]
1414from libzim .suggestion import ( # pyright: ignore [reportMissingModuleSource]
1515 SuggestionSearcher ,
@@ -599,3 +599,11 @@ def filename(self):
599599 assert zim != Different (fpath1 )
600600 assert zim == Sub (fpath1 )
601601 assert zim != Sub2 (fpath1 )
602+
603+
604+ @skip_if_offline
605+ @pytest .mark .parametrize (* parametrize_for (["filename" ]))
606+ def test_reader_get_random_entry (all_zims , filename ):
607+ zim = Archive (all_zims / filename )
608+
609+ assert isinstance (zim .get_random_entry (), Entry )
You can’t perform that action at this time.
0 commit comments