Question

I'm trying to create a simple (hopefully) Python script that copies the text from this address:

http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD

to either a simple text file or an excel spreadsheet.

I've tried utilising urllib and resquests libraries, but every time I would try and run a very basic script, the shell wouldn't display anything.

For example,

import requests
data = requests.get('http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD')
data.text

Any help would be appreciated. Thank you.

Was it helpful?

Solution

You're almost done;

import requests
symbol = "mtgoxUSD"
url = 'http://api.bitcoincharts.com/v1/trades.csv?symbol={}'.format(symbol)
data = requests.get(url)

# dump resulting text to file
with open("trades_{}.csv".format(symbol), "w") as out_f:
    out_f.write(data.text)

OTHER TIPS

Using urllib:

import urllib
f = urllib.urlopen("http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD")
print f.read()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top