[D66] frankfurter.app

A.OUT jugg at ziggo.nl
Tue Oct 22 18:18:46 CEST 2019


Simpel conversiescriptje voor uw pleuro's:

rene at NUC:~/bin$ euro GBP
Date:  2019-10-22
EUR/GBP: 0.86065


------------------------8<----------------------
#!/usr/bin/env python3
# euro currency converter
# A.OUT-2019
#
# https://www.frankfurter.app/docs/#usage
# The Frankfurter API tracks foreign exchange references rates published
# by the European Central Bank. The # data refreshes around 16:00 CET
# every working day.

import pycurl
import json
import sys
from io import BytesIO

buffer = BytesIO()
c = pycurl.Curl()
arglen= len(sys.argv)
if arglen==1:
	print("euro TO")
	print("euro list")
	exit(0)
tocur=sys.argv[1]
listcur=0
if tocur=='list':
	listcur=1
	c.setopt(c.URL, 'https://frankfurter.app/currencies')
else:
	c.setopt(c.URL, 'https://frankfurter.app/latest?to='+tocur)
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()

body = buffer.getvalue()
# Body is a byte string.
# We have to know the encoding in order to print it to a text file
# such as standard output.
# print(body.decode('iso-8859-1'))
s = json.loads(body)
if listcur:
	for i in s:
		print(i, s[i])
	exit(0)
print("Date: " , s['date'])
print("EUR/"+tocur+":", s['rates'][tocur])


More information about the D66 mailing list