Working with (X/HT)ML in Python: I was playing around with scraping some web pages at home and I found this tool to be pretty neat: http://pypi.python.org/pypi/pyquery – pyquery allows you to make jquery queries on xml documents.
- dimagi.utils.parsing.string_to_datetime (which calls the standard dateutil library’s parser.parse). This will take input such as “January 5”, “2011-02-02”, “11/12/11”, etc.
- For dates in JSON/Couch format (“2011-12-23T20:59:19Z”) use dimagi.utils.parsing.json_format_datetime.
- Check out the diagram at http://wiki.python.org/moin/WorkingWithTime.
strip, lstrip, rstrip
The way we “delete” things in couch is often to just change the doc_type so it doesn’t show up in views. For instance, an XFormInstance that has been deleted will have doc_type “XFormInstance-Deleted”. This lets us undelete them later if it was an error.
When it came time to write the code to undelete, I thought I’d just use rstrip to strip the string ‘-Deleted’ off of the right of the string.
It turns out that’s not what that does. According to the docs: “The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped”. So in my case I was getting “XformInstanc”, since ‘e’ is in ‘-Deleted’.