Created
May 31, 2011 21:12
-
-
Save tebeka/1001299 to your computer and use it in GitHub Desktop.
Get exchange rate for two currencies
This file contains hidden or 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 | |
# Print exchange rate | |
import yql | |
QUERY = 'SELECT * FROM yahoo.finance.xchange WHERE pair in ("%s%s")' | |
ENV = "store://datatables.org/alltableswithkeys" | |
def main(argv=None): | |
import sys | |
from argparse import ArgumentParser | |
argv = argv or sys.argv | |
parser = ArgumentParser(description="") | |
parser.add_argument("base", help="base currency") | |
parser.add_argument("to", help="target currency") | |
args = parser.parse_args(argv[1:]) | |
y = yql.Public() | |
result = y.execute(QUERY % (args.base, args.to), env=ENV).one() | |
print result["Rate"] | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment