Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Created June 16, 2013 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhkeller/5793432 to your computer and use it in GitHub Desktop.
Save mhkeller/5793432 to your computer and use it in GitHub Desktop.
An example querying the FMS Treasury database using python.
#!/usr/bin/env python
from json import load
from urllib import urlopen
from urllib import urlencode
from pandas import DataFrame
def treasury(sql):
url = 'https://box.scraperwiki.com/cc7znvq/47d80ae900e04f2/sql/'
query_string = urlencode({'q':sql})
handle = urlopen(url + '?' + query_string)
if handle.code == 200:
d = load(handle)
return DataFrame(d)
else:
raise ValueError(handle.read())
if __name__ == '__main__':
print('Operating cash balances for May 22, 2013')
print(treasury('''SELECT * FROM "t1" WHERE "date" = '2013-05-22';'''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment