Beispiel #1
0
    def client(self) -> PersonalCapital:
        """
        Log into Personal Capital and save the session.
        """
        if self._api_client is None:
            self._api_client: PersonalCapital = PersonalCapital()

            if self._session_cookies:
                self._api_client.set_session(self._session_cookies)

            try:
                self._api_client.login(self.config.username,
                                       self.config.password)
            except RequireTwoFactorException:
                self._api_client.two_factor_challenge(
                    TwoFactorVerificationModeEnum.SMS)
                self._api_client.two_factor_authenticate(
                    TwoFactorVerificationModeEnum.SMS, self._auth_code)
                self._api_client.authenticate_password(self.config.password)

            with open(self.config.cookies, 'w') as stream:
                stream.write(json.dumps(self._api_client.get_session()))

            return self._api_client
        else:
            return self._api_client
Beispiel #2
0
    def __init__(self, pc_username, pc_password, email_username,
                 email_password):
        self.client = PersonalCapitalClient()

        self.pc_username = pc_username
        self.pc_password = pc_password
        self.email_username = email_username
        self.email_password = email_password

        self.session = None
Beispiel #3
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Personal Capital component."""
    from personalcapital import PersonalCapital, RequireTwoFactorException, TwoFactorVerificationModeEnum
    pc = PersonalCapital()
    session = load_session(hass)

    if len(session) > 0:
        pc.set_session(session)

        try:
            pc.login(config.get(CONF_EMAIL), config.get(CONF_PASSWORD))
            continue_setup_platform(hass, config, pc, add_devices, discovery_info)
        except RequireTwoFactorException:
            request_app_setup(hass, config, pc, add_devices, discovery_info)
    else:
        request_app_setup(hass, config, pc, add_devices, discovery_info)
Beispiel #4
0
 def __init__(self):
     PersonalCapital.__init__(self)
     self.__session_file = 'session.json'
Beispiel #5
0
 def __init__(self):
     PersonalCapital.__init__(self)
     self.__session_file = 'session.json'
Beispiel #6
0
from personalcapital import PersonalCapital, RequireTwoFactorException,\
                            TwoFactorVerificationModeEnum
from datetime import datetime, timedelta

import json

pc = PersonalCapital()

email, password =

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

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

now = datetime.now()
date_format = '%Y-%m-%d'
days = 90
start_date = (now - (timedelta(days=days+1))).strftime(date_format)
end_date = (now - (timedelta(days=1))).strftime(date_format)
transactions_response = pc.fetch('/transaction/getUserTransactions', {
    'sort_cols': 'transactionTime',
    'sort_rev': 'true',
    'page': '0',
    'rows_per_page': '20',
Beispiel #7
0
 def __init__(self):
     PersonalCapital.__init__(self)
     self.__session_file = os.getenv('PEW_SESSION_FILE', 'session.json')
Beispiel #8
0
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, redirect
from django.template import loader

from .fetchdata import fetch_accounts_json, fetch_transactions_json
from .forms import SmsAuthenticationForm, PersonalCapitalLoginForm

from datetime import datetime, timedelta
from personalcapital import PersonalCapital, RequireTwoFactorException,\
                            TwoFactorVerificationModeEnum

import json

pc = PersonalCapital()


def index(request):
    if request.method == "POST":
        form = PersonalCapitalLoginForm(request.POST)

        if form.is_valid():
            session = request.session
            session['pc_email'] = form.cleaned_data['pc_email']
            session['pc_password'] = form.cleaned_data['pc_password']

            try:
                pc.login(session['pc_email'], session['pc_password'])
            except RequireTwoFactorException:
                pc.two_factor_challenge(TwoFactorVerificationModeEnum.SMS)
                return redirect('two-factor')
Beispiel #9
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Personal Capital component."""
    from personalcapital import PersonalCapital, RequireTwoFactorException, TwoFactorVerificationModeEnum
    pc = PersonalCapital()
    request_app_setup(hass, config, pc, add_devices, discovery_info)
Beispiel #10
0
class PersonalCap(object):
    def __init__(self, pc_username, pc_password, email_username,
                 email_password):
        self.client = PersonalCapitalClient()

        self.pc_username = pc_username
        self.pc_password = pc_password
        self.email_username = email_username
        self.email_password = email_password

        self.session = None

    def _login(self):
        if self.session:
            self.client.set_session(self.session)
            return
        else:
            try:
                self.client.login(username=self.pc_username,
                                  password=self.pc_password)
            except:
                self.client.two_factor_challenge(
                    TwoFactorVerificationModeEnum.EMAIL)

                ## get 2FA code magic via SMS or email tbd.
                code = self._get_code_from_email()

                self.client.two_factor_authenticate(
                    TwoFactorVerificationModeEnum.EMAIL, code)
                self.client.authenticate_password(self.pc_password)
            self.session = self.client.get_session()
            self.client.set_session(self.session)

    def _get_code_from_email(self):
        mailbox = imaplib.IMAP4_SSL("imap.gmail.com")
        mailbox.login(self.email_username, self.email_password)
        mailbox.select('inbox')
        result, data = mailbox.search(None, "ALL")
        mail_ids = data[0]  # data is a list.
        mail_ids_list = mail_ids.split()  # ids is a space separated string
        latest_email_id = mail_ids_list[-1]  # get the latest
        result, data = mailbox.fetch(
            latest_email_id,
            "(RFC822)")  # fetch the email body (RFC822) for the given ID
        raw_email = str(data[0][1])

        code = re.search(TWOFA_CODE_REGEX, raw_email)[1].split()[0]
        return code
Beispiel #11
0
from personalcapital import PersonalCapital, RequireTwoFactorException, TwoFactorVerificationModeEnum
import curses
from curses import wrapper
import json

_COOKIES_FILE = 'cookies.json'

pc = PersonalCapital()

email, password = "******", "password"
try:
    with open('cookies.json') as fd:
        cookies = json.load(fd)
        pc.set_session(cookies)
        pc.login(email, password)
except FileNotFoundError:
    try:
        pc.login(email, password)
    except RequireTwoFactorException:
        pc.two_factor_challenge(TwoFactorVerificationModeEnum.SMS)
        pc.two_factor_authenticate(TwoFactorVerificationModeEnum.SMS,
                                   input('code: '))
        pc.authenticate_password(password)
        cookies = pc.get_session()
        with open('cookies.json', 'w') as fd:
            json.dump(cookies, fd)

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

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