rossengeorgiev / aprs-python

📡 Python module for working with APRS
http://aprs-python.readthedocs.io/en/latest/
GNU General Public License v2.0
118 stars 37 forks source link

[question] how to extract parsed value from the dictionary #52

Closed iw5ejm closed 5 years ago

iw5ejm commented 5 years ago

def callback(packet): T = packet.get('temperature') print(T)

Running this callback function on a weather packet filtered stream, with AIS.consumer(callback, raw=False)

Why I'm getting only KeyError Exceptions or None value for the temperature (and for all the other key in the dict)? It seems that there is no key in packet.. What am I doing wrong?

thanks, Marco

iw5ejm commented 5 years ago

problem was the nested dictionary for weather data

you have to use something like this to get wx data:

T = packet['weather']['temperature']
print(T)
H = packet['weather']['humidity']
P = packet['weather']['pressure'] 
rossengeorgiev commented 5 years ago

Hi @iw5ejm, the packet will be a dict and will have a different structure depending on the message. You will have to check for the weather key, or that format is wx. You can find the various package structure in the docs: https://aprs-python.readthedocs.io/en/latest/parse_formats.html#weather