Skip to content

Instantly share code, notes, and snippets.

@imrahil
Last active December 16, 2016 23:09
Show Gist options
  • Save imrahil/41c93715ba19fc70de50e630ca9e54f4 to your computer and use it in GitHub Desktop.
Save imrahil/41c93715ba19fc70de50e630ca9e54f4 to your computer and use it in GitHub Desktop.
getHistory
@octoprint.plugin.BlueprintPlugin.route("/history", methods=["GET"])
def getHistoryData(self):
self._console_logger.debug("Rendering history.yaml")
def view():
history_dict = self._getHistoryDict()
if history_dict is not None:
self._console_logger.debug("Returning data")
result = jsonify(history=history_dict)
else:
self._console_logger.debug("Empty file history.yaml")
result = jsonify({})
return result
def etag(lm=None):
if lm is None:
lm = lastmodified()
import hashlib
hash = hashlib.sha1()
hash.update(str(lm))
return hash.hexdigest()
def condition():
return check_etag(etag())
def lastmodified():
stat = os.stat(self._history_file_path)
return stat.st_mtime
# return view()
return with_revalidation_checking(etag_factory=lambda *args, **kwargs: etag(),
lastmodified_factory=lambda *args, **kwargs: lastmodified())(view)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment