From 5b866c4a2a2a416bbada12c97c5579ded9d3dfb7 Mon Sep 17 00:00:00 2001 From: Adam Piontek Date: Sat, 25 Aug 2018 16:11:55 -0400 Subject: [PATCH] Change breeds data structure to dictionary in preparation for implementing sub-breeds --- doggo.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/doggo.py b/doggo.py index 9822d75..89a7abf 100644 --- a/doggo.py +++ b/doggo.py @@ -1,9 +1,7 @@ - import logging -import json - -from errbot import botcmd, BotPlugin import requests +import json +from errbot import botcmd, BotPlugin class Doggo(BotPlugin): @@ -11,7 +9,7 @@ class Doggo(BotPlugin): BASE_URL = 'https://dog.ceo/api' - breeds = [] + breeds = {} @botcmd(split_args_with=' ') def doggo(self, msg, args): @@ -24,7 +22,7 @@ class Doggo(BotPlugin): breed = args[0] if not self.breeds: self.reloadbreeds(msg, args) - if breed in self.breeds: + if breed in self.breeds.keys(): url = '{}/breed/{}/images/random'.format(self.BASE_URL, breed) else: return 'Breed not found: {}. List breeds with !listbreeds'.format(breed) @@ -52,7 +50,7 @@ class Doggo(BotPlugin): # Send the output to the user to prevent spamming the channel direct_to_user = self.build_identifier(str(msg.frm)) - for breed in sorted(self.breeds): + for breed in sorted(self.breeds.keys()): self.send(direct_to_user, breed) @@ -74,4 +72,5 @@ class Doggo(BotPlugin): if not isinstance(data, list): return 'Unable to load breeds list' - self.breeds = data + for breed in data: + self.breeds[breed] = []