Post by amber on Jun 13, 2018 14:50:50 GMT 1
Hej!
Här kommer mitt bidrag till modul 10. Jag har skrivit två script.
Det första scriptet, get_currencies.py, hämtar hem en lista på alla kryptovalutor från coinmarketcap.com.
Det andra scriptet, get_markets.sh, hämtar hem URL:er till marknadsplatser där en viss kryptovaluta handlas.
$ cat get_currencies.py
$ ./get_currencies.py
*** Fetching list of cryptocurrencies and saving to file 2018-06-13_nr_of_coins_1628 ...please wait!
$ wc -l 2018-06-13_nr_of_coins_1628
1628 2018-06-13_nr_of_coins_1628
$ head 2018-06-13_nr_of_coins_1628
BTC,Bitcoin,bitcoin
LTC,Litecoin,litecoin
NMC,Namecoin,namecoin
TRC,Terracoin,terracoin
PPC,Peercoin,peercoin
NVC,Novacoin,novacoin
FTC,Feathercoin,feathercoin
MNC,Mincoin,mincoin
FRC,Freicoin,freicoin
IXC,Ixcoin,ixcoin
$ cat get_markets.sh
$ ./get_markets.sh namecoin
bittylicious.com
bleutrade.com
bx.in.th
poloniex.com
tradebytrade.com
tuxexchange.com
wex.nz
www.altcointrader.co.za
www.cryptopia.co.nz
www.livecoin.net
www.southxchange.com
yobit.net
$ ./get_markets.sh bitcoin | wc -l
87
Här kommer mitt bidrag till modul 10. Jag har skrivit två script.
Det första scriptet, get_currencies.py, hämtar hem en lista på alla kryptovalutor från coinmarketcap.com.
Det andra scriptet, get_markets.sh, hämtar hem URL:er till marknadsplatser där en viss kryptovaluta handlas.
$ cat get_currencies.py
#!/usr/bin/python
# output to file Y-m-d
import datetime
import requests
url = "https://api.coinmarketcap.com/v2/listings/"
r = requests.get(url)
nr = r.json()["metadata"]['num_cryptocurrencies']
filename = datetime.datetime.fromtimestamp(int(r.json()["metadata"]["timestamp"])).strftime('%Y-%m-%d_') + "nr_of_coins_" + str(nr)
print "*** Fetching list of cryptocurrencies and saving to file ",
print filename,
print " ...please wait!"
file = open(filename, 'w')
i = 0
while i < nr:
# {u'symbol': u'FTO', u'website_slug': u'futurocoin', u'id': 2846, u'name': u'FuturoCoin'}
coin = r.json()["data"][i]
file.write(coin['symbol'] + "," + coin['name'] + "," + coin["website_slug"] + "\n")
i = i + 1
file.close()
$ ./get_currencies.py
*** Fetching list of cryptocurrencies and saving to file 2018-06-13_nr_of_coins_1628 ...please wait!
$ wc -l 2018-06-13_nr_of_coins_1628
1628 2018-06-13_nr_of_coins_1628
$ head 2018-06-13_nr_of_coins_1628
BTC,Bitcoin,bitcoin
LTC,Litecoin,litecoin
NMC,Namecoin,namecoin
TRC,Terracoin,terracoin
PPC,Peercoin,peercoin
NVC,Novacoin,novacoin
FTC,Feathercoin,feathercoin
MNC,Mincoin,mincoin
FRC,Freicoin,freicoin
IXC,Ixcoin,ixcoin
$ cat get_markets.sh
#!/bin/sh
# return list of URLs to exchanges for a coin (Default to bitcoin if no argument is given)
curl -s https://coinmarketcap.com/currencies/${1-bitcoin}/#markets | grep -E 'data-sort.*a href' | grep -o -P '(?<=a\ href=").*(?=" target)' | awk -F/ '{print $3}' | sort | uniq
$ ./get_markets.sh namecoin
bittylicious.com
bleutrade.com
bx.in.th
poloniex.com
tradebytrade.com
tuxexchange.com
wex.nz
www.altcointrader.co.za
www.cryptopia.co.nz
www.livecoin.net
www.southxchange.com
yobit.net
$ ./get_markets.sh bitcoin | wc -l
87