Archives for Code

Using urllib2 to POST JSON

import json import urllib2 data = {‘name’:'Alex’,'colour’:'Green’,'number’:42,’foo’:'bar’} data = json.dumps(data) url = “http://somewebsite.zzz/webservice” req = urllib2.Request(url, data, {‘Content-Type’: ‘application/json’}) f = urllib2.urlopen(req) response = f.read() f.close() Excellent guide to Python and REST webservices: http://developer.yahoo.com/python/python-rest.html

Get a files ‘last modified’ datetime using Python

Recently I wrote a script which checks an FTP server every morning for a new file. When it finds the remote file it must decide whether or not it is newer than the same file it downloaded at an earlier date. This is how the code compares the ‘last modified’ date of two files. The [...]

PostgreSQL with Python using Psycopg

The business intelligence suite I manage at work is built on PostgreSQL and Python. I work on the code that sits between the database and the internet/front-end to move data accross layers. From the start of the project I used the PyGreSQL module, see this post for info, so my scripts could interface with the database. One [...]