summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryet-another-username <mikejamesjsmith@gmail.com>2014-07-27 16:09:22 +0100
committeryet-another-username <mikejamesjsmith@gmail.com>2014-07-27 16:09:22 +0100
commitbcf854ef83139f3e66fcbd754fcd9175859af879 (patch)
tree48dadcf0c7169fd1383b21df5b1d51dc2c22f747
parent18a4e260d00746da8dc210c44e70e57471f8fb1b (diff)
Create coinfetch
-rw-r--r--coinfetch34
1 files changed, 34 insertions, 0 deletions
diff --git a/coinfetch b/coinfetch
new file mode 100644
index 0000000..c5e1067
--- /dev/null
+++ b/coinfetch
@@ -0,0 +1,34 @@
+#!/usr/bin/python3
+
+# Wow such python
+# Feel free to modify
+# So generous: DGSWzqyofHC6YDSA34hwVQpWGQHnzJm1sk
+#
+# Values retrieved are in the form
+# 1 <coin_a> = <printed output> <coin_b>
+#
+# Remember to make this file executable ( "$chmod +x ./coinfetch" )
+
+import requests, sys
+
+def coinfetch(coin_a, coin_b):
+ """
+ Fetch a coin pair
+ """
+ url = 'http://data.bter.com/api/1/tickers'
+ r = requests.get(url)
+ try:
+ pair = coin_a+"_"+coin_b
+ out = float(r.json()[pair]['avg'])
+ except:
+ pair = coin_b+"_"+coin_a
+ out = float((r.json()[pair]['avg']))**-1
+ return out
+
+try:
+# To change precision of output, replace the 8 with the desired number of decimal places.
+ print ("%.8f" %coinfetch(sys.argv[1], sys.argv[2]))
+except KeyError:
+ exit("Coinpair not found.")
+except IndexError:
+ exit("Enter an argument!!")