Category Tutorials

Flask Web Apps in OS X Server

So, you want to run your Python Flask web applications the native OS X Apache web server? Well that’s awesome, because so did I! This probably won’t work on 10.7.x and earlier without using Apache from brew/ports or using MAMP (which I used); I’m running OS X Yosemite 10.10.5 with the latest server application for this version of OS X.

vonavi:~ jamie$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.10.5
BuildVersion: 14F27

vonavi:~ jamie$ sudo serveradmin -v
Version 15S2259

Step 1: Choose where your app will live.
I personally chose “/Users/jamie/Sites/home” simply for ease of access but I’m not using the userdir functionality.

Here is how my app is laid out:
home\
|-- _venv\
|-- app\
|-- static\
|-- templates\
|-- __init__.py
|-- forms.py
...

Read More

XML fun with Python and lxml’s objectify: Part 1.5: Advanced Parsing (XML, HTML, XHTML, oh my!)

There are dozens of scraping and parsing tools out there but sometimes they are too bloated or simply don’t do what you want them to do. Some may think this is the Rube Goldberg approach but this keeps you in absolute control and really isn’t as hard as it seems. This illustrates some of the features of lxml’s objectify which can be used to parse simple XML down to HTML/XHTML and broken variations.

For this example, I will be using the source code from google.com. You could use urllib or urllib2 to fetch the source and store it in a StringIO object. In this demonstration, I’ve loaded the source to google.com in a StringIO object.

NOTE: Looking at the google.com source, it kind-of makes my eyes want to bleed...

Read More