progala / ttl255.com Goto Github PK
View Code? Open in Web Editor NEWttl255.com - Resources
License: MIT License
ttl255.com - Resources
License: MIT License
Hi I came across your examples. Need a little help with the below code to render Jinja template. I am going to be using a file as a data source for account_details below. Can you please tell me how I can make it work?
from jinja2 import Environment, FileSystemLoader
from pathlib import Path
account_details = [
{'alias': 'MEMBER1', 'region': 'us-east-1', 'member_account_id': '0000000000', 'ccs_mem_account_id': '0000000000'},
{'alias': 'MEMBER2', 'region': 'us-east-2', 'member_account_id': '0000000000', 'ccs_mem_account_id': '0000000000'}
]
def task_render():
""" "Render jinja2 templates.
Yields:
Render task for each jinja2 template file.
"""
cwd = Path(".")
environment = Environment(loader=FileSystemLoader(cwd))
j2_templates = cwd.glob("*.j2")
def render_template(template_path):
"""Render template.
Args:
template_path: Path to jinja2 template file
"""
template = environment.get_template(str(template_path))
with open(f"{template_path.stem}", "w") as output_file:
output_file.write(template.render(data=account_details))
for j2_template in j2_templates:
target = f"_{j2_template.stem}"
yield {
"name": target,
"actions": [
(
render_template,
[j2_template],
{},
),
],
"file_dep": [j2_template],
"targets": [target],
"clean": True,
}
Love the tool! Just wanted to know if we could add a separate style sheet for a dark mode toggle? Would be much easier on the eyes for me.
Hi,
What is the code to Dictionaries As Variables and what does the template file look like?
The https://ttl255.com/jinja2-tutorial-part-1-introduction-and-variable-substitution post is great. I've leaned alot about jinja2 and python, I can hard code a value to a template, but how do you use a dictionary to populate a template? Your post does not have code to explain.
Thanks!!!
Hi,
I have this coding to fetch CSV content from a Git repo and write it in a file:
{% set gitUrl = 'https://git.example.com/api/v1/repos/ABC/stats/raw/exportlocationlist.csv' %}
{% set headers = {"Authorization": "token 1234abcd1234abcd"} %}
{% set contentCsv = salt['http.query'](gitUrl, header_dict=headers)['body'] %}
write_to_file:
file.managed:
- name: /tmp/contentCsv
- contents: {{ contentCsv }}
- makedirs: True
- overwrite: True
However this returns error:
Rendering SLS 'base:manager_org_1.stc-test-automnt-manila-backup' failed: could not find expected ':'; line 12
This is an extract of the content of the CSV:
body:
TIME;DATE;ID;PATH;PREF;NAME;SID;AZ
1687174100;19062023-132820;05bc1a8f-3953-4ea7-a716-19631030a669;10.180.2.99:/share_041c6c87_5d87_4cd4_b344_f20bd2164f75;True;backupAM3;am3;eu-de-1d
1687174100;19062023-132820;eb81e7b7-79fc-41da-9d02-6d1fdda3e10b;10.180.2.107:/share_041c6c87_5d87_4cd4_b344_f20bd2164f75;False;backupAM3;am3;eu-de-1d
1687240964;20062023-080244;1d1fe0be-0f59-44bf-9139-8768c423192b;10.180.3.242:/share_9d8031f2_68aa_449c_9257_a27b40b17ba2;False;backupAMH;amh;eu-de-2a
My goal is to write the content of field PATH in a variable after selecting PREF=true and NAME=backup where is another variable.
Could you please advise how to fix this issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.