Code Monkey home page Code Monkey logo

personalcapital's Introduction

Personal Capital

Python library for accessing Personal Capital data

Installation

With Pip

pip install personalcapital

With Source Code

You can get the source code by cloning it from Github:

git clone https://github.com/haochi/personalcapital.git

or get the tarball:

curl -OJL https://github.com/haochi/personalcapital/tarball/master

then either include the library into your code, or install it with:

python setup.py install

Usage

You need to first create an instance.

pc = PersonalCapital()

Then you will need to authenticate the account by logging in:

pc.login(email, password)

login may throw a RequireTwoFactorException, if two factor is enabled on your account and the current session is not yet associated with the account. In this case, you will need to pick a way to complete the two factor authenticate by calling

pc.two_factor_challenge(mode)

mode can either be TwoFactorVerificationModeEnum.SMS or TwoFactorVerificationModeEnum.EMAIL.
Then you need to finish the two factor challenge by verifying the code and continue the login process.

pc.two_factor_authenticate(mode, raw_input('code'))
pc.authenticate_password(password)

Once authenticated, you can start fetching data from the Personal Capital API.

accounts_response = pc.fetch('/newaccount/getAccounts')

The above request will load your accounts data, and with that response you can get your net worth.

print('Networth', accounts_response.json()['spData']['networth'])

To avoid two factor authentication every time you run the script, you can use get_session() to store your session somewhere and set_session(session) to re-use the session.

Here's the entire thing.

from personalcapital import PersonalCapital, RequireTwoFactorException, TwoFactorVerificationModeEnum

pc = PersonalCapital()

email, password = "[email protected]", "password"

try:
    pc.login(email, password)
except RequireTwoFactorException:
    pc.two_factor_challenge(TwoFactorVerificationModeEnum.SMS)
    pc.two_factor_authenticate(TwoFactorVerificationModeEnum.SMS, raw_input('code: '))
    pc.authenticate_password(password)

accounts_response = pc.fetch('/newaccount/getAccounts')
accounts = accounts_response.json()['spData']

print('Networth: {0}'.format(accounts['networth']))

Example

See main.py for an example script.

To run it, simply run python main.py.

Or set the environment email and password so you don't need to enter it every time.

PEW_PASSWORD="password" PEW_EMAIL="email" python main.py 

Personal Capital API

Please inspect the network requests to see what requests are possible. The main.py example includes two such calls.

personalcapital's People

Contributors

haochi avatar ameng avatar amarvin avatar banool avatar iantrich avatar jacobchurch avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.