MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / DynamicDocument

Class DynamicDocument

openlibrary/plugins/upstream/code.py:153–182  ·  view source on GitHub ↗

Dynamic document is created by concatenating various rawtext documents in the DB. Used to generate combined js/css using multiple js/css files in the system.

Source from the content-addressed store, hash-verified

151
152
153class DynamicDocument:
154 """Dynamic document is created by concatenating various rawtext documents in the DB.
155 Used to generate combined js/css using multiple js/css files in the system.
156 """
157
158 def __init__(self, root):
159 self.root = root.removesuffix("/")
160 self.docs = None
161 self._text = None
162 self.last_modified = None
163
164 def update(self):
165 keys = web.ctx.site.things({"type": "/type/rawtext", "key~": self.root + "/*"})
166 docs = sorted(web.ctx.site.get_many(keys), key=lambda doc: doc.key)
167 if docs:
168 self.last_modified = min(doc.last_modified for doc in docs)
169 self._text = "\n\n".join(doc.get("body", "") for doc in docs)
170 else:
171 self.last_modified = datetime.datetime.utcnow()
172 self._text = ""
173
174 def get_text(self):
175 """Returns text of the combined documents"""
176 if self._text is None:
177 self.update()
178 return self._text
179
180 def md5(self):
181 """Returns md5 checksum of the combined documents"""
182 return hashlib.md5(self.get_text().encode("utf-8")).hexdigest()
183
184
185def create_dynamic_document(url, prefix):

Callers 1

create_dynamic_documentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected