Skip to content

Instantly share code, notes, and snippets.

@opalczynski
Created September 16, 2021 16:52
Show Gist options
  • Select an option

  • Save opalczynski/c6ebe744564050e72882bcc2754ad76b to your computer and use it in GitHub Desktop.

Select an option

Save opalczynski/c6ebe744564050e72882bcc2754ad76b to your computer and use it in GitHub Desktop.
Process the data from YAML file
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