This repository has been archived by the owner on Nov 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontrol2.py
115 lines (98 loc) · 3.34 KB
/
control2.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# control2.py
# http://sites.google.com/site/pocketsense/
# contains some common configuration data and modules for the ofx pkg
# Initial version: rlc: Feb-2010
#
# 27-Jul-2013: rlc
# - Added locale support
#
# 03-Sep-2014: rlc
# - xfrdir is now platform independent
#------------------------------------------------------------------------------------
#---MODULES---
import os, sys, pyDes, glob, pickle, locale
#04-Jan-2010*rlc
# - Added DefaultAppID and DefaultAppVer
Debug = False #debug mode = true only when testing
#Debug = True
AboutTitle = 'PocketSense OFX Download Python Scripts'
AboutVersion = '14-Sep-2015'
AboutSource = 'http://sites.google.com/site/pocketsense'
AboutName = 'Robert'
#xfrdir = temp directory for statement downloads. Platform independent
xfrdir = os.path.join(os.path.curdir,"xfr") + os.sep
if Debug: print "XFRDIR = " + xfrdir
cfgFile = 'ofx_config.cfg' #user account settings (can be encrypted)
DefaultAppID = 'QWIN'
DefaultAppVer = '2200'
if Debug:
import traceback
def get_int(prompt):
#get number entry
prompt = prompt.rstrip() + ' '
done = False
while not done:
istr = raw_input(prompt)
if istr == '':
a = 0
done = True
else:
try:
a=int(istr)
done = True
except:
print 'Please enter a valid integer'
return a
def FieldVal(dic, fieldname):
#get field value from a dict list
#return value for fieldname (returns as type defined in dict)
val = ''
fieldname = fieldname.upper()
if fieldname in dic:
val = dic[fieldname]
return val
def decrypt_pw(pwkey):
#validate password if pwkey isn't null
if pwkey <> '':
#file encrypted... need password
pw = pyDes.getDESpw() #ask for password
k = pyDes.des(pw) #create encryption object using key
pws = k.decrypt(pwkey,' ') #decrypt
if pws <> pw: #comp to saved password
print 'Invalid password. Exiting.'
sys.exit()
else:
#decrypt the encrypted fields
pwkey = pws
return pwkey
def acctEncrypt(AcctArray, pwkey):
#encrypt accounts
d = pyDes.des(pwkey)
for acct in AcctArray:
acct[1] = d.encrypt(acct[1],' ')
acct[3] = d.encrypt(acct[3],' ')
acct[4] = d.encrypt(acct[4],' ')
return AcctArray
def acctDecrypt(AcctArray, pwkey):
#decrypt accounts
d = pyDes.des(pwkey)
for acct in AcctArray:
acct[1] = d.decrypt(acct[1],' ')
acct[3] = d.decrypt(acct[3],' ')
acct[4] = d.decrypt(acct[4],' ')
return AcctArray
def get_cfg():
#read in user configuration
c_AcctArray = [] #AcctArray = [['SiteName', 'Account#', 'AcctType', 'UserName', 'PassWord'], ...]
c_pwkey='' #default = no encryption
c_getquotes = False #default = no quotes
if glob.glob(cfgFile) <> []:
cfg = open(cfgFile,'rb')
try:
c_pwkey = pickle.load(cfg) #encrypted pw key
c_getquotes = pickle.load(cfg) #get stock/fund quotes?
c_AcctArray = pickle.load(cfg) #
except:
pass #nothing to do... must not be any data in the file
cfg.close()
return c_pwkey, c_getquotes, c_AcctArray