-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdobi_zneske.py
More file actions
77 lines (64 loc) · 2.27 KB
/
Copy pathdobi_zneske.py
File metadata and controls
77 lines (64 loc) · 2.27 KB
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
import urllib.request, json, time
naslov = 'https://www.bitstamp.net/api/ticker_hour/'
valute = 'https://bittrex.com/api/v1.1/public/getcurrencies'
def dobi_podatke(stran):
'''Dobi podatke iz spleta in jih pretvori v slovar'''
with urllib.request.urlopen(stran) as url:
podatki = json.loads(url.read().decode())
cas = datum(podatki.get('timestamp'))
podatki['datetime'] = cas
return podatki
def dobi_podatke_coin_market():
'''Please limit requests to no more than 10 per minute.
Endpoints update every 5 minutes.'''
stran = 'https://api.coinmarketcap.com/v1/ticker/?convert=EUR'
sez = []
with urllib.request.urlopen(stran) as url:
podatki = json.loads(url.read().decode())
return podatki
def vrni_podatke():
slo = {}
for el in dobi_podatke_coin_market():
slo[el.get('id','')] = (float(el.get('price_usd',0.0)),float(el.get('price_eur',0.0)),el.get('last_updated',0))
return slo
def datum(podatki):
'''pretvori in vrne čas v obliki leto-mesec-dan ura:minuta:sekunde'''
niz = ""
if podatki is not None:
k=0
for x in time.gmtime(int(podatki))[:]:
niz += izpis_datuma(x, k)
k+=1
else:
k=0
for x in time.gmtime()[:]:
niz += izpis_datuma(x, k)
k+=1
return niz[:-8]
def izpis_datuma(x, k):
'''izpis'''
niz = ''
if k<2:
niz += str(x)+'-'
elif k==2:
niz+= str(x) + ' '
else:
niz+= str(x)+':'
return niz
def imena_valut(naslov='https://bittrex.com/api/v1.1/public/getcurrencies'):
sez = dobi_podatke(naslov)['result']
seznam_valut=[]
for i in range(len(sez)):
if sez[i]['IsActive']:
ime = sez[i]['CurrencyLong']
ime_k = sez[i]['Currency']
seznam_valut.append((ime_k,ime,ime.lower()))
return seznam_valut
def vrednost_valut():
vrednost_valute = dobi_podatke('https://www.bitstamp.net/api/ticker_hour/')
trenutna_vrednost = vrednost_valute['last']
valute = [('BitCoin', trenutna_vrednost)]
return valute
def generiraj_spletno(ime):
spletna = 'https://api.coinmarketcap.com/v1/ticker/'
return spletna + ime.lower()