def load_from_cache(self, form): if "value" in self.dbs[form].keys(): Console.print(self.__class__, "loadFromCache: " + form + " of " + self.ticker) return self.dbs[form]["value"] else: return self.load_from_file(form)
def download(self, form): if self.workFromArchive is False: url = self.dbs[form]["url"] filePath = self.get_file_path(form) urllib.request.urlretrieve(url, filePath) else: Console.print(FmpHandler, "Download disabled, working from archive: " + form + " of " + self.ticker)
def load_from_file(self, form): filePath = self.get_file_path(form) if os.path.isfile(filePath) is True: Console.print(self.__class__, "loadFromFile: " + form + " of " + self.ticker) return self.cache(form) else: return self.load_from_url(form)
def createFolder(path): if os.path.isdir(path) is False: try: os.mkdir(path) except OSError: Console.print(FileHandler, "Creation of the directory %s failed" % path) else: Console.print(FileHandler, "Successfully created the directory %s " % path)
def write(filePath, dictionary, encoding='utf8'): jsonString = json.dumps(dictionary, sort_keys=True, indent=4, separators=(',', ': ')) try: FileHandler.writeTextFile(filePath, jsonString, encoding) except: Console.print(FileHandler, "No such file or directory: " + filePath)
def download(self, form): if self.workFromArchive is False: # Start Browser YfHandler.start_browser() # Set Browser download path YfHandler.set_browser_download_path(self.path) if form == "DividendHistory": self.download_dividend_history() else: Console.print( YfHandler, "Download disabled, working from archive: " + form + " of " + self.ticker)
def load_from_url(self, form): Console.print(self.__class__, "loadFromUrl: " + form + " of " + self.ticker) self.download(form) return self.cache(form)