This book is new. If you'd like to go through it, then join the Learn Code Forum to get help while you attempt it. I'm also looking for feedback on the difficulty of the projects. If you don't like public forums, then email firstname.lastname@example.org to talk privately.
Exercise 46: blog
You should have your process theme written up as described in the beginning of this section, and you should have your process listed out and ready to go. To get started we'll make a totally new tool called blog as a warm-up for the rest of this section.
You should take this project slowly and try not to rush it. The goal is not to be a fast programmer. It's better to build speed fluidly and slowly by methodically going slow until how you work is simply second nature. If you always rush, then you'll be sloppy.
Make sure to keep your notebook handy and track facts and metrics about your work. You are trying to see if there's a process that will work for you as a method of working later. Not all methods work all the time, which is why I've tried to teach you various tactics and strategies for working that are used by many different programmers. If you do this project and you find out that something you did didn't work, then your notes will help you find out why. Change it up for the next project and see if something else works better.
I'm tasking you with writing a simple command line blogging tool called blog. It's a very creative name for a very creative project. Blogs are some of the first projects early programmers write but your project is going to generate the blog locally and then send it to a server using another tool called rsync. Here's the requirements for this exercise:
- If you don't know what a blog is then you should probably go start one and try it for a little while. There are plenty of platforms, but you might like either Wordpress or Tumblr. Just use it for a little while and take notes on its features that you might want to copy. Don't go crazy.
- You're going to want to learn how to use a templating system for styling your HTML pages. I recommend you use either the mako or jinja template systems. These systems let you make template HTML files that you can then put the real content into based on text files the user has placed in a directory.
- You'll want to use Markdown as your blogging format, so install the markdown library for your project.
- Your blog will be a static file blog, so you'll want to use python -m SimpleHTTPServer 8000 as demonstrated on the SimpleHTTPServer instructions. This will serve files to your browser out of the directory where you dump them.
- You'll need a command line tool called blog to work with someone's blog.
- Before you work, think through all of the things your blog tool has to do and then devise all the commands that are needed and their arguments. Then check out the docopt project as a way to implement these commands.
- You should use the mock to mock out anything that you need to test, especially for error conditions. Refer to how I used mock in Part III and Part V.
Other than that you are free to develop this blog tool how you want. Get creative. All that needs to happen is a blog is created somehow that I then can put on a server to be viewed.
Finally, the way I might put a blog like this online is with rsync using this command:
rsync -azv dist/* myserver.com:/var/www/myblog/
It's possible that this is a little more advanced, but this could be a good time to learn how to serve static files. There's a study drill that also talks about how to use Amazon S3 to do this.
- Static files to your own server is fun and all, but wouldn't it be better if the blog tool worked with Amazon S3? There's a project called boto3 that will give you everything you need to make blog do this.
- Write a blog serve command that uses the SimpleHTTPServer class to simply serve the blog directly rather than generating it separately.