Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import arrow
- import json
- import pickle
- import time
- import urllib
- def main():
- date = arrow.utcnow().format('YYYY_MM_DD_HH_mm_ss')
- previous_date = "2016_02_18_09_02_52"
- previous_second = date[-2:]
- count = 0
- while True:
- date = arrow.utcnow().format('YYYY_MM_DD_HH_mm_ss')
- second = date[-2:]
- url = 'https://poloniex.com/public?command=returnLoanOrders¤cy=BTS'
- try:
- response = urllib.urlopen(url)
- data = json.loads(response.read())
- except:
- data = 'error'
- print 'error wth BTS has occured, probably been blocked by polo'
- time.sleep(10)
- #open previous data
- with open( 'D:/python/loanrates/BTS/'+previous_date+'.json', 'r') as f:
- previous_data = json.load(f)
- #open date log
- with open( 'D:/python/loanrates/BTS/date_store.json', 'r') as f:
- date_store = json.load(f)
- #compare new to old data
- # if new != old, new data is saved and that date recives a 1 in the 'date_store' dict,
- # signifying theres is new data for that date
- if previous_data != data and previous_second != second:
- date_store.append((date,1))
- with open( 'D:/python/loanrates/BTS/'+date+'.json', 'w') as f:
- json.dump(data, f)
- with open( 'D:/python/loanrates/BTS/date_store.json', 'w') as f:
- json.dump(date_store, f)
- previous_date = date
- previous_second = second
- count += 1
- if count == 1000: print 'BTS has logged 1000'
- # if new = old the new data hasn't changed and isn't saved, that date 'date_store' recieves a 0
- # signifying that the previous date of value 1 can be subtituted for this date
- elif previous_second != second:
- date_store.append((date,0))
- with open( 'D:/python/loanrates/BTS/date_store.json', 'w') as f:
- json.dump(date_store, f)
- previous_second = second
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement