Python Forum
How can I only receive data from selected serial numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I only receive data from selected serial numbers
#3
Unless you are able to filter serialNumbers in the API requests your approach is correct. The problem that in the JSON serialNumber is str and in your ignore list - int

# assuming you have properly converted the json response
json_response = [
{
"serialNumber": "121718037628",
"lastReportDate": 1549920259,
"devType": 1,
"lastReportWatts": 18,
"maxReportWatts": 18
},
{
"serialNumber": "121718037534",
"lastReportDate": 1555635154,
"devType": 1,
"lastReportWatts": 108,
"maxReportWatts": 187
},
{
"serialNumber": "121718037683",
"lastReportDate": 1555635148,
"devType": 1,
"lastReportWatts": 117,
"maxReportWatts": 197
}
]

ignore_set = {'121718037628',} # that is actually a set

for inverter in json_response:
    if inverter['serialNumber'] not in ignore_set:
        print(inverter)
Output:
{'serialNumber': '121718037534', 'lastReportDate': 1555635154, 'devType': 1, 'lastReportWatts': 108, 'maxReportWatts': 187} {'serialNumber': '121718037683', 'lastReportDate': 1555635148, 'devType': 1, 'lastReportWatts': 117, 'maxReportWatts': 197} >>>
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: How can I only receive data from selected serial numbers - by buran - Apr-19-2019, 11:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guidance for the basic concept send/receive a heartbeat signal StefanL38 1 220 Jun-09-2024, 05:31 PM
Last Post: Gribouillis
  Receive Input on Same Line? johnywhy 8 1,052 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 5,817 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  How to continuously receive messages until specified to stop using Bleak jacobbreen25 3 2,392 Dec-28-2022, 04:25 PM
Last Post: jacobbreen25
  How can I add an end line character after every value that I receive? GiggsB 11 5,668 Mar-06-2022, 08:51 PM
Last Post: GiggsB
  How to receive webcam capture on spout? buzzdarkyear 2 2,797 Jan-12-2022, 02:26 PM
Last Post: buzzdarkyear
  Help reading data from serial RS485 korenron 8 14,762 Nov-14-2021, 06:49 AM
Last Post: korenron
  Reading Serial data Moris526 6 5,633 Dec-26-2020, 04:04 PM
Last Post: Moris526
  Taking serial data to perform key.press functions ausbollinger13 1 2,435 Sep-04-2020, 10:26 PM
Last Post: bowlofred
  Put Serial data to list PA3040 5 6,791 Sep-01-2020, 02:34 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020