本文整理汇总了Python中account.Account类的典型用法代码示例。如果您正苦于以下问题:Python Account类的具体用法?Python Account怎么用?Python Account使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Account类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _view_range_budget
def _view_range_budget(a: Account, timeframe: [(int, int)], width: int) -> str:
"""Returns string of Account's budget tuple over a certain time period
"""
bud_lim = ((width-10)//11) # How many budgets can be on one line
it = len(timeframe) # How many budgets that will be displayed
set_lim = it//bud_lim + 1 # How many sets to iterate through
set_apprch = 0; bud_apprch = 0; lines = list()
while set_apprch != set_lim:
set_apprch += 1
title_sub_str = "Account {} for set {}".format(a.get_name(), set_apprch)
hd = "="*width + "\n"
space_amt = width//2-len(title_sub_str)
title_str = "{}{}{}".format(" "*space_amt, title_sub_str, " "*space_amt)
attrib_str = "Attribute|"
goal_str = "Goal.....|"
reach_str = 'Reached..|'
remain_str = "Remaining|"
for y,m in timeframe[(set_apprch-1)*min(bud_lim, it):set_apprch*min(bud_lim, it)]:
bud_apprch += 1
attrib_str += " {} {}|".format(bc.months_abv(m), y+1)
g_str = "{:.2f}".format(a.get_goal(y,m)/100)
goal_str += "."*(10-len(g_str)) + g_str+"|"
r_str = "{:.2f}".format(a.get_reached(y,m)/100)
reach_str += "."*(10-len(r_str)) + r_str+"|"
e_str = "{:.2f}".format(a.get_remain(y,m)/100)
remain_str += "."*(10-len(e_str)) + e_str + "|"
lines.append(title_str + "\n" + hd + attrib_str + "\n" + goal_str + "\n" + reach_str + "\n" + remain_str + "\n")
return "\n".join(lines)
示例2: cprint
def cprint(a: Account):
"""Clean prints an Account
"""
print("Account({},{},".format(a.get_name(), a.get_kind()))
pprint(a.get_ts())
print(",")
pprint(a.get_budgets())
示例3: modify
def modify(self, account, newname = None):
if not Account.hasSupport(account.network):
return False
if not self.exists(account):
return False
pm = PersistenceManager()
if not pm.existsConfig():
return False
config = pm.readConfig()
accountType = Account.networkToAccount(account.network)
for entry in config['accounts'][account.network]:
if entry['name'] == account.name:
if newname:
entry['name'] = newname
if accountType == 'OAuth':
entry['key'], entry['secret'] = account.credentials()
elif accountType == 'UserPass':
entry['user'], entry['password'] = account.credentials()
break
pm.writeConfig(config)
return True
示例4: new_account
def new_account():
"""
Endpoint for creating new accounts when the app is installed.
Returns the account id and the account's secret key.
"""
if not request.form.get('uuid'):
return api_error('must provide a device uuid')
uuid = request.form['uuid'].strip()
name = request.form['name'].strip() if 'name' in request.form else None
email = request.form['email'].strip() if 'email' in request.form else None
phone = request.form['phone'].strip() if 'phone' in request.form else None
if phone == '':
phone = None
if Account.uuid_used(uuid):
return user_error('an account already exists for this device.')
if phone and Account.phone_used(phone):
return user_error('phone number already in use')
if email and Account.email_used(email):
return user_error('email already in use')
new_account = Account.new(uuid, name, phone, email)
if not new_account:
return api_error('unable to create new account')
ret = {'aid': new_account.aid, 'key': new_account.key}
return jsonify(**ret)
示例5: main
def main():
try:
rate_history = RateHistory(u"配置.ini")
print rate_history
# return
if len(sys.argv) < 2:
data_file = raw_input(u"请输入文件名称:".encode('gbk')).decode('gbk')
else:
data_file = sys.argv[1]
if not os.path.isfile(data_file):
print u"文件'%s'不存在" % data_file
exit(0)
balance_list = load_balance_flow(data_file)
acc = Account(rate_history)
earn = acc.interest(balance_list)
open(u"明细.csv", "w").write(str(acc))
print u"余额明细如下\n%s" % acc
print u"明细可参考文档'明细.csv'"
print u"总利息 %s亿,余额 %s亿" % (earn, acc.total_amount())
print u"计算完成!"
except Exception, e:
print u"异常:%s" % str(e)
traceback.print_tb()
示例6: getAllByNetwork
def getAllByNetwork(self, network):
if not Account.hasSupport(network):
return None
pm = PersistenceManager()
if not pm.existsConfig():
return None
config = pm.readConfig()
accounts = []
accountType = Account.networkToAccount(network)
for entry in config['accounts'][network]:
account = Account.getAccount(network, entry['name'])
if accountType == 'OAuth':
account.setCredentials((entry['key'], entry['secret']))
elif accountType == 'UserPass':
account.setCredentials((entry['user'], entry['password']))
accounts.append(account)
return accounts
示例7: test_checking_account
def test_checking_account():
bank = Bank()
checkingAccount = Account(CHECKING)
bill = Customer("Bill").openAccount(checkingAccount)
bank.addCustomer(bill)
checkingAccount.deposit(100.0)
assert_equals(bank.totalInterestPaid(), 0.1)
示例8: AccountTest
class AccountTest(unittest.TestCase):
def setUp(self):
self.account = Account(number='123456', holder='Linus')
def test_it_has_a_number(self):
self.account.number |should| equal_to('123456')
def test_it_as_a_holder(self):
self.account.holder |should| equal_to('Linus')
def test_it_has_a_balance_beginning_at_zero(self):
self.account.balance |should| be(0)
def test_it_allows_deposit(self):
self.account.deposit(100)
self.account.balance |should| be(100)
self.account.deposit(100)
self.account.balance |should| be(200)
def test_it_allows_withdrawals(self):
self.account.deposit(100)
self.account.withdrawal(75)
self.account.balance |should| be(25)
def test_it_raises_an_error_for_insufficient_balance(self):
self.account.deposit(100)
(self.account.withdrawal, 100.01) |should| throw(InsufficientBalance)
示例9: draw
def draw(uid, currency):
s = current_session()
u = Account.find(uid)
if not u:
raise exceptions.UserNotFound
helpers.require_free_backpack_slot(s, uid)
if currency == 'ppoint':
amount = constants.LOTTERY_PRICE
Account.add_user_credit(u, [('ppoint', -amount)],
exceptions.InsufficientFunds)
elif currency == 'jiecao':
amount = constants.LOTTERY_JIECAO_PRICE
Account.add_user_credit(u, [('jiecao', -amount)],
exceptions.InsufficientFunds)
else:
raise exceptions.InvalidCurrency
reward = random.choice(constants.LOTTERY_REWARD_LIST)
item = Item(owner_id=uid, sku=reward, status='backpack')
s.add(item)
s.flush()
s.add(ItemActivity(
uid=uid, action='lottery', item_id=item.id,
extra=json.dumps({'currency': currency, 'amount': amount}),
created=datetime.datetime.now(),
))
return reward
示例10: _new
def _new(cls, author, link, parent, body, ip):
from r2.lib.db.queries import changed
c = Comment(_ups=1, body=body, link_id=link._id, sr_id=link.sr_id, author_id=author._id, ip=ip)
c._spam = author._spam
# these props aren't relations
if parent:
c.parent_id = parent._id
link._incr("num_comments", 1)
to = None
name = "inbox"
if parent:
to = Account._byID(parent.author_id, True)
elif link.is_self and not link.noselfreply:
to = Account._byID(link.author_id, True)
name = "selfreply"
c._commit()
changed(link, True) # only the number of comments has changed
inbox_rel = None
# only global admins can be message spammed.
if to and (not c._spam or to.name in g.admins):
inbox_rel = Inbox._add(to, c, name)
return (c, inbox_rel)
示例11: add_handler
def add_handler(sub_args):
alias = sub_args.alias
service = sub_args.service
account = sub_args.account
if alias is None:
alias = str(click.prompt("Please type an alias to store the credential (this alias must be unique)"))
if not _alias_valid(alias):
select = Account.select().where(Account.alias == alias)
service = str(select[0].service)
account = str(select[0].account)
sys.exit("Aborting , this alias already exist for the service " + service + " and the account " + account)
if service is None:
service = str(click.prompt("Please type the name of the service you want to use"))
if not sub_args.noformat:
if service.split("://")[0].lower() == "http":
service = urlparse(service).netloc
service = service.lower()
if account is None:
account = str(click.prompt("Please enter the account for the credential (aka login)"))
select = Account.select().where((Account.service == service) & (Account.account == account))
if len(select) != 0:
print "The account " + account + " associated to the service " + service + " already exist"
if not click.confirm("Do you wish to continue adding this credential ?"):
sys.exit("Aborting")
passphrase = getpass.getpass("Enter passphrase:")
Account.create(service=service,
account=account,
passphrase=passphrase,
alias=alias)
示例12: _new
def _new(cls, author, link, parent, body, ip):
c = Comment(body = body,
link_id = link._id,
sr_id = link.sr_id,
author_id = author._id,
ip = ip)
c._spam = author._spam
#these props aren't relations
if parent:
c.parent_id = parent._id
c._commit()
link._incr('num_comments', 1)
to = None
if parent:
to = Account._byID(parent.author_id)
elif link.is_self:
to = Account._byID(link.author_id)
inbox_rel = None
# only global admins can be message spammed.
if to and (not c._spam or to.name in g.admins):
inbox_rel = Inbox._add(to, c, 'inbox')
return (c, inbox_rel)
示例13: _new
def _new(cls, author, link, parent, body, ip,criticism=False):
from r2.lib.db.queries import changed
#We're turing it off for now...
criticism = False
c = Comment(_ups = 1,
body = body,
link_id = link._id,
sr_id = link.sr_id,
author_id = author._id,
ip = ip)
c._spam = author._spam
c.criticism=criticism
#these props aren't relations
if parent:
c.parent_id = parent._id
#should increment based on crit flag
#Each should contain the root author and its id, problem is the id isn't created yet if we're the root so have to be clever
if criticism:
link._incr("num_criticisms",1)
if parent:
c.rootauthor=parent.rootauthor
if parent.rootid:
c.rootid=parent.rootid
else:
c.rootid=parent._id
else:
c.rootauthor=author._id
c.rootid=False
else:
link._incr('num_comments', 1)
to = None
name = 'inbox'
if parent:
to = Account._byID(parent.author_id, True)
elif link.is_self and not link.noselfreply:
to = Account._byID(link.author_id, True)
name = 'selfreply'
c._commit()
changed(link, True) # link's number of comments changed
inbox_rel = None
# only global admins can be message spammed.
# Don't send the message if the recipient has blocked
# the author
if to and ((not c._spam and author._id not in to.enemies)
or to.name in g.admins):
# When replying to your own comment, record the inbox
# relation, but don't give yourself an orangered
orangered = (to.name != author.name)
inbox_rel = Inbox._add(to, c, name, orangered=orangered)
return (c, inbox_rel)
示例14: get_default_account
def get_default_account(cls):
# we are not going to set the id, because we never save this
url = 'blogtest.letseatalready.com'
username = 'test'
password = 'test'
default_account = Account(url, username, password)
default_account.set_section_id(AccountManager.DEFAULT_ACCOUNT_ID)
return default_account
示例15: _view_all_budgets
def _view_all_budgets(a: Account, width: int) -> str:
"""Returns string of Account's budget tuple over all time periods.
Prints out strings with the specified maximum width
"""
r = sorted(
[(y,m) for y in a.get_budgets() for m in a.get_budgets(y)],
key=lambda x: (x[0], x[1]), reverse = True)
return "\n"+_view_range_budget(a, r, width)