python-twitter
python-twitter copied to clipboard
testNewFromJsonDict from test_status.py is incomplete and hides missing functionality: 'entities' dict
The test string does not include nested objects which the twitter JSON delivers in 'entities'. The AsJsonString [via AsDict] places those aspects directly within the json dict root.
AsDict automatically generates the dictionary without accounting for values with lists should be inside the 'entities' dict
Post = api.GetStatus(851223203167039492)
PP = twitter.Status.NewFromJsonDict(json.loads( str(Post.AsJsonString() ) ) )
>>> print Post.urls
[URL(URL=https://t.co/uUG61G1wPn, ExpandedURL=https://www.propublica.org/article/minority-neighborhoods-higher-car-insurance-premiums-white-areas-same-risk)]
>>> print PP.urls
None
Kiiiiinda. So what happens is the Twitter JSON data gets deconstructed starting here https://github.com/bear/python-twitter/blob/master/twitter/models.py#L471 and then the the individual nodes values are passed as kwargs to super().NewFromJsonDict(), essentially flattening the JSON dict and setting those node values as instance attributes.
If you want the raw JSON data from Twitter to pass back into NewFromJsonDict, use ._json instance attribute. Making those two functions symmetrical might be a good enhancement, though.