Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.