本文整理汇总了Python中datastore.Drinker.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Drinker.objects方法的具体用法?Python Drinker.objects怎么用?Python Drinker.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datastore.Drinker
的用法示例。
在下文中一共展示了Drinker.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cashmoney
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def cashmoney(self):
whom = self.lastsender
drinker = Drinker.objects(name=whom).first()
if not drinker:
drinker = Drinker(name=whom)
self.chat("You gots $%.02f" % drinker.cash)
示例2: _get_drinker
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def _get_drinker(self):
drinker = Drinker.objects(name=self.lastsender).first()
if not drinker:
self.chat("Be gone peasant.")
return None
return drinker
示例3: portfolio
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def portfolio(self):
if not self.values:
whom = self.lastsender
else:
whom = self.values[0]
drinker = Drinker.objects(name=whom).first()
if not drinker:
self.chat("%s doesn't exist" % whom)
return
if not drinker.positions:
self.chat("%s doesn't have one" % whom)
else:
drinker.positions.sort(key=lambda p: p.symbol)
self.chat("%8s %10s %10s %10s %10s %10s" % ('type', 'symbol',
'qty', 'price', 'last', 'gain'))
total = 0
for p in drinker.positions:
stock = Stock(p.symbol)
if p.type == 'long':
net = p.quantity * (stock.price - p.price)
else:
net = p.quantity * (p.price - stock.price)
self.chat("%8s %10s %10d %10.02f %10.02f %10.02f" % \
(p.type, p.symbol, p.quantity, p.price, stock.price,
net))
total += net
self.chat("%8s %10s %10s %10s %10s %10.02f" % ('', '', '', '', '', total))
示例4: sms
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def sms(self):
if self.context != CHANNEL:
self.chat("No private sms abuse. Tsk tsk.")
return
if not self.values:
self.chat("-sms <number> <message>")
return
to = self.values[0]
msg = " ".join(self.values[1:])
if not re.search("^[+0-9]+$", to):
user = Drinker.objects(name=to).first()
if not user or not user.phone:
self.chat('No num found')
return
else:
to = user.phone
try:
message = self.client.sms.messages.create(
body=msg,
to=to,
from_=TWILIO_NUMBER
)
self.chat("Message sent: " + message.sid)
except:
self.chat("Done broke")
return
示例5: __init__
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def __init__(self, *arguments, **keywords):
if not len(arguments) and len(keywords):
# Prepend 'data__' to all keywords for appropriate searching in data dictfield
keywords = dict(map(lambda (key, value): ('data__' + str(key), value), keywords.items()))
# Search for a user with the data field
self.prop = Drinker.objects(**keywords).first()
if self.prop:
self.nick = self.prop.name
else:
user = arguments[0]
self.fullid = user
try:
self.nick, self.ident = user.split('!')
self.host = self.ident.split('@', 1)[1]
except:
self.nick = user
try:
self.ip = socket.gethostbyname_ex(self.host.strip())[2][0]
except:
pass
if not self.nick:
return
# ident not getting set for some reason?
self.is_recognized = True
self.prop = Drinker.objects(name=self.nick).first()
if not self.prop:
self.prop = Drinker(name=self.nick)
self.is_recognized = False
if self.ident in self.prop['idents']:
self.is_authenticated = True
secrets = load_config('config/secrets.yaml')
if self.nick == secrets.owner and self.is_authenticated:
self.is_owner = True
示例6: digits
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def digits(self):
if not self.values:
search_for = self.lastsender
else:
search_for = self.values[0]
user = Drinker.objects(name=search_for).first()
if not user or not user.phone:
return "No such numba. No such zone."
else:
return user.name + ': ' + user.phone
示例7: company
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def company(self):
if not self.values:
search_for = self.lastsender
else:
search_for = self.values[0]
user = Drinker.objects(name=search_for).first()
if user and user.company:
self.chat(user.name + ": " + user.company)
else:
self.chat("Tell that deadbeat %s to get a damn job already..." % search_for)
示例8: _create_position
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def _create_position(self, ptype):
whom = self.lastsender
try:
quantity = int(self.values[0])
symbol = self.values[1]
except:
self.chat("That's not right")
return
if quantity <= 0:
self.chat("Do you think this is a muthafuckin game?")
return
stock = Stock(symbol)
if not stock:
self.chat("Stock not found")
return
if stock.exchange.upper() not in VALID_EXCHANGES:
self.chat("Stock exchange %s DENIED!" % stock.exchange)
return
if stock.price < 0.01:
self.chat("No penny stocks")
return
drinker = Drinker.objects(name=whom).first()
if not drinker:
drinker = Drinker(name=whom)
cost = stock.price * quantity
if cost > drinker.cash:
self.chat("You is poor")
return
position = Position(symbol=stock.symbol,
price=stock.price,
quantity=quantity,
date=datetime.utcnow(),
type=ptype)
drinker.positions.append(position)
drinker.cash -= cost
drinker.save()
verb = 'bought' if ptype == 'long' else 'shorted'
self.chat("%s %s %d shares of %s (%s) at %s" %
(whom, verb, position.quantity, stock.company,
position.symbol, position.price))
示例9: workat
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def workat(self):
if not self.values:
self.chat("If you're unemployed, that's cool, just don't abuse the bot")
return
name = self.lastsender
company = " ".join(self.values)
drinker = Drinker.objects(name=name)
if drinker:
drinker = drinker[0]
drinker.company = company
else:
drinker = Drinker(name=name, company=company)
drinker.save()
示例10: smsticker
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def smsticker(self):
self.current = mktime(localtime())
if self.current < self.next_:
return
self.next_ += 10
try:
messages = self.client.sms.messages.list(to=TWILIO_NUMBER)
except:
print "Error fetching"
return
while messages:
item = messages.pop()
sid = item.sid
if sid in self.incoming:
continue
self.incoming.append(sid)
if not self.loaded:
continue
clipped = item.from_[2:]
drinker = Drinker.objects(phone=clipped)
if drinker:
from_ = drinker[0].name
else:
from_ = item.from_
message = "SMS from " + from_ + ": " + item.body
self.announce(message)
if item.body[:1] == CONTROL_KEY and (drinker and item.from_ != TWILIO_NUMBER or item.from_ in SAFE_NUMBERS):
self.cx.context = CHANNEL
self.cx.replysms = from_
# TODO: make this a butler call
self.cx.command(drinker[0].name, item.body)
self.loaded = True
示例11: awaiting
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def awaiting(self):
if not self.values:
self.chat("Whatchu waitin fo?")
return
name = self.lastsender
awaits = " ".join(self.values)
drinker = Drinker.objects(name=name)
if drinker:
drinker = drinker[0]
drinker.awaiting = awaits
else:
drinker = Drinker(name=name, awaiting=awaiting)
drinker.save()
return "Antici..... pating."
示例12: smsticker
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def smsticker(self):
self.current = mktime(localtime())
if self.current < self.next_:
return
self.next_ += 10
try:
messages = self.client.sms.messages.list(to="+16468635380")
except:
print "Error fetching"
print messages
return
while messages:
item = messages.pop()
sid = item.sid
if sid in self.incoming:
continue
self.incoming.append(sid)
if not self.loaded:
continue
clipped = item.from_[2:]
drinker = Drinker.objects(phone=clipped)
if drinker:
from_ = drinker[0].name
else:
from_ = item.from_
message = "SMS from " + from_ + ": " + item.body
self.announce(message)
if item.body[:1] == CONTROL_KEY and drinker:
self.cx.context = CHANNEL
self.cx.command(drinker[0].name, item.body)
self.loaded = True
示例13: workat
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def workat(self):
if not self.values:
return 'If you\'re unemployed, that\'s cool, just don\'t abuse the bot'
user = Id(self.lastid)
if not user.is_authenticated:
return 'That\'s cool bro, but I don\'t know you!'
drinker = Drinker.objects(name=user.name)
if drinker:
drinker = drinker[0]
drinker.company = ' '.join(self.values)
else:
drinker = Drinker(name=user.name, company=' '.join(self.values))
drinker.save()
return 'I know where you work... watch your back.'
示例14: timeleft
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def timeleft(self):
if not self.values:
search_for = self.lastsender
else:
search_for = self.values[0]
drinker = Drinker.objects(name=search_for).first()
if not drinker or not drinker.awaiting:
self.chat("%s waits for nothing." % search_for)
return
try:
moment, event = drinker.awaiting.split("=")
year, month, day = moment.split("/")
delta = datetime.date(int(year), int(month), int(day)) - datetime.date.today()
return "Only %s days till %s" % (delta.days, event)
except:
self.chat("Couldn't parse that out.")
示例15: stockscore
# 需要导入模块: from datastore import Drinker [as 别名]
# 或者: from datastore.Drinker import objects [as 别名]
def stockscore(self):
if self.values:
drinkers = Drinker.objects(name__in=self.values)
else:
drinkers = Drinker.objects
scores = []
for drinker in drinkers:
# Assume these people are not playing.
if not drinker.positions and drinker.cash == STARTING_CASH:
continue
total = 0
collateral = 0
cash = drinker.cash
for p in drinker.positions:
stock = Stock(p.symbol)
if p.type == 'long':
net = p.quantity * stock.price
else:
net = -p.quantity * stock.price
collateral += 2 * p.quantity * p.price
if net >= 10000000:
# Get rid of stupid twitter positions
continue
total += net
scores.append((drinker.name, cash, collateral,
total, cash + collateral + total))
if not scores:
self.chat("can't find 'em, won't find 'em")
else:
scores.sort(key=lambda x: x[4], reverse=True)
self.chat("%15s %10s %10s %10s %10s" %
('drinker', 'cash', 'collateral', 'value', 'total'))
for s in scores:
self.chat("%15s %10.02f %10.02f %10.02f %10.02f" % s)