Skip to content

Commit

Permalink
feat(devtools): add experimantal history page
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Jan 15, 2022
1 parent a6955bf commit 9210dab
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
43 changes: 32 additions & 11 deletions apps/tools/librelingo_tools/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ def get_template(filename):
return env.get_template(filename)


def generate_html(start_time, end_time, links, outdir):
def generate_history_html(history, outdir):
template = get_template("history.html")
html = template.render(
history=history,
title="LibreLingo history",
)

with open(os.path.join(outdir, "history.html"), "w") as fh:
fh.write(html)


def generate_index_html(start_time, end_time, links, outdir):
template = get_template("courses.html")
html = template.render(
start_time=start_time,
Expand Down Expand Up @@ -92,6 +103,24 @@ def generate_course(links, courses_data, sdir, reldir, outdir, tdir, course_dir)
courses_data[tdir] = json.load(fh)


def save_history(history_file, start_time, courses_data, outdir):
with open(history_file, "a") as fh:
json.dump(
{"courses": courses_data, "date": start_time},
fh,
sort_keys=True,
default=myconverter,
)
fh.write("\n")
shutil.copy(history_file, os.path.join(outdir, "history.json"))
history = []
with open(history_file) as fh:
for line in fh:
res = json.loads(line)
history.append(res)
generate_history_html(history, outdir)


def main():
args = get_args()
if args.log:
Expand Down Expand Up @@ -144,16 +173,8 @@ def main():
with open(os.path.join(outdir, "courses.json"), "w") as fh:
json.dump(courses_data, fh, sort_keys=True)
if args.history:
with open(args.history, "a") as fh:
json.dump(
{"courses": courses_data, "date": start_time},
fh,
sort_keys=True,
default=myconverter,
)
fh.write("\n")
shutil.copy(args.history, os.path.join(outdir, "history.json"))
generate_html(start_time, end_time, links, outdir)
save_history(args.history, start_time, courses_data, outdir)
generate_index_html(start_time, end_time, links, outdir)


if __name__ == "__main__":
Expand Down
13 changes: 13 additions & 0 deletions apps/tools/librelingo_tools/templates/history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% include 'central/header.html' %}

<table>
<tr><th>Date</th><th>ladino-from-english</th></tr>
{% for event in history %}
{% if event.courses["ladino-from-english"] %}
<tr><td>{{event.date}}</td><td>{{event.courses["ladino-from-english"].source_phrases}} / {{event.courses["ladino-from-english"].source_words}} to {{event.courses["ladino-from-english"].target_phrases}} / {{event.courses["ladino-from-english"].target_words}}</td></tr>
{% endif %}
{% endfor %}
</table>

{% include 'central/footer.html' %}

1 comment on commit 9210dab

@vercel
Copy link

@vercel vercel bot commented on 9210dab Jan 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.