Simple steps…but so much fun.

Worked on the application I am building for my day job a little more today. I am finding that I have a lot to learn about basics of python. Particularly working with parsing string data.  So far this project has been a lot of fun because I am learning a lot about strip, split and join string operations. It’s actually pretty mind blowing that I can take a word document and with a few lines of code build a data structure, in this case a dictionary which will likely end up a Json object.  I’m having a great time working with data in this manner and I’m actually considering going through a data science course to pick up some more concepts.

Also, just the prospect of saving myself time in my day job is giving me a lot more ambition.

I am also seeing that I’ve got to adopt more DRY principles in my code, but I’m currently just trying to hack this thing together. I feel like I can refactor the code once I have a working prototype.


Today while working on the flask casts site, I decided it would be a good idea to generate a url slug. This is extremely important for search engine optimization. I thought about writing my own class to do this, then thought it might get ugly…so I searched for a package. I found Slugify:

Pretty simple to use. When creating the Post object I just modified my __init__ to the following:

[pastacode lang=”python” manual=”%20%20%20%20def%20__init__(self%2C%20title%2C%20content%2C%20author%2C%20created%3DNone)%3A%0A%20%20%20%20%20%20%20%20self.title%20%3D%20title%0A%20%20%20%20%20%20%20%20self.slug%20%3D%20slugify(title)‘%25A%20%25x%20%40%20%25H%3A%25M%3A%25S’)%20%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20created%20is%20None%20else%20created” message=”” highlight=”” provider=”manual”/]

Now I can pass the slug to a url like:

[pastacode lang=”python” manual=”%40home.route(‘%2Fpost%2F%3Cstring%3Aslug%3E’)%0Adef%20post(slug)%3A%0A%20%20%20%20post%20%3D%20Post.get_post(slug)%0A%20%20%20%20author%20%3D%20User.get_user(post%5B’author’%5D)%0A%20%20%20%20return%20render_template(‘home%2Fpost.html’%2C%20post%3Dpost%2C%20author%3Dauthor%5B’fullname’%5D)” message=”” highlight=”” provider=”manual”/]

Thanks for reading!