I have a web scraper that grabs info and saves it to a database. I use the following code to save data.
try:
base['vevo']['url']
except:
base['vevo']['url'] = "NotGiven"
try:
base['vevo']['viewsLastWeek']['data']['time']
except:
base['vevo']['viewsLastWeek']['data']['time'] = '2199-01-01'
Now normally this works, however ocassionally the data stream doesn't return any info at all for base['vevo']
. This breaks the above dict add and says that KeyError 'vevo'
.
I've been trolling through other stackoverflow questions, but I haven't been able to find anything that references adding multiple keys at once like I'm trying to do. I've tried to use base.append('key'), tried base.get() but couldn't find a reference on how to use it for multiple keys deep. Any ideas on how to get around it?