Skip to content

Instantly share code, notes, and snippets.

@edhiley
Created August 30, 2013 23:21
Show Gist options
  • Save edhiley/6395213 to your computer and use it in GitHub Desktop.
Save edhiley/6395213 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "Url Template"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "# url template\n\nusing uritemplate"
},
{
"cell_type": "code",
"collapsed": false,
"input": "from uritemplate import expand\nreport_template = \"http://{domain}/report/summary?startTime={startTime}&endTime={endTime}\"\nurl = expand(report_template, \n {\n \"domain\": \"foo.com\", \n \"startTime\": \"atime\", \n \"endTime\": \"btime\"})\nassert url == \"http://foo.com/report/summary?startTime=atime&endTime=btime\"",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 18
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Or just ..."
},
{
"cell_type": "code",
"collapsed": false,
"input": "report_template = \"http://{domain}/report/summary?startTime={startTime}&endTime={endTime}\"\nreport_template.format(\n domain=\"foo.com\", \n startTime=\"atime\", \n endTime=\"btime\")\nassert url == \"http://foo.com/report/summary?startTime=atime&endTime=btime\"",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment