Created
June 16, 2013 21:00
-
-
Save mhkeller/5793432 to your computer and use it in GitHub Desktop.
An example querying the FMS Treasury database using python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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