File indexing completed on 2024-05-12 05:08:48
0001 #!/usr/bin/env python3 0002 # -*- coding: utf-8 -*- 0003 #*************************************************************************** 0004 #* SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0005 #* SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0006 #* SPDX-License-Identifier: GPL-3.0-or-later 0007 #*************************************************************************** 0008 0009 from urllib.request import Request, urlopen 0010 import json 0011 import sys 0012 0013 units=sys.argv[1].split('-') 0014 # url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/historical?symbol='+units[0]+'&convert='+units[1]+'&time_start='+sys.argv[2]+'T00:00:00.000Z&time_end='+sys.argv[3]+'T23:59:59.000Z' 0015 url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol='+units[0]+'&convert='+units[1] 0016 0017 req = Request(url) 0018 req.add_header("X-CMC_PRO_API_KEY", sys.argv[5]) 0019 f = urlopen(req) 0020 print("Date,Price") 0021 item=json.loads(f.read().decode('utf-8'))['data'][units[0]]['quote'][units[1]] 0022 print(item["last_updated"][0:10]+','+str(item["price"]))