Commit d90cb8a7 authored by Stephane Mankowski's avatar Stephane Mankowski

Add new source "exchangeratesapi.io"

parent 9c3ea5ec
skrooge (2.23.0)
*Correction: cryptocompare fails if too many values are requested (>2000)
*Correction: Change icon for trackers by a "crosshairs"
*Feature: Add new source "exchangeratesapi.io"
-- Stephane MANKOWSKI <stephane@mankowski.fr> NotPlannedYet
......
......@@ -61,3 +61,4 @@ INSTALL(PROGRAMS skrooge-yahoodl.py DESTINATION ${KDE_INSTALL_DATADIR}/skrooge)
INSTALL(PROGRAMS skrooge-ratesapi.py DESTINATION ${KDE_INSTALL_DATADIR}/skrooge)
INSTALL(PROGRAMS skrooge-cryptocompare.py DESTINATION ${KDE_INSTALL_DATADIR}/skrooge)
INSTALL(PROGRAMS skrooge-coinmarketcap.py DESTINATION ${KDE_INSTALL_DATADIR}/skrooge)
INSTALL(PROGRAMS skrooge-exchangerates.py DESTINATION ${KDE_INSTALL_DATADIR}/skrooge)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#**************************************************************************
#* Copyright (C) 2020 by S. MANKOWSKI / G. DE BURE support@mankowski.fr
#* Redistribution and use in source and binary forms, with or without
#* modification, are permitted provided that the following conditions
#* are met:
#*
#* 1. Redistributions of source code must retain the above copyright
#* notice, this list of conditions and the following disclaimer.
#* 2. Redistributions in binary form must reproduce the above copyright
#* notice, this list of conditions and the following disclaimer in the
#* documentation and/or other materials provided with the distribution.
#*
#* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
#* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
#* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
#* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
#* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
#* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
#* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#**************************************************************************
import urllib.request
import json
import sys
import datetime
units=sys.argv[1].split('-')
mode = sys.argv[4]
url = 'https://api.exchangeratesapi.io/history?start_at='+sys.argv[3]+'&end_at='+sys.argv[2]+'&symbols='+units[1]+'&base='+units[0]
f = urllib.request.urlopen(url)
print("Date,Price")
data = json.loads(f.read().decode('utf-8'))['rates']
output = []
for item in data:
d = datetime.datetime.strptime(item, '%Y-%m-%d')
if mode == '1d' or (mode=='1wk' and d.isoweekday()==1) or (mode=='1mo' and d.day==1) or (mode=='1mo' and d.day==2 and not datetime.date(d.year, d.month, d.day-1).strftime('%Y-%m-%d') in data) or (mode=='1mo' and d.day==3 and not datetime.date(d.year, d.month, d.day-1).strftime('%Y-%m-%d') in data and not datetime.date(d.year, d.month, d.day-2).strftime('%Y-%m-%d') in data):
output.append(item+","+str(data[item][units[1]]))
for item in sorted(output):
print(item)
[Desktop Entry]
Name=exchangeratesapi.io
Comment=You can get the list of available quotes from <a href="https://exchangeratesapi.io/">exchangeratesapi.io</a>.Then, enter the <expected quote>-<in the expected currency>. Example: if you want BTC in USD, you must enter BTC-USD.
Encoding=UTF-8
Icon=skrooge
Type=Service
X-KDE-ServiceTypes=skrooge/source
X-Krunner-ID=exchangeratesapi
X-KDE-PluginInfo-Author=Stephane MANKOWSKI,miraks
X-KDE-PluginInfo-Email=stephane@mankowski.fr
X-KDE-PluginInfo-Name=exchangeratesapi.io
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=https://skrooge.org/
X-KDE-PluginInfo-Category=Plugins
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
#To know if this plugin needs a key API
X-SKROOGE-keyAPI=true
#The url or the command line to get the list of accounts in the standard output, something like this:
#%1 will be replaced by the internet code of the unit
#%2 will be replaced by the current day in format yyyy-MM-dd
#%3 will be replaced by the previous date in format yyyy-MM-dd
#%4 will be replaced by the interval
#%5 will be replaced by the key API
#Example:
# X-SKROOGE-url=https://server/?s=%1
# or
# X-SKROOGE-script=mydownloadscript %1
#This parameter is MANDATORY
X-SKROOGE-script=skrooge-exchangerates.py "%1" "%2" "%3" "%4" "%5"
#The mode (HTML or CSV or CSVR). In HTML mode, only one value will be extracted from downloaded page. In CSV mode, a value per line will be extracted. CSVR means CSV in reverse mode
X-SKROOGE-mode=CSVR
#Regular expression to capture the price of the quote
#This parameter is not MANDATORY.
X-SKROOGE-price=[^,]*,([^,]*)
#Regular expression to capture the date of the quote
#This parameter is not MANDATORY.
X-SKROOGE-date=([^,]*),.*
#The date format
X-SKROOGE-dateformat=yyyy-MM-dd
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment