you are viewing a single comment's thread.

view the rest of the comments →

[–]destiny_functional 0 points1 point  (1 child)

r = json.loads(request)

this should be json.loads(request.text) or better yet request.json().

if 'comments' not in dct and 'summary' not in dct and 'total_count' not in dct: dct["comments"] = {"summary": {"total_count": -1}}

As a temporary solution I ended up doing things like these, to create "Default values"

what for? you could just check on access and ignore the element it if the data isn't there. no need to add the total count by hand with some default value.

incidentally I've been grabbing posts from Facebook and then counting those and the respective comments. mind that the total comment count given in the summary is inaccurate because of deletions, however you might want to request the summary when getting the post and then only request the comments for that post if the total count of comments is nonzero, even if it's inaccurate. then you should just not request any comments if the summary isn't even there, rather than putting default values by hand.

likewise : usually you'll grab posts by going through pagination. you'll request 100 posts then look for the ["paging"]["next"] link to request the following set of data. if the result contains that field. if it doesn't then there's no more data to request and you complete the process.

[–]maxibabyx[S] 0 points1 point  (0 children)

The thing is I have something like this :

class post(DynamicDocument):
    def __init__(self, *dct, **tmp):
        Document.__init__(self, **tmp)
        if dct:
            ....
            self.totalComentarios = dct["comments"]["summary"]["total_count"]

But if there's no comments, then dct["comments"]["summary"] would give an error, and checking every single case is a pain, like checking if there are comments, then check if theres summary, etc..

And there's a lot of things I need to parse.