-
Notifications
You must be signed in to change notification settings - Fork 2
/
crypto-tickerv2.py
78 lines (70 loc) · 2.53 KB
/
crypto-tickerv2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /usr/bin/env python
import requests, json
from os.path import expanduser
home = expanduser('~')
def parse():
bitcoin = Bitcoin()
ethereum = Ethereum()
monero = Monero()
file_write(bitcoin, ethereum, monero)
def Bitcoin():
info = []
price_url = "http://coinmarketcap-nexuist.rhcloud.com/api/btc/price"
r = requests.get(price_url)
jsn_dict = r.json()
price = jsn_dict['usd']
volume_url = "http://coinmarketcap-nexuist.rhcloud.com/api/btc/volume"
t = requests.get(volume_url)
jsn_dict2 = t.json()
volume = jsn_dict2['usd']
change_url = "http://coinmarketcap-nexuist.rhcloud.com/api/btc/change"
e = requests.get(change_url)
change = e.json()
info.extend((price, volume, change))
return info
def Ethereum():
info = []
price_url = "http://coinmarketcap-nexuist.rhcloud.com/api/eth/price"
r = requests.get(price_url)
jsn_dict = r.json()
price = jsn_dict['usd']
volume_url = "http://coinmarketcap-nexuist.rhcloud.com/api/eth/volume"
t = requests.get(volume_url)
jsn_dict2 = t.json()
volume = jsn_dict2['usd']
change_url = "http://coinmarketcap-nexuist.rhcloud.com/api/eth/change"
e = requests.get(change_url)
change = e.json()
info.extend((price, volume, change))
return info
def Monero():
info = []
price_url = "http://coinmarketcap-nexuist.rhcloud.com/api/xmr/price"
r = requests.get(price_url)
jsn_dict = r.json()
price = jsn_dict['usd']
volume_url = "http://coinmarketcap-nexuist.rhcloud.com/api/xmr/volume"
t = requests.get(volume_url)
jsn_dict2 = t.json()
volume = jsn_dict2['usd']
change_url = "http://coinmarketcap-nexuist.rhcloud.com/api/xmr/change"
e = requests.get(change_url)
change = e.json()
info.extend((price, volume, change))
return info
def file_write(bitcoin, ethereum, monero):
bitprice = bitcoin[0]
bitvolume = bitcoin[1]
bitchange = bitcoin[2]
ethprice = ethereum[0]
ethvolume = ethereum[1]
ethchange = ethereum[2]
xmrprice = monero[0]
xmrvolume = monero[1]
xmrchange = monero[2]
file = open("%s/prices.txt" % home, 'w')
file.write("\nBitcoin: \n Price: $%.2f \n 24h Volume: $%s\n 24h Change: %s%% \n" % (bitprice, format(bitvolume, ','), bitchange))
file.write("Ethereum: \n Price: $%.2f\n 24h Volume: $%s\n 24h Change: %s%% \n" % (ethprice, format(ethvolume, ','), ethchange))
file.write("Monero: \n Price: $%.2f\n 24h Volume: $%s\n 24h Change: %s%%" % (xmrprice, format(xmrvolume, ','), xmrchange))
file.close
parse()