-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto-info.py
126 lines (99 loc) · 3.39 KB
/
crypto-info.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from bs4 import BeautifulSoup
from urllib.request import urlopen as req
import json,csv
import pandas as pd
def getJSONResponse(extension):
base_url = 'https://min-api.cryptocompare.com/data/'
complete_url = base_url + extension
response = req(complete_url)
data = response.read()
soup = BeautifulSoup(data,"html.parser")
json_data = json.loads(str(soup))
return json_data
def getAllCoinDetails():
coinlist = []
all_coins = getJSONResponse('all/coinlist')
data_coins = all_coins['Data']
print(len(data_coins))
cnt = 1
#print(data_coins)
for coin_details in data_coins:
for k,v in data_coins[coin_details].items():
if k == 'CoinName':
coin_name = str(v)
if k == 'FullName':
coin_full_name = str(v)
if k == 'Algorithm':
coin_algorithm = str(v)
if k == 'ProofType':
coin_prooftype = str(v)
if k == 'TotalCoinSupply':
coin_tcs = str(v)
each_coin_detail = [coin_name,coin_full_name,coin_algorithm,coin_prooftype,coin_tcs]
print(cnt)
print(each_coin_detail)
coinlist.append(each_coin_detail)
cnt += 1
my_df = pd.DataFrame(coinlist)
my_df.to_csv('my_csv.csv', index=False, header=['Coin Name','Complete Name','Algorithm','Proof Type','Total Coin Supply'])
def getCryptoPriceInOtherCurrency():
print("\nConverts 1 unit of currency to another currency.")
print("\nExample: 1 BTC EQUALS ? in USD.")
#https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=BTC,USD,EUR
fromsystem = str(input("\nEnter input currency symbol: ").upper())
tosys_num = int(input("\nEnter number of output currencies: "))
tosys_str = ""
print("\nEnter output currency symbols: ")
for i in range(tosys_num):
name = str(input("").upper())
tosys_str += name
tosys_str += ","
tosystems = tosys_str.rstrip(',')
try:
data = getJSONResponse('price?fsym=' + fromsystem + "&tsyms=" + tosystems)
for k,v in data.items():
value = str(k)
print("\n1 " + fromsystem + " equals " ,str(v) + " " ,str(k))
except Exception as e:
print("Error." + str(e))
def getMatrixCurrencyPrices():
print("\nConverts 1 unit of currency to another currency.")
print("\nExample: 1 BTC EQUALS ? in USD.")
#https://min-api.cryptocompare.com/data/price?fsym=ETH,DASH&tsyms=BTC,USD,EUR
fromsys_num = int(input("\nEnter number of input currencies: "))
fromsys_str = ""
print("\nEnter input currency symbols: ")
for i in range(fromsys_num):
name = str(input("").upper())
fromsys_str += name
fromsys_str += ","
fromsystems = fromsys_str.rstrip(',')
print(fromsystems)
tosys_num = int(input("\nEnter number of output currencies: "))
tosys_str = ""
print("\nEnter output currency symbols: ")
for i in range(tosys_num):
name = str(input("").upper())
tosys_str += name
tosys_str += ","
tosystems = tosys_str.rstrip(',')
try:
data = getJSONResponse('pricemulti?fsyms=' + fromsystems + "&tsyms=" + tosystems)
for ele in data:
print("\n1 "+ ele + " equals: ")
for k,v in data[ele].items():
print("\n" ,str(v) + " " ,str(k))
except Exception as e:
print("Error." + str(e))
def main():
a = '''1. List all coin details and export it to csv.\n2. Convert one cryptocurrency to other currencies.\n3. Convert multiple cryptocurrencies to other currencies.'''
print(a)
choice = int(input("\nEnter choice:\n"))
if choice == 1:
getAllCoinDetails()
if choice == 2:
getCryptoPriceInOtherCurrency()
if choice == 3:
getMatrixCurrencyPrices()
if __name__ == '__main__':
main()