Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

Commit

Permalink
fixed initial commit. added .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
rdkr committed Sep 7, 2015
1 parent 74fa799 commit 4f29785
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 58 deletions.
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/
Binary file added __pycache__/account.cpython-34.pyc
Binary file not shown.
27 changes: 12 additions & 15 deletions banks/Nationwide.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
import time
from bs4 import BeautifulSoup

import account
from account import account

class Nationwide(Thread):

accounts = []

def __init__(self, user, pswd, info):
def __init__(self):

Thread.__init__(self)

self.user = user
self.pswd = pswd
self.info = info
def set_login_params(self, login_dict):

self.user = login_dict['user']
self.pswd = login_dict['pswd']
self.info = login_dict['info']

def run(self):

Expand All @@ -28,7 +30,7 @@ def run(self):
r = self.main_page(s, r)
except:
print('EXCEPT IN NATIONWIDE')
self.accounts.append(account.account('nationwide', 'error', 'error', 'error', 'error', 'error'))
self.accounts.append(account('nationwide', 'error', 'error', 'error', 'error', 'error'))

def get_accounts(self):
return self.accounts
Expand Down Expand Up @@ -88,11 +90,11 @@ def main_page(self, s, r):

soup = BeautifulSoup(r.text, 'html.parser')

for accText in soup.find_all(class_ = 'account-row'):
for accountEntry in soup.find_all(class_ = 'account-row'):

# get account details and add to accounts list

r = s.get('https://onlinebanking.nationwide.co.uk' + accText.find(class_ = 'acLink')['href'])
r = s.get('https://onlinebanking.nationwide.co.uk' + accountEntry.find(class_ = 'acLink')['href'])
soup = BeautifulSoup(r.text, 'html.parser')

accInfo = soup.find(class_ = 'stage-head-ac-info')
Expand All @@ -105,7 +107,7 @@ def main_page(self, s, r):
accBalance = self.get_num(accInfo.find_all('dd')[0].get_text())
accAvailable = self.get_num(accInfo.find_all('dd')[1].get_text())

acc = account.account('nationwide', accSort, accNumber, accName, accBalance, accAvailable)
acc = account('nationwide', accSort, accNumber, accName, accBalance, accAvailable)

self.accounts.append(acc)

Expand All @@ -122,10 +124,5 @@ def main_page(self, s, r):
file.write(r.text)
file.close()

self.accounts.append(acc)

def get_num(self, x): # http://stackoverflow.com/a/10365472 #TODO static method?
return float(''.join(ele for ele in x if ele.isdigit() or ele == '.'))



return float(''.join(ele for ele in x if ele.isdigit() or ele == '.'))
38 changes: 15 additions & 23 deletions banks/Tsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
import time
from bs4 import BeautifulSoup

import account
from account import account

class Tsb(Thread):

accounts = []

def __init__(self, user, pswd, info):
def __init__(self):

Thread.__init__(self)

self.user = user
self.pswd = pswd
self.info = info
def set_login_params(self, login_dict):

self.user = login_dict['user']
self.pswd = login_dict['pswd']
self.info = login_dict['info']

def run(self):

Expand All @@ -30,7 +32,7 @@ def run(self):
print('EXCEPT IN TSB')
import traceback
traceback.print_exc()
self.accounts.append(account.account('tsb', 'error', 'error', 'error', 'error', 'error'))
self.accounts.append(account('tsb', 'error', 'error', 'error', 'error', 'error'))

def get_accounts(self):
return self.accounts
Expand Down Expand Up @@ -68,8 +70,6 @@ def login2(self, s, r):
char2label = "frmentermemorableinformation1:strEnterMemorableInformation_memInfo2"
char3label = "frmentermemorableinformation1:strEnterMemorableInformation_memInfo3"

print(soup)

# find the requested character index from login page (index starts at 1)
char = [ int(''.join(c for c in soup.find('label',{'for':char1label}).text if c.isdigit())) \
,int(''.join(c for c in soup.find('label',{'for':char2label}).text if c.isdigit())) \
Expand All @@ -87,11 +87,11 @@ def main_page(self, s, r):

soup = BeautifulSoup(r.text, 'html.parser')

for account in soup.find(id = 'lstAccLst').findAll('li', recursive=False):
for accountEntry in soup.find(id = 'lstAccLst').findAll('li', recursive=False):

# get account details and add to accounts list

r = s.get('https://secure.tsb.co.uk' + account.find('h2').a['href'])
r = s.get('https://secure.tsb.co.uk' + accountEntry.find('h2').a['href'])
soup = BeautifulSoup(r.text, 'html.parser')

accountNumbers = soup.find(class_ = 'numbers').get_text().split(', ')
Expand All @@ -100,10 +100,10 @@ def main_page(self, s, r):
accSort = accountNumbers[0].replace('-', '')
accNumber = accountNumbers[1]

accBalance = get_num(soup.find(class_ = 'balance').get_text())
accAvailable = get_num(soup.find(class_ = 'manageMyAccountsFaShowMeAnchor {bubble : \'fundsAvailable\', pointer : \'top\'}').parent.get_text())
accBalance = self.get_num(soup.find(class_ = 'balance').get_text())
accAvailable = self.get_num(soup.find(class_ = 'manageMyAccountsFaShowMeAnchor {bubble : \'fundsAvailable\', pointer : \'top\'}').parent.get_text())

acc = account.account('nationwide', accSort, accNumber, accName, accBalance, accAvailable)
acc = account('tsb', accSort, accNumber, accName, accBalance, accAvailable)

self.accounts.append(acc)

Expand Down Expand Up @@ -133,18 +133,10 @@ def main_page(self, s, r):

r = s.post('https://secure.tsb.co.uk/personal/a/viewproductdetails/m44_exportstatement_fallback.jsp', data=d)

filename = time.strftime('%Y%m%d') + '-' + accountSort + '-' + accountNumber + '.qif'
filename = time.strftime('%Y%m%d') + '-' + accSort + '-' + accNumber + '.qif'
file = open(filename, 'w')
file.write(r.text)
file.close()

summary.append([accountSort, accountNumber, accountBalance, accountAvailable, filename, accountName])

return summary

def get_num(self, x): # http://stackoverflow.com/a/10365472
return float(''.join(ele for ele in x if ele.isdigit() or ele == '.'))

# userID = 'neelradhakrishnan'
# password = '8rXuehXX1iiChAH'
# info = 'ela18121994'
return float(''.join(ele for ele in x if ele.isdigit() or ele == '.'))
Binary file added banks/__pycache__/Nationwide.cpython-34.pyc
Binary file not shown.
Binary file added banks/__pycache__/Tsb.cpython-34.pyc
Binary file not shown.
27 changes: 7 additions & 20 deletions pybank.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pip install pyyaml appdirs requests beautifulsoup4
#pip install pyyaml appdirs requests beautifulsoup4 tabulate

import threading

# config file imports
import yaml
from appdirs import AppDirs

import account
from tabulate import tabulate

from account import account

# get config from user config file

Expand All @@ -20,34 +22,19 @@

accProviderThreads = []


for accProvider, accProviderDetails in config.items():

print('1')
exec( 'from banks.' + accProvider + ' import ' + accProvider )
values = []

for key, value in accProviderDetails.items():
values.append('\'' + value + '\'')
accProviderThread = eval( accProvider + '()')
accProviderThread.set_login_params(accProviderDetails)

accProviderThread = eval( accProvider + '(' + ','.join(values) + ')')
accProviderThreads.append(accProviderThread)
accProviderThread.start()


for accProviderThread in accProviderThreads:
print(accProviderThread)
accProviderThread.join()
accounts.extend(accProviderThread.get_accounts())


print(accounts)

#print(acc)

#acc = print ( accProvider + '.' + accProvider + '(' + accDetails + ')')
# tsb:


#threading.Thread(target = tsb.do).start()
#threading.Thread(target = nationwide.do).start()accProvider + '.' +
#print(tabulate(accounts))

0 comments on commit 4f29785

Please sign in to comment.