eccentric blog

[ Home | RSS 2.0 | ATOM 1.0 ]

Fri, 23 Jun 2017

getting canadian exchange rates in python

Simple script to get the current exchange rates from the bank of canada:

import requests

r = requests.get('')
rates = r.json()
date = rates['observations'][-1]['d']
rate = rates['observations'][-1]['FXUSDCAD']['v']

posted at: 12:23 | path: /python | permanent link to this entry

Tue, 12 Jun 2012

running roundup tracker under mod_wsgi

I recently setup a Roundup tracker and wanted to host it through mod_wsgi. There is an example in the installation document, but it didn't work for me, so here is what I ended up doing.

Setup my apache2 virtualhost:

<VirtualHost *>
    DocumentRoot /opt/roundup/site/html
    AddDefaultCharset utf-8

    WSGIScriptAlias /   /opt/roundup/site.wsgi
    # create some wsgi daemons - use these parameters for a simple setup
    WSGIDaemonProcess site-roundup user=useraccount group=useracounnt processes=5 threads=10 maximum-requests=200 umask=0007
    # use the daemons we defined above to process requests!
    WSGIProcessGroup site-roundup

    LogLevel warn
    ErrorLog /opt/logs/
    CustomLog /opt/logs/ combined
    ServerSignature Off

Set web = directive in my roundup config.ini to

Created my site.wsgi file:

from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/opt/roundup/site'
application = RequestDispatcher(tracker_home)

And that seemed to do the trick.

posted at: 13:23 | path: /python | permanent link to this entry

Thu, 09 Feb 2012

python T4 XML generator

I needed to generate a XML file required to submit T4 income tax information to the government, and figured I'd share it incase anyone else was looking for a solution to the same problem. The XML spec isn't that complicated, but the naming convention used by CRA is rather painful to deal with. The script isn't anything special but it should do the trick and can always be easily modified. It also does the schema verification so it will warn you if there are any errors in the xml structure or data.

Here is a copy of the code, see the source file for more information.

And here is a link to the governments site with more information about filing electronically:

posted at: 02:42 | path: /python | permanent link to this entry

Fri, 26 Aug 2011

pythonmagick pdf to image

I've always used PIL for image work in python, but I needed to convert a PDF to an image recently and using image magick looked to be the way. There is a pythonmagick interface to use imagemagick in python, but there is zero documentation... Here is what I'm using to do the job:
#!/usr/bin/env python

import PythonMagick

pdf = 'doc.pdf'
p = PythonMagick.Image()    
This sets the density value (default is 72) that the pdf is read at, so that you can get a higher resolution image from the PDF, and then simply writes it to a jpg file.

posted at: 12:41 | path: /python | permanent link to this entry

Made with Pyblosxom