How to use the yfinance.get_rates function in yfinance

To help you get started, we’ve selected a few yfinance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jason0x43 / jc-units / alfred_convert.py View on Github external
lines = []
        last_refresh = None
        today = datetime.date.today()

        if os.path.exists(self.currencies_file):
            with open(self.currencies_file, 'rt') as cf:
                lines = cf.readlines()

        if len(lines) > 0 and lines[0].startswith('# date:'):
            last_refresh = lines[0].split(':')[1].strip()
            last_refresh = datetime.datetime.strptime(last_refresh, '%Y-%m-%d').date()

        if not last_refresh or last_refresh != today:
            import yfinance
            rates = yfinance.get_rates(CURRENCIES)
            with open(self.currencies_file, 'wt') as cf:
                cf.write('# date: ' + today.strftime('%Y-%m-%d') + '\n')
                cf.write('USD = [currency] = usd\n')
                for k, v in rates.items():
                    cf.write('{0} = USD / {1} = {2}\n'.format(k, v, k.lower()))