Skip to content

Commit ae5a97b

Browse files
author
Gabriel Hodoroaga
committed
Add more command arguments, update examples
1 parent 39ee739 commit ae5a97b

File tree

16 files changed

+73
-27
lines changed

16 files changed

+73
-27
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
venv/
22
build/
3+
dist/
4+
tmp/
5+
out/
36

47
*.pyc
58
.DS_Store

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Use Jinja2 templates to format data from CSV files.
55
## Example usage
66

77
```bash
8-
jinja-csv -i example/test.csv -t example/example.j2 -o example/output.txt
8+
jinja-csv -i example/users.csv -t example/users.j2 -o example/users.sql
99

1010
```
1111

dist/jinja-csv-0.1.tar.gz

-4.8 KB
Binary file not shown.
-6.35 KB
Binary file not shown.
File renamed without changes.
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
{% set avgrating = (rows|sumcolumns(['Rating1', 'Rating2']))/(rows|length)/2 %}
2-
3-
{% for row in rows|sortedby('Rating2') %}
41

52
{# you can specify columns by both their name and their index #}
63
Hello {{ row[0] }} {{ row['Last Name'] }},
74
The {{ row['State'] }} branch of ACME Corporation would like to publish your comment "{{ row.Comments }}", which you provided in the Google Form in our latest publication, The ACME {{ row['State'] }} Times.
85

9-
{% if row['Rating1']|int < avgrating %}
6+
{% if row['Rating1']|int < 3 %}
107
Additionally, since you rated us less than the average rating of {{ avgrating }} on the Google Form, we would like to ask for feedback on what factors led to your this rating. This feedback will not be shared publicly.
118

129
{% elif row['Rating1']|int >= 9 %}
@@ -17,4 +14,3 @@ Thanks,
1714
Johnny Cossack
1815
CEO of ACME Corporation
1916

20-
{% endfor %}

example/users.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
userid,role,pass,name
2+
admin1,admin,password,Administrator
3+
user1,viewer,password,User 1
4+
user2,editor;admin,password,User 2

example/users.j2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- begin script
2+
{% for row in rows %}
3+
-- begin user script : {{row['userid']}}
4+
INSERT INTO user(userid,pass,name) VALUES ('{{row['userid']}}','{{row['pass']}}','{{row['name']}}');
5+
{% for role in row['role'].split(';') %}
6+
INSERT INTO role(userid,role) VALUES ('{{row['userid']}}','{{role.strip()}}');
7+
{% endfor %}
8+
-- end user script
9+
{% endfor %}
10+
-- end script

scripts/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
python3 setup.py sdist bdist_wheel

scripts/run_local.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
cd src
3+
python3 -m jinja_csv.jinja_csv -i ../example/users.csv -t ../example/users.j2
4+
cd ..

0 commit comments

Comments
 (0)