本文整理汇总了Python中datastore.Drinker类的典型用法代码示例。如果您正苦于以下问题:Python Drinker类的具体用法?Python Drinker怎么用?Python Drinker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Drinker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_position
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))
示例2: portfolio
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))
示例3: cashmoney
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)
示例4: _get_drinker
def _get_drinker(self):
drinker = Drinker.objects(name=self.lastsender).first()
if not drinker:
self.chat("Be gone peasant.")
return None
return drinker
示例5: workat
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()
示例6: sms
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
示例7: awaiting
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."
示例8: __init__
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
示例9: workat
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.'
示例10: digits
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
示例11: company
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)
示例12: __init__
def __init__(self, user):
try:
self.nick, data = user.split('!')
self.ident, self.host = data.split('@')
except Exception as e:
pprint(e)
return
settings = load_config('config/settings.yaml')
auth_data = load_config(settings.directory.authfile)
if self.nick in auth_data:
self.is_authenticated = True
if 'owner' in auth_data[self.nick] and auth_data[self.nick].owner:
self.is_owner = True
self.prop = Drinker.objects(name=self.nick).first()
if not self.prop:
self.prop = Drinker(name=self.nick)
示例13: salias
def salias(self):
whom = self.lastsender
name = self.values[0]
evil = ['salias', 'ralias', 'lalias', 'dalias']
definition = ' '.join(self.values[1:])
drinker = Drinker.objects(name=whom).first()
if not name:
self.chat("Nope.")
return
if any(sin in definition for sin in evil):
self.chat("You're trying to hurt me aren't you?")
return
if not drinker:
drinker = Drinker(name=whom)
new_alias = Alias(name=name, definition=definition)
drinker.aliases.append(new_alias)
drinker.save()
self.chat(name + " saved.")
示例14: reward
def reward(self):
if not self.values:
self.chat("Reward whom?")
return
kinder = self.values[0]
if kinder == self.ego.nick:
self.chat("Service is own reward for " + self.ego.nick)
return
drinker = Drinker.objects(name=kinder)
if drinker:
drinker = drinker[0]
rewards = drinker.rewards + 1
else:
drinker = Drinker(name=kinder)
rewards = 1
drinker.rewards = rewards
drinker.save()
self.chat("Good job, " + kinder + ". Here's your star: " + colorize(u'\u2605', "yellow"))
self._act(" pats " + kinder + "'s head.")
示例15: smsticker
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