Skip to content

Instantly share code, notes, and snippets.

@hamletbatista
Last active September 28, 2019 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamletbatista/2cd87f5a843de939f490b49eb9f48eae to your computer and use it in GitHub Desktop.
Save hamletbatista/2cd87f5a843de939f490b49eb9f48eae to your computer and use it in GitHub Desktop.
from jinja2 import Template
js_template="""
function drawChart137() {
var columns = {{columns}};
var title = "{{title}}";
return [title, columns];
}
"""
template=Template(js_template)
js_script=template.render(title=title, columns = columns)
from py_mini_racer import py_mini_racer
ctx = py_mini_racer.MiniRacer()
ctx.eval(js_script)
title, columns = ctx.call("drawChart137")
def build_dict(script_list):
wait_times = dict()
ctx = py_mini_racer.MiniRacer()
for script in script_list:
#title and columns are in JavaScript format
title, columns = extract_dates(script.text)
print(title)
js_template="""
function drawChart137() {
var columns = {{columns}};
var title = "{{title}}";
return [title, columns];
}
"""
template=Template(js_template)
#generate JavaScript dynamically and execute it
js_script=template.render(title=title, columns = columns)
ctx.eval(js_script)
#title and columns are Python objects
title, columns = ctx.call("drawChart137")
#build up wait times dictionary for each ride
wait_times[title] = columns
return wait_times
wait_times_by_ride = build_dict(all_rides)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment