Python Forum

Full Version: Scraping into dictionary
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
mv = {}
def woohoo():
    for i in json_data['result']:
        if i['MarketName'] not in mv:
            mv[i['MarketName']] = i['Volume']
        else:
            try:
                DifferenceInVolume = i['Volume'] / mv[i['MarketName']]
            except ZeroDivisionError:
                DifferenceInVolume = 0
                if DifferenceInVolume >= 1.01:
                    print(i['MarketName'])
My objective is to pull data from an API every ?/seconds and add it to a dictionary. I'm then trying to compare that dictionary with the previous scraped dictionary (n-1). This is what I have at the moment and it's only scraping one ['MarketName'] and ['Volume'] at a time rather than the entire list of ['MarketName'] and ['Volume'] in each run through the function.

I hope this makes sense. Any guidance would be much appreciated!