Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutual funds not reporting properly #15

Open
bryanlan opened this issue Dec 22, 2017 · 0 comments
Open

Mutual funds not reporting properly #15

bryanlan opened this issue Dec 22, 2017 · 0 comments

Comments

@bryanlan
Copy link

Google's mechanism to report mutual funds is a bit different, and the way it returns data sometimes has a ',}' that causes the json parser to hit an exception. Also, the keys are different from non-mutual funds. I used the hackery below to get past it, but you may want to do something more elegant:

try:
jayson = r.text.replace('\n', '')
# mutual funds have a ,} that messes up the json parser
jayson = jayson.replace(',}','}')
jayson = json.loads(jayson[2:])[0]
self.ticker = jayson['t']
except:
self.ticker = None

    if r.status_code == 400 or self.ticker != query.split(':')[-1]:
        raise LookupError('Ticker symbol not found. Try adding the exchange parameter')
    else:
        r.raise_for_status()

    self.id = jayson["id"]
    self.exchange = jayson['e']
    self._last_trade = None
    self.name = jayson['name']
    if self.exchange != 'MUTF':
        self._price = parse(jayson['l'])
        try:
            self.change = parse(jayson['c'])
            self.cp = parse(jayson['cp'])
        except ValueError:
            self.change = jayson['c']
            self.cp = jayson['cp']

        self.dy = parse(jayson.get('dy') or 0)/100
    else:
        self._price = parse(jayson['nav_prior'])
        try:
            self.change = parse(jayson['nav_c'])
            self.cp = parse(jayson['nav_cp'])
        except ValueError:
            self.change = jayson['nav_c']
            self.cp = jayson['nav_cp']
        self.dy = parse(jayson.get('yield_percent') or 0) / 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant