Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import arrow
  2. import json
  3. import pickle
  4. import time
  5. import urllib
  6.  
  7. def main():
  8.  
  9. date = arrow.utcnow().format('YYYY_MM_DD_HH_mm_ss')
  10. previous_date = "2016_02_18_09_02_52"
  11. previous_second = date[-2:]
  12. count = 0
  13.  
  14. while True:
  15. date = arrow.utcnow().format('YYYY_MM_DD_HH_mm_ss')
  16. second = date[-2:]
  17. url = 'https://poloniex.com/public?command=returnLoanOrders&currency=BTS'
  18. try:
  19. response = urllib.urlopen(url)
  20. data = json.loads(response.read())
  21. except:
  22. data = 'error'
  23. print 'error wth BTS has occured, probably been blocked by polo'
  24. time.sleep(10)
  25.  
  26. #open previous data
  27. with open( 'D:/python/loanrates/BTS/'+previous_date+'.json', 'r') as f:
  28. previous_data = json.load(f)
  29.  
  30. #open date log
  31. with open( 'D:/python/loanrates/BTS/date_store.json', 'r') as f:
  32. date_store = json.load(f)
  33.  
  34. #compare new to old data
  35. # if new != old, new data is saved and that date recives a 1 in the 'date_store' dict,
  36. # signifying theres is new data for that date
  37. if previous_data != data and previous_second != second:
  38.  
  39. date_store.append((date,1))
  40.  
  41. with open( 'D:/python/loanrates/BTS/'+date+'.json', 'w') as f:
  42. json.dump(data, f)
  43.  
  44. with open( 'D:/python/loanrates/BTS/date_store.json', 'w') as f:
  45. json.dump(date_store, f)
  46.  
  47. previous_date = date
  48. previous_second = second
  49.  
  50. count += 1
  51. if count == 1000: print 'BTS has logged 1000'
  52. # if new = old the new data hasn't changed and isn't saved, that date 'date_store' recieves a 0
  53. # signifying that the previous date of value 1 can be subtituted for this date
  54. elif previous_second != second:
  55. date_store.append((date,0))
  56.  
  57. with open( 'D:/python/loanrates/BTS/date_store.json', 'w') as f:
  58. json.dump(date_store, f)
  59.  
  60. previous_second = second
  61.  
  62. if __name__ == '__main__':
  63.  
  64. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement