def downloadZipFile(self, ctx) -> str: url = ctx.url zip_path = path.join( self.compression_dir, "{}-{}.zip".format(name_to_filename(ctx.name), ctx.iso_datetime)) if path.exists(zip_path): die("Compression file already exists: %s", zip_path) # Download logger.debug("Downloading StatsCan table from %s", url) response = urllib.request.urlopen(url) logger.debug("> Done downloading") # Verify output context_length = tryint( coalese(response.getheader("Content-Length"), "0").strip()) content_type = coalese(response.getheader("Content-Type"), "").strip() if content_type != "application/zip" or context_length == 0: logger.warning("> Failed to download table %s zip from %s ", ctx.name, url) return None logger.debug("> Zip size: %d", context_length) # Save to data to zip file logger.debug("> Saving response to %s", zip_path) zip_file = open(zip_path, "wb") zip_file.write(response.read()) logger.debug("> Done saving") ctx.zip_filepath = zip_path self.pushFile(zip_path) return zip_path
def getValue(self, row) -> int: value = tryint(row[VALUE_KEY]) multiplier = scalar_multiplier(row[SCALAR_KEY]) return value * multiplier