Removed uneccesary code and more comments
This commit is contained in:
		
							parent
							
								
									87789e8500
								
							
						
					
					
						commit
						9ad1111055
					
				
							
								
								
									
										8
									
								
								meuro.py
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								meuro.py
									
									
									
									
									
								
							@ -72,8 +72,9 @@ def reload(maxCacheSeconds=3600):
 | 
				
			|||||||
        with open('cache.json', 'r') as f:
 | 
					        with open('cache.json', 'r') as f:
 | 
				
			||||||
            cacheUpdate, cacheYears = json.loads(f.read())
 | 
					            cacheUpdate, cacheYears = json.loads(f.read())
 | 
				
			||||||
        if (datetime.now() - dparser.isoparse(cacheUpdate)).total_seconds() < maxCacheSeconds:
 | 
					        if (datetime.now() - dparser.isoparse(cacheUpdate)).total_seconds() < maxCacheSeconds:
 | 
				
			||||||
            # JSON does not allow integers as keys; so we convert them back here...
 | 
					            # JSON does not allow integers as keys; so we convert them back here
 | 
				
			||||||
            cacheYears = {int(y):{int(m):float(n) for m,n in ms.items()} for y,ms in cacheYears.items()}
 | 
					            cacheYears = {int(y):{int(m):float(n) for m,n in ms.items()} for y,ms in cacheYears.items()}
 | 
				
			||||||
 | 
					            # For every month we dont have data for, we assume the ECB nailed their 2%-target
 | 
				
			||||||
            _years = defaultdict(lambda: {m:1 + 0.02/12 for m in range(1,13)}, cacheYears)
 | 
					            _years = defaultdict(lambda: {m:1 + 0.02/12 for m in range(1,13)}, cacheYears)
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
    _years = _loadYearsTableWeb()
 | 
					    _years = _loadYearsTableWeb()
 | 
				
			||||||
@ -91,11 +92,6 @@ def _loadYearsTableWeb():
 | 
				
			|||||||
        inflation = float(vals[1])
 | 
					        inflation = float(vals[1])
 | 
				
			||||||
        years[year][month] = 1 + (inflation/100)/12
 | 
					        years[year][month] = 1 + (inflation/100)/12
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for year in years:
 | 
					 | 
				
			||||||
        months = years[year]
 | 
					 | 
				
			||||||
        for month in range(1,13):
 | 
					 | 
				
			||||||
            if month not in months:
 | 
					 | 
				
			||||||
                years[year][month] = 1 + 0.02/12 # Lets say the ECB archives their target
 | 
					 | 
				
			||||||
    with open('cache.json', 'w') as f:
 | 
					    with open('cache.json', 'w') as f:
 | 
				
			||||||
        f.write(json.dumps([datetime.now().isoformat(),years]))
 | 
					        f.write(json.dumps([datetime.now().isoformat(),years]))
 | 
				
			||||||
    return years
 | 
					    return years
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user