Last active
September 28, 2019 16:54
-
-
Save hamletbatista/2cd87f5a843de939f490b49eb9f48eae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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