I have an output from dweepy as :
[{'content': {'mouse_x': 271,
'mouse_y': 285,
'tilt_x': 0,
'tilt_y': 0,
'tilt_z': 82},
'created': '2018-02-10T06:03:02.680Z',
'thing': 'my_thing_name'}]
My input was :
dweepy.get_latest_dweet_for('my_thing_name')
Question :
How to print value of mouse_x value alone from above dweet output ?
What i tried was :
dweepy.dweet_for('my_thing_name', {'': 'mouse_x'})
which gave me output :
{'content': {'': 'mouse_x'},
'created': '2018-02-10T06:23:20.320Z',
'thing': 'my_thing_name',
'transaction': '6f295639-a667-48ff-bbbf-6dda111333d1'}
How can i print value 271 for mouse_x ?
For the content you are
dweetingwith thenameasmy_thing_name, let us assume that you havedweet_for()as follows initiallyWhich creates a
dweetwith name asmy_thing_name. Now when you query for thedweetusingdweepy.get_latest_dweet_for()you are returned a dictionary as followsResult is a list of
objectwhose keys arecontent,thingandcreated. For retrieving the content for keymouse_xyou need to access the object inside the dweet response'scontentdictionary.This can be done by doing
a[0]['content']['mouse_x']which will return the value271. This will however work only with the firstdweetobject. If there are multiple objects returned you can loop through the items and access themouse_xvalue by usinga[i]['content']['mouse_x']whereicorresponds to the index of the items.