def download_image(self):
split = urlsplit(self.url)<EOL>filename = split.path.split("<STR_LIT:/>")[-<NUM_LIT:1>]<EOL>if not os.path.exists(self.cache_directory):<EOL><INDENT>os.makedirs(self.cache_directory)<EOL><DEDENT>filepath = os.path.join(self.cache_directory, filename)<EOL>data = urllib_request.urlopen(self.url)<EOL>with open(filepath, "<STR_LIT:wb>") as image:<EOL><INDENT>image.write(data.read())<EOL><DEDENT>return filepath<EOL>
Download the image and return the
local path to the image file.