mirror of
https://github.com/jwinterm/btcTicker.git
synced 2026-10-17 05:21:25 +02:00
28 lines
697 B
Python
28 lines
697 B
Python
import requests
|
|
import json
|
|
|
|
# Set URL for bitstamp ticker info
|
|
URL = 'https://www.bitstamp.net/api/ticker/'
|
|
# Headers, because headers
|
|
headers = {'content-type': 'application/json'}
|
|
|
|
|
|
def GetTicker(serverURL=URL):
|
|
"""Try and get bitstamp ticker info"""
|
|
try:
|
|
resp = requests.get(serverURL, headers=headers, verify=False)
|
|
output = json.loads(resp.text)
|
|
print(output)
|
|
last_price = float(output[u'last'])
|
|
time_stamp = int(output[u'timestamp'])
|
|
return last_price, time_stamp
|
|
|
|
|
|
except:
|
|
#Return out of sync if bitmonerod is not ready
|
|
message = "error"
|
|
return message, message
|
|
|
|
|
|
if __name__ == "__main__":
|
|
GetTicker() |