Added documentation and fixed typos
This commit is contained in:
parent
0cc00fdf11
commit
fc0019e57c
@ -17,7 +17,7 @@ Converts the given amount of euros to meuros for the given date. (wholeCents mea
|
|||||||
#### meuroToEuro(meur, date=None, wholeCents=True)
|
#### meuroToEuro(meur, date=None, wholeCents=True)
|
||||||
Converts the given amount of meuros to euros for the given date. (wholeCents means it rounds to two decimal places)
|
Converts the given amount of meuros to euros for the given date. (wholeCents means it rounds to two decimal places)
|
||||||
#### liveValue(eur, interval=10)
|
#### liveValue(eur, interval=10)
|
||||||
Print the current amount of meuros for the given amunt of euros every interval-seconds. Comes in handy when you want to watch your live saving slowly fade away thanks to inflation.
|
Print the current amount of meuros for the given amunt of euros every interval-seconds. Comes in handy when you want to watch your life savings slowly fade away thanks to inflation.
|
||||||
##### When the date is set to None the current date is used. Otherwise a datetime-object is expected
|
##### When the date is set to None the current date is used. Otherwise a datetime-object is expected
|
||||||
## Caveats
|
## Caveats
|
||||||
The ecb only gives an estimate for the inflation of the last month and no data for the current month.
|
The ecb only gives an estimate for the inflation of the last month and no data for the current month.
|
||||||
|
13
meuro.py
13
meuro.py
@ -2,10 +2,11 @@ import requests
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from dateutil import relativedelta
|
from dateutil import relativedelta
|
||||||
|
|
||||||
|
# Ugly code thats outside of any function
|
||||||
url = 'https://sdw.ecb.europa.eu/quickviewexport.do?SERIES_KEY=122.ICP.M.U2.N.000000.4.ANR&type=csv'
|
url = 'https://sdw.ecb.europa.eu/quickviewexport.do?SERIES_KEY=122.ICP.M.U2.N.000000.4.ANR&type=csv'
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
lines = resp.text.split('\n')[6:]
|
lines = resp.text.split('\n')[6:]
|
||||||
years = {}
|
years = {} # Will later contain the monthly factor of inflation (~1.0016667) for every month
|
||||||
for line in lines:
|
for line in lines:
|
||||||
vals = line.split(',')
|
vals = line.split(',')
|
||||||
year = int(vals[0][:4])
|
year = int(vals[0][:4])
|
||||||
@ -21,6 +22,9 @@ for year in years:
|
|||||||
if month not in months:
|
if month not in months:
|
||||||
years[year][month] = 1 + 0.02/12 # Lets say the ECB archives their target
|
years[year][month] = 1 + 0.02/12 # Lets say the ECB archives their target
|
||||||
|
|
||||||
|
# Gives you the exchange rate between euros and meuros for the given date.
|
||||||
|
# (Should always be a float < 1)
|
||||||
|
# date should be either a datetime-object or None (= current date)
|
||||||
def exchangeRate(date=None):
|
def exchangeRate(date=None):
|
||||||
if date==None:
|
if date==None:
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
@ -47,13 +51,18 @@ def exchangeRate(date=None):
|
|||||||
akk *= inflationThisMonth
|
akk *= inflationThisMonth
|
||||||
|
|
||||||
return 1/akk
|
return 1/akk
|
||||||
|
# Converts the given amount of euros to meuros for the given date. (wholeCents means it rounds to two decimal places)
|
||||||
|
# date should be either a datetime-object or None (= current date)
|
||||||
def euroToMeuro(eur,date=None,wholeCents=True):
|
def euroToMeuro(eur,date=None,wholeCents=True):
|
||||||
return round(eur * factorForDate(date),[64,2][wholeCents])
|
return round(eur * factorForDate(date),[64,2][wholeCents])
|
||||||
|
|
||||||
|
# Converts the given amount of meuros to euros for the given date. (wholeCents means it rounds to two decimal places)
|
||||||
|
# date should be either a datetime-object or None (= current date)
|
||||||
def meuroToEuro(meur,date=None,wholeCents=True):
|
def meuroToEuro(meur,date=None,wholeCents=True):
|
||||||
return round(meur / factorForDate(date),[64,2][wholeCents])
|
return round(meur / factorForDate(date),[64,2][wholeCents])
|
||||||
|
|
||||||
|
# Print the current amount of meuros for the given amunt of euros every <interval>-seconds.
|
||||||
|
# Comes in handy when you want to watch your life savings slowly fade away thanks to inflation.
|
||||||
def liveValue(eur,interval=10):
|
def liveValue(eur,interval=10):
|
||||||
import time
|
import time
|
||||||
while True:
|
while True:
|
||||||
|
Loading…
Reference in New Issue
Block a user