52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
class ConsoleFormatter(object):
|
|
"""Formats data to be printed to a console."""
|
|
|
|
def __init__(self, account_data):
|
|
self.account_data = account_data
|
|
|
|
def as_string(self):
|
|
result = ''
|
|
for account in self.account_data['accounts']:
|
|
name = account['name']
|
|
balance = account['balance']
|
|
transactions = account['transactions']
|
|
result += name + '\n'
|
|
result += '=' * len(name) + '\n'
|
|
result += 'date,description,amount\n'
|
|
for transaction in transactions:
|
|
if 'CHANGE' in transaction['description']:
|
|
continue
|
|
result += str(transaction['date']) + ','
|
|
result += str(transaction['description']) + ','
|
|
result += str(transaction['amount']) + '\n'
|
|
result += 'Balance: ' + balance + '\n'
|
|
result += '\n'
|
|
return result
|
|
|
|
|
|
def main():
|
|
from selenium import webdriver
|
|
from scrapers.bank_of_america import BankOfAmericaBankScraper
|
|
from getpass import getpass
|
|
import os
|
|
import pickle
|
|
|
|
cache_filename = '/tmp/cache'
|
|
data = ''
|
|
if os.path.exists(cache_filename):
|
|
with open(cache_filename, 'rb') as cache_file:
|
|
data = pickle.load(cache_file)
|
|
else:
|
|
with open(cache_filename, 'wb') as cache_file:
|
|
driver = webdriver.PhantomJS()
|
|
scraper = BankOfAmericaBankScraper(driver)
|
|
credentials = (input("username: "), getpass("password: "))
|
|
data = scraper.get_data(credentials)
|
|
pickle.dump(data, cache_file)
|
|
print(ConsoleFormatter(data).as_string())
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|