itsmehemant7 / PyMovieDb

A Simple IMDb API for Python
MIT License
90 stars 18 forks source link

get() returns json dump instead of dict #3

Closed fcakyon closed 1 year ago

fcakyon commented 1 year ago

Thanks for all the effort, I just started utilizing your package in one of my works!

In most apis, data is returned as a dict instead of json dump. However in your work, I manually convert your method outputs to a dict at every call.

Do you have any intentions to update the get() output so that it returns a dict instead of json dump?

https://github.com/itsmehemant7/PyMovieDb/blob/40e37ab83616a5a7b1abe7b1a958dae3f722e0c6/build/lib/PyMovieDb/imdb.py#L188

iamgojoof6eyes commented 1 year ago

Thank you for creating this issue. I was just about to make this one

iamgojoof6eyes commented 1 year ago

However, I just found a solution to it

import json
res = imdb.get_by_name("Loki")
res = json.load(res)

or

import ast
res = imdb.get_by_name("Loki")
res = ast.literal_eval(res)

I have tried the second one and it worked for me. I have also tried 1st one but it isn't working for me at least

Context

Hope it would help

fcakyon commented 1 year ago

@iamgojoof6eyes thanks for your workaround but it would be easier if the original output returned a dict. What do you think about it? @itsmehemant7

iamgojoof6eyes commented 1 year ago

Necessary indeed. While using it sometimes it throws errors while running the code.

itsmehemant7 commented 1 year ago

@iamgojoof6eyes thanks for the issue(s)....will fix in next version ASAP.

fcakyon commented 1 year ago

@itsmehemant7 thanks a lot! Can you also address this issue? https://github.com/itsmehemant7/PyMovieDb/issues/2

itsmehemant7 commented 1 year ago

OK...PyMovieDb is designed for web app implementation, you can directly make calls from the front-end to the API easily. Although this is not a blocker, if you need output as dict then simply use output_dict= json.loads(API_response)

samarthdave commented 1 year ago

Hi, can you make this more apparently in the README? I copied the result of imdb.get_by_id("tt4807830") (Bullet Train) from the README into ChatGPT and asked it to write a script for my Notion page.

I whole heartedly trusted the output (yeah i know). Then, I spent 10 minutes wondering why I couldn't index on the result object:

>>> res = imdb.get_by_id("tt12593682")
# { Bullet Train ... }
>>> res['name']
# ??? *confused*
>>> type(res)
<class 'str'> *ohhhh* *realizes*

How does adding an optional kwarg that bypasses the json dump sound? Something like this:

imdb.get_by_id("tt12593682", dump=True)
fcakyon commented 1 year ago

@samarthdave i honestly dont understand why he refuses to add such a feature.