extremeheat / JSPyBridge

🌉. Bridge to interoperate Node.js and Python
MIT License
701 stars 55 forks source link

problem to create a object of a js class #85

Closed Shuvadip-Ghosh closed 1 year ago

Shuvadip-Ghosh commented 1 year ago

This is the Javascript code I want to write in Python

import { META } from '@consumet/extensions';
const anilist = new META.Anilist();

function test(id) {
    anilist.fetchAnimeInfo(id).then(data => {
        console.log(data);
      })
}

test("20")

This is what I have written in Python till now

from javascript import require

Meta = require("@consumet/extensions")
anilist = Meta.Anilist()

This is the error I get

TypeError: 'NoneType' object is not callable

Thanks to anyone who would help me do this.

extremeheat commented 1 year ago

When you do import { META } from ... in JS, you're doing the same as:

const { META } = require(...) // or await import() in ESM
// or without destructuring:
const META = require(...).META

Therefore, in Python the import would look as

from javascript import require

Meta = require("@consumet/extensions").META
anilist = Meta.Anilist()
print(anilist.fetchAnimeInfo(id))
Shuvadip-Ghosh commented 1 year ago

Thank You it worked but the type printed is <class 'javascript.proxy.Proxy'> how to convert it into a dictionary and I want to use

console.dir(data, {'maxArrayLength': null});

instead of

console.log(data);

so that it print the full array and not print ". . .120 more rows"

extremeheat commented 1 year ago

Do fetchAnimeInfo(id).valueOf() to get a native object

Shuvadip-Ghosh commented 1 year ago

I am getting this error sometimes

Call to 'fetchAnimeInfo' timed out. Increase the timeout by setting the `timeout` keyword argument.

Can You tell me is this because of js or Python and its solution

extremeheat commented 1 year ago

That error is because the JS code has returned a Promise but did not resolve in a few seconds. You can try and increase the timeout with fetchAnimeInfo(id, timeout=9000)

Shuvadip-Ghosh commented 1 year ago

The timeout is in milliseconds right??