Here is a solution I found after much searching. It really should not be that hard. I hope it helps somebody. If anybody has a simpler solution, preferably Python-only, please let us know!
Note: Python2.
In a separate cell:
%%javascript
var kernel = IPython.notebook.kernel;
var thename = window.location.href;
var command = "notebook_url = " + "'"+thename+"'";
kernel.execute(command);
in the next cell:
import urllib2
nb_filename = urllib2.url2pathname(notebook_url).split('/')[-1]
if nb_filename.endswith('#'):
nb_filename = nb_filename[:-1]
I have no idea why I am getting the '#' character at the end.