Skip to content

Instantly share code, notes, and snippets.

@slapec
Last active August 29, 2015 14:15
Show Gist options
  • Save slapec/2b08f2516cc69dcdd9e6 to your computer and use it in GitHub Desktop.
Save slapec/2b08f2516cc69dcdd9e6 to your computer and use it in GitHub Desktop.
Javascript function arguments extraction with PyV8
import PyV8
class Globals(PyV8.JSClass):
def __init__(self):
super(Globals, self).__init__()
self.coords = []
def PutMarkers(self, selector, coords):
coords = PyV8.convert(coords)
for coord in coords['data']:
self.coords.append({
'lat': float(coord['lat']),
'lng': float(coord['lng']),
'id': int(coord['id'])
})
def ready(self, function):
function()
def __call__(self, *args, **kwargs):
return self
def __getattr__(self, *args):
return self
script_content = """
$(document).ready(function(){
new AwesomeLibrary.PutMarkers('#map', {
data: [{id: '1', lat: '47.160971', lng: '16.4878386'}]
});
});"""
context_globals = Globals()
with PyV8.JSContext(context_globals) as ctx:
ctx.eval(script_content)
print(context_globals.coords)
@slapec
Copy link
Author

slapec commented Feb 8, 2015

This is a Python 3 project. See the related blog post (hungarian):
http://slpython.blogspot.hu/2015/02/javascript-fuggveny-parameterenek.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment