-
Notifications
You must be signed in to change notification settings - Fork 3
/
wellsfargo.py
77 lines (54 loc) · 2.12 KB
/
wellsfargo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium import webdriver
from billmonster import _element_available
from clint import args
from clint.textui import colored, puts
import keyring, sys
def wellsfargo(user=None, quit_when_finished=True, browser=None):
if not user:
# Get the username from the command line arguments.
user = args.get(0)
# Must supply username.
if user is None:
puts(colored.red('You must supply a username like "python wellsfargo.py nick"'))
sys.exit()
# Get the user's password from the password backend.
key = keyring.get_password('wellsfargo.com', user)
# If the key doesn't exist in the password backend.
if key is None:
puts(colored.red("You must store the password for {} in your keyring's backend.".format(user)))
puts('See: http://pypi.python.org/pypi/keyring/#configure-your-keyring-lib')
sys.exit()
# Log what we're currently working on.
puts(colored.blue('\nWells Fargo ({})'.format(user)))
if not browser:
# Init the WebDriver.
b = webdriver.Firefox()
else:
b = browser
b.get('https://www.wellsfargo.com/')
# Find the username field on the page.
username = b.find_element_by_css_selector('input#userid')
username.send_keys(user)
# Find the password field on the page.
password = b.find_element_by_css_selector('input#password')
password.send_keys(key)
password.submit()
# Wait for an account list.
try:
WebDriverWait(b, timeout=10).until(_element_available(b, 'a.account'))
except TimeoutException:
puts(colored.red("Couldn't find any accounts for that username."))
b.quit()
sys.exit()
# Click the first account.
b.find_element_by_css_selector('a.account').click()
amount = b.find_element_by_css_selector('table#balanceDetails td.topRow a')
print 'Wells Fargo ({}): {}'.format(user, amount.text)
if quit_when_finished:
b.quit()
return b
if __name__ == '__main__':
wellsfargo()