adafruit / Adafruit_Learning_System_Guides

Programs and scripts to display "inline" in Adafruit Learning System guides

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Matrix_Portal_Moon_Clock - MemoryError with json.loads

bembengarifin opened this issue · comments

Hi guys,

Initially I kept getting some weird errors about missing midnight property when running the code, but then found that it's actually due to this specific line throwing MemoryError (but swallowed by except)

full_data = json.loads(NETWORK.fetch_data(url))

It seems that converting json from the response string takes quite a memory:

                full_data = json.loads(NETWORK.fetch_data(url))
                moon_data = full_data['location']['time'][0]

After going through the code, I noticed there is an overload that will enable fetching specific path and return the result in needed json/dictionary object, so simple code change below will solve the problem

                location_data = NETWORK.fetch_data(url, json_path=[["location"]])
                moon_data = location_data["time"][0]

Hope this helps someone who's getting the same problem as mine
Thanks.

fixed in latest pr