Advertisement
Guest User

Untitled

a guest
Aug 19th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import json
  4. from urllib import request
  5.  
  6. MAX_ITEMS = 5
  7.  
  8. req = request.Request("http://www.coinchoose.com/api.php", headers = {'User-Agent': "Chuck Browser"})
  9. response = request.urlopen(req)
  10.  
  11. stringResponse = response.read().decode("utf-8")
  12. jsonData = json.loads(stringResponse)
  13.  
  14. #file output
  15. output = open('./result.txt', 'w')
  16. for i, currency in enumerate(jsonData):
  17.     output.write("#%d %s (%s) %.2f" % (i + 1, currency['name'], currency['symbol'], float(currency['avgProfit'])))
  18.    
  19.     if MAX_ITEMS - 1 == i:
  20.         break
  21.     else:
  22.         output.write('\n')
  23.    
  24.  
  25. output.close()
  26.        
  27. print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement