Created
December 20, 2013 19:14
-
-
Save xorrbit/8059859 to your computer and use it in GitHub Desktop.
doge.py
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
# -*- coding: utf-8 -*- | |
import httplib2 | |
import re | |
cadpat = re.compile('Daily.*?<td> ([0-9.]+) \(CAD\)', re.DOTALL) | |
usdpat = re.compile('"btc_to_usd":"([0-9.]+?)"') | |
dogepat = re.compile('"lasttradeprice":"([0-9.]+?)"') | |
def get_html(url): | |
_, html = httplib2.Http(disable_ssl_certificate_validation=True).request(url) | |
return html | |
def get_doge_per_btc(): | |
html = get_html("http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132") | |
return dogepat.findall(html)[0] | |
def get_cad_per_btc(): | |
html = get_html("https://www.cavirtex.com/home") | |
return cadpat.findall(html)[0] | |
def get_usd_per_btc(): | |
html = get_html("https://coinbase.com/api/v1/currencies/exchange_rates") | |
return usdpat.findall(html)[0] | |
def main(): | |
doges = get_doge_per_btc() | |
usds = get_usd_per_btc() | |
cads = get_cad_per_btc() | |
usd_per_100kdoge = float(doges) * float(usds) * 100000 | |
cad_per_100kdoge = float(doges) * float(cads) * 100000 | |
print("BTC per DOGE: ฿%s, CAD per 100k DOGE: $%.2f, USD per 100k DOGE: $%.2f"%(doges, cad_per_100kdoge, usd_per_100kdoge)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment