Last active
August 29, 2015 14:15
-
-
Save slapec/2b08f2516cc69dcdd9e6 to your computer and use it in GitHub Desktop.
Javascript function arguments extraction with PyV8
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a Python 3 project. See the related blog post (hungarian):
http://slpython.blogspot.hu/2015/02/javascript-fuggveny-parameterenek.html