-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.py
60 lines (44 loc) · 2 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from datapackage_pipelines.wrapper import ingest, spew
from datapackage_pipelines.utilities.resources import PROP_STREAMING
import logging
import os, sys, shutil
import template_functions
LABELS = {
"title": ("מידברן 2018 - אינדקס מחנות נושא",
"Midburn 2018 - Theme Camps Index"),
"contact_name": ("שם", "Name"),
"contact_email": ("אימייל", "Email"),
"contact_details": ("פרטי התקשרות", "Contact Details"),
"description": ("תיאור", "Description"),
"members": ("פתוח להשתתפות", "Participants welcome")
}
parameters, datapackage, resources = ingest()
all_camps = []
for resource in resources:
for camp in resource:
all_camps.append(camp)
def get_context(**context):
context["labels"] = {label_id: label[{"he":0,"en":1}[context["lang"]]] for label_id, label in LABELS.items()}
return template_functions.get_context(context)
def get_camp_context(camp):
for k in ["name", "leader_name", "leader_email", "description"]:
if not camp[k] or camp[k] == "NULL":
camp[k] = ""
else:
camp[k] = camp[k].strip()
return camp
def get_camps(lang):
for index, camp in enumerate(all_camps):
yield get_camp_context({"index": index,
"id": camp["camp_name_en"].replace(' ', '').lower(),
"name": camp["camp_name_{}".format(lang)],
"leader_name": camp["name"],
"leader_email": camp["email"],
"description": camp.get("camp_desc_{}".format(lang)),
"status": camp.get("status")})
env = template_functions.get_jinja_env()
for lang in ["he", "en"]:
template_functions.build_template(env, "list.html",
get_context(lang=lang, camps=get_camps(lang)),
"public/index_{}.html".format(lang))
spew(dict(datapackage, resources=[]), [])