Пример #1
0
class TangerineStatementImporter():
    def __init__(self, secret_file):
        secret_provider = create_provider(secret_file, provider_factory=TangerineSecretProvider)
        self._client = TangerineClient(secret_provider)

    def _get_date_range(self):
        today = datetime.date.today()
        from_ = today - relativedelta(months=1)
        to_ = today + relativedelta(days=1)
        return from_, to_

    def upload(self, statement_content, target_account_id, target):
        raise NotImplemented()

    def __call__(self, account_ids, targets):
        from_, to_ = self._get_date_range()

        with self._client.login():
            accounts = self._client.list_accounts()
            accounts = {
                acct['number']: acct
                for acct in accounts
            }
            for account_id in account_ids:
                account_obj = accounts.get(account_id)
                if not account_obj:
                    logger.warn('Account {} does not exist. Skip...'.format(account_id))
                    continue
                for target in targets:
                    account_id_mapping = target.get('account_id_mapping') or  {}

                    target_account_id = account_id_mapping.get(account_id)
                    content = self._client.download_ofx(account_obj, from_, to_, save=False)
                    self.upload(content, target_account_id, target)
Пример #2
0
def main():
    secret_provider = InteractiveSecretProvider()
    client = TangerineClient(secret_provider)

    start_http_server(8000)

    session = client.login()
    scrape_account_metrics(client, session)
Пример #3
0
def notify_tangerine_transactions(account_ids,
                                  secret_file,
                                  recipient,
                                  tangerine_client=None,
                                  email=None):
    if tangerine_client is None:
        secret_provider = create_provider(secret_file, provider_factory=TangerineSecretProvider)
        tangerine_client = TangerineClient(secret_provider)
    notifier = TangerineTransactionNotifier(account_ids, recipient, tangerine_client, email)
    return notifier()
Пример #4
0
    with tangerine_client.login():
        accounts = get_accounts()

    process_data(accounts)


def info(message: str, color: str = "blue"):
    click.secho(message, fg=color)


if __name__ == '__main__':
    info("Loading config file")
    with open("config.json", mode="r") as config_file:
        config = Munch(ujson.loads(config_file.read()))

    info("Loading credentials")
    with open("credentials.json", mode="r") as credentials_file:
        credentials = ujson.loads(credentials_file.read())

    info("Initializing Tangerine client")
    secret_provider = DictionaryBasedSecretProvider(credentials)
    tangerine_client = TangerineClient(secret_provider)

    info("Initializing Google Sheet client")
    gdrive_credentials = ServiceAccountCredentials.from_json_keyfile_name(
        "client_secret.json", gdrive_scope)
    gdrive_client = gspread.authorize(gdrive_credentials)

    info("Starting import")
    run()
Пример #5
0
import json
import logging
import datetime
import subprocess
from tangerine import TangerineClient, DictionaryBasedSecretProvider
from tangerine.exceptions import UnsupportedAccountTypeForDownload


FROM = datetime.date(2017, 6, 1)
TO = datetime.date(2017, 11, 2)


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    output = subprocess.check_output(['gpg', '-d', 'tangerine.json.gpg'])
    secret_provider = DictionaryBasedSecretProvider(json.loads(output))
    client = TangerineClient(secret_provider)
    with client.login():
        accounts = [
            acct for acct in client.list_accounts()
            if acct['type'] != 'CREDIT_CARD'
        ]
        for acct in accounts:
            try:
                client.download_ofx(acct, FROM, TO)
            except UnsupportedAccountTypeForDownload as e:
                print(e)
Пример #6
0
def tangerine_client_factory(secret_file):
    secret_provider = create_provider(secret_file, provider_factory=TangerineSecretProvider)
    tangerine_client = TangerineClient(secret_provider)
    return tangerine_client
Пример #7
0
 def __init__(self, secret_file):
     secret_provider = create_provider(secret_file, provider_factory=TangerineSecretProvider)
     self._client = TangerineClient(secret_provider)
import datetime
import json
import logging
import subprocess
from tangerine import TangerineClient, DictionaryBasedSecretProvider

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    output = subprocess.check_output(['gpg', '-d', 'tangerine.json.gpg'])
    secret_provider = DictionaryBasedSecretProvider(json.loads(output))
    client = TangerineClient(secret_provider)
    with client.login():
        cc_accounts = [
            acct for acct in client.list_accounts()
            if acct['type'] == 'CREDIT_CARD'
        ]

        for acct in cc_accounts:
            acct_details = client.get_account(acct['number'])
            billing_cycles = acct_details['credit_card']['cc_account_details'][
                'card_details']['billing_cycle_ranges']
            for cycle in billing_cycles:
                start_date, end_date = cycle['start_date'], cycle['end_date']
                start_date = datetime.datetime.strptime(
                    start_date, '%Y-%m-%d').date()
                end_date = datetime.datetime.strptime(end_date,
                                                      '%Y-%m-%d').date()
                client.download_ofx(acct, start_date, end_date)
Пример #9
0
def tangerine(ctx):
    ctx.tangerine_client = TangerineClient(
        VaultSecretProvider(ctx.vault_client, 'secret/tangerine'))