1 import os, pwd, hashlib, pickle
5 if mod.startswith("fulbank."):
7 return "%s.%s" % (mod, type.__name__)
11 def number(self): raise NotImplementedError("account.number")
13 def name(self): raise NotImplementedError("account.name")
14 def transactions(self): raise NotImplementedError("account.transactions")
17 return "#<%s %s: %r>" % (_localname(type(self)), self.number, self.name)
19 class txnaccount(account):
21 def balance(self): raise NotImplementedError("txnaccount.balance")
23 def clearing(self): raise NotImplementedError("txnaccount.clearing")
25 def fullnumber(self): raise NotImplementedError("txnaccount.fullnumber")
27 class cardaccount(account):
30 class transaction(object):
32 def value(self): raise NotImplementedError("transaction.value")
34 def message(self): raise NotImplementedError("transaction.message")
36 def date(self): raise NotImplementedError("transaction.date")
40 dig = hashlib.sha256()
41 dig.update(str(self.date.toordinal()).encode("ascii") + b"\0")
42 dig.update(self.message.encode("utf-8") + b"\0")
43 dig.update(str(self.value.amount).encode("ascii") + b"\0")
44 dig.update(self.value.currency.symbol.encode("ascii") + b"\0")
45 return dig.hexdigest()
48 return "#<%s %s: %r>" % (_localname(type(self)), self.value, self.message)
50 class session(object):
51 def save(self, filename):
52 with open(filename, "wb") as fp:
57 with open(filename, "rb") as fp:
58 return pickle.load(fp)
64 raise ValueError("no such known session type: " + name)
67 return os.path.join(pwd.getpwuid(os.getuid()).pw_dir, ".cache/fulbank", name)
70 ret = os.getenv("NETBANKSESS")
75 def loadsess(name=None, default=FileNotFoundError):
76 if name is None: name = defaultsess()
77 path = _sesspath(name)
78 if not os.path.exists(path):
79 if default is FileNotFoundError:
80 raise FileNotFoundError(name)
82 return session.load(path)
84 def savesess(sess, name=None):
85 if name is None: name = defaultsess()
86 path = _sesspath(name)
88 sessdir = os.path.dirname(path)
89 if not os.path.isdir(sessdir):
91 return sess.save(_sesspath(name))
93 if os.path.exists(path):
96 class savedsess(object):
97 def __init__(self, name=None):
98 if name is None: name = defaultsess()
103 self.sess = loadsess(self.name)
107 savesess(self.sess, name)