Created
September 16, 2021 16:52
-
-
Save opalczynski/c6ebe744564050e72882bcc2754ad76b to your computer and use it in GitHub Desktop.
Process the data from YAML file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_data(data_path="./data.yml"): | |
| with open(data_path, "r") as f: | |
| data = yaml.load(f, Loader=yaml.FullLoader) | |
| # we need to process the data a bit to match the HTML template; | |
| for invoice in data["invoices"]: | |
| # here we simply defined customer and issuer entity in data to avoid lot of typing; | |
| invoice["customer"] = data["customer"][invoice["customer"]] | |
| invoice["issuer"] = data["issuer"][invoice["issuer"]] | |
| # we also needs to add total to items: | |
| total = 0 | |
| for item in invoice["items"]: | |
| total += float(item["price"]) * int(item["quantity"]) | |
| invoice["total"] = total | |
| return data["invoices"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment