Today a friend of mine had the idea to parse some sensor data on a raspberry pi and generate a html file out of it. So, having had some time I wrote a small clojure application which does just that.
I did that in a tutorial form by adding functionality to that project in small steps and explaining what I did in the commits.
What the application does is the following:
- Parse a config file for the path to a sensor file
- Open that sensor file and convert the data to a clojure map
- Take that clojure map and pass it to an enlive template
- The template generates a html with a li entry for each key value pair of the map
- Parse the config file for a path where we can store the generated html files
- Write the html to a randomly generated html file in that path
The sensor file has to look like this:
It completely misses error handling and support for multiple files and a lot of different things one might think of, but I think you can get the point and an entry to step further with clojure.
You can find the code here: https://github.com/sveri/read-sensors
I am surprised that it only took me two hours. I had to ask once in the irc channel for the conversion of file data to maps but the rest of it could be done with my knowledge that I collected in the last 6 months and a bit of googling 🙂