本文整理汇总了Python中core.people.person.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
"""default method"""
#start sqlalchemy session
sess = Session()
sender = self.req_obj.get('sender', '')
#exctract sender email
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
if profile:
pass
response = 'sorry you are not allowed to tweet'
if profile.type == 'admin' and self.req_from == 'jabber':
response = tweet(" ".join(self.args))
response = 'Done. Check it at http://twitter.com/myname'
if self.req_from == 'jabber':
todo = {'text': response, 'jmsg': response, 'type': 'response'}
self.response = todo
if self.req_from == 'julius':
bang()
todo = {'say': response, 'text': response, 'type': 'response'}
self.response = say(self.request.replace('say', '').upper())
return self.response
示例2: run
def run(self):
"""default method"""
sess = Session()
sender = self.req_obj.get('sender', '')
uuid = self.req_obj.pop('uuid', '')
hosts = None
profile = None
response = ''
#exctract sender email
if sender:
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(
Profile.email == email).one()
if uuid:
#find user profile by uuid
profile = sess.query(Profile).filter(
Profile.uuid == uuid).one()
if profile:
hosts = sess.query(ProfileLink).filter(
ProfileLink.uuid == profile.uuid).all()
code = -1
if hosts:
for h in hosts:
logger.info('open http connection to %s ..' % h.url)
try:
r = urllib2.urlopen(h.url)
code = r.code
except Exception:
code = -1
#logger.exception(e)
if code != 200:
response += "Could not connect %s \n" % (h.url)
else:
response = 'you have no urls that I can check, ' + \
'add url by command: add url http://mysite.com'
if self.req_from == 'jabber':
if response == '':
response = 'looks like everything is ok.'
todo = {'text': response, 'jmsg': response, 'type': 'response'}
self.response = todo
elif self.req_from == 'julius':
bang()
todo = {'say': response, 'text': response, 'type': 'response'}
self.response = say(self.request.replace('say', '').upper())
elif response:
send(settings.MY_ACCOUNTS['gmail']['email'],
profile.email,
'check my sites report from Smarty',
response)
todo = {'text': response, 'jmsg': response, 'type': 'response'}
self.response = todo
return self.response
示例3: run
def run(self):
"""default method"""
#start sqlalchemy session
sess = Session()
sender = self.req_obj.get('sender', '')
#exctract sender email
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
if profile:
pass
response = 'Sorry, you are not allowed to execute this action'
if profile.type == 'admin' and self.req_from == 'jabber':
upgrade()
response = 'Upgrade started.'
if self.req_from == 'jabber':
todo = {'text': response, 'jmsg': response, 'type': 'response'}
self.response = todo
if self.req_from == 'julius':
bang()
todo = {'say': response, 'text': response, 'type': 'response'}
self.response = say(self.request.replace('say', '').upper())
return self.response
示例4: run
def run(self):
"""default method"""
sess = Session()
sender = self.req_obj.get('sender', '')
response = 'done.'
req = self.request.replace(
'create new reaction ', '', 1).replace('"', "")
if sender:
#extract sender email
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
if profile:
self.create_new_reaction(req)
if self.req_from == 'jabber':
todo = {'text': response, 'jmsg': response, 'type': 'response'}
self.response = todo
if self.req_from == 'julius':
bang()
todo = {'say': response, 'text': response, 'type': 'response'}
self.response = say(self.request.replace('say', '').upper())
return self.response
示例5: run
def run(self):
"""default method"""
sess = Session()
sender = self.req_obj.get('sender', '')
#exctract sender email
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
cron = CronTab(getuser())
msg = ''
job = cron.new(command='/usr/bin/python %s/core/cron/cronjob.py --uuid=%s --cmd="check my sites" --arguments="%s"' % (ROBOT_DIR, profile.uuid, msg.replace('"', '')))
#every hour
job.minute.on(0)
cron.write()
response = 'ok, cronjob added %s' % job.render()
if self.req_from == 'jabber':
todo = {'text': response, 'jmsg': response, 'type': 'response'}
self.response = todo
if self.req_from == 'julius':
bang()
todo = {'say': response, 'text': response, 'type': 'response'}
self.response = say(self.request.replace('say', '').upper())
return self.response
示例6: run
def run(self):
"""default method"""
sess = Session()
sender = self.req_obj.get('sender', '')
subdir = ROBOT_DIR.child('core', 'brain', 'remind', 'me')
logger.info(subdir)
#exctract sender email
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
response = ''
if profile:
response = profile.first_name + ', '
pass
response += "how do you want to be reminded ?\nHere are some examples of how you can set a reminder:\n"
l = [" ".join(p.format().split('/')[2:]) for p in subdir.relative().listdir() if p.isdir()]
response += "\n".join(l)
if self.req_from == 'jabber':
todo = {'text': response, 'jmsg': response, 'type': 'response'}
self.response = todo
if self.req_from == 'julius':
from core.broadcast import say, bang
bang()
todo = {'say': response, 'text': response, 'type': 'response'}
self.response = say(self.request.replace('say', '').upper())
return self.response
示例7: run
def run(self):
"""default method"""
sess = Session()
sender = self.req_obj.get('sender', '')
#exctract sender email
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
cron = CronTab('smarty')
job = cron.new( command='/usr/bin/python %s/cron/cronjob.py --uuid=%s ' % ( ROBOT_DIR, profile.uuid ))
logger.info('show cronjob %s' % cron.render() )
list = cron.find_command( '--uuid=%s' % profile.uuid )
response = 'all my cronjobs'
for job in list:
response += "\n" + job
if self.req_from == 'jabber':
todo = { 'text' : response, 'jmsg' : response, 'type': 'response' }
self.response = todo
if self.req_from == 'julius':
bang()
todo = { 'say': response , 'text' : response ,'type': 'response' }
self.response = say(self.request.replace('say', '').upper())
return self.response
示例8: on_continue
def on_continue(self, msg):
"""docstring for on_continue"""
todo = {}
response = "Ok."
#request = msg.get('request', None)
sender = msg.get('sender', '')
req_from = msg.get('from', '')
#error = msg.get('error', '')
#logger.info('error %s..........................' % error)
#logger.info('req_from %s..........................' % req_from)
#logger.info('request %s..........................' % request)
sess = Session()
#exctract sender email
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
#if self.is_correct_format(request):
#insert = {}
#insert['uuid'] = profile.uuid
#insert['type'] = 'custom'
#insert['created'] = datetime.datetime.now()
#logger.debug('request type %s' % type(request), request)
#insert['spent'] = request
#try:
#ts = ProfileTimesheet(**insert)
#sess.add(ts)
#sess.commit()
#except Exception as e:
#sess.rollback()
#logger.exception(e)
#report_bug(e)
#response = 'I could not save it, problem has \
#been already reported to developer'
#else:
#response = " type something like: 8 hours "
#todo['continue'] = 1
if req_from == 'jabber':
todo = {'text': response,
'jmsg': response,
'type': 'response',
'continue': 0}
self.response = todo
if req_from == 'julius':
from core.broadcast import say, bang
bang()
todo = {'say': response,
'text': response,
'type': 'response',
'continue': 0}
self.response = say(self.request.replace('say', '').upper())
return self.response
示例9: on_continue
def on_continue(self, msg):
"""docstring for on_continue"""
#print('nice, continue with:')
request = msg.get('request', None)
sender = msg.get('sender', '')
req_from = msg.get('from', '')
error = msg.get('error', '')
#logger.info('error %s..........................' % error)
#logger.info('req_from %s..........................' % req_from)
#logger.info('request %s..........................' % request)
sess = Session()
#exctract sender email
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
#logger.info('profile %s..........................' % profile)
if error:
if agree(request):
report_bug('user %s can not find cronjobs ' % profile.uuid)
response = 'ok, reported.. '
response += 'by the way, you can add a reminder with command: *remind me every day at 10:00 with message "Do not forget to drink coffee"* '
else:
response = 'ok'
response += ' by the way, you can add a reminder with command: \
*remind me every day at 10:00 with message "Do not forget to drink coffee"* '
self.response = {'text': response, 'jmsg': response, 'type': 'response', 'continue': 0}
return self.response
cron = CronTab(getuser())
if agree(request):
logger.info('deleting all cronjobs for %s' % ( profile.email))
for j in cron:
if profile.uuid in j.render():
cron.remove(j)
cron.write()
response = 'ok, done'
else:
response = "ok"
if req_from == 'jabber':
todo = {'text': response, 'jmsg': response, 'type': 'response', 'continue': 0}
self.response = todo
if req_from == 'julius':
from core.broadcast import say, bang
bang()
todo = {'say': response, 'text': response, 'type': 'response', 'continue': 0}
self.response = say(self.request.replace('say', '').upper())
return self.response
示例10: run
def run(self):
"""default method"""
skip_other = False
sess = Session()
sender = self.req_obj.get('sender', '')
#exctract sender email
email = sender.split('/')[0]
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
req = self.request.replace('ping my sites every day', '', 1)
msg = ''
cron = CronTab(getuser())
job = cron.new(command='/usr/bin/python %s/core/cron/cronjob.py --uuid=%s --cmd="ping my sites" --arguments="%s"' % (ROBOT_DIR, profile.uuid, msg.replace('"', '')))
if req.strip().startswith('at '):
################################################
# every day at 10 o'clock
################################################
time = re.search("[^0-9](\d{1,2})\so'clock", req)
if time and time.group(1):
job.minute.on(0)
job.hour.on(time.group(1))
skip_other = True
################################################
# every day at 00:00
################################################
if not skip_other:
time = re.search('[^0-9](\d{1,2}):(\d{2})[^0-9]', req)
if time and time.group(1) and time.group(2):
job.minute.on(time.group(2))
job.hour.on(time.group(1))
skip_other = True
cron.write()
logger.info('adding cronjob %s' % cron.render())
response = 'ok, cronjob added %s' % str(job)
if self.req_from == 'jabber':
todo = {'text': response, 'jmsg': response, 'type': 'response'}
self.response = todo
if self.req_from == 'julius':
from core.broadcast import say, bang
bang()
response = 'ok'
todo = {'say': response, 'text': response, 'type': 'response'}
self.response = say(self.request.replace('say', '').upper())
return self.response
示例11: run
def run(self):
"""default method"""
sender = self.req_obj.get('sender', '')
email = sender.split('/')[0]
sess = Session()
profile = None
try:
profile = sess.query(Profile).filter(Profile.email == email).one()
except Exception, e:
logger.exception(e)
示例12: run
def run(self):
"""default method"""
"""default method that will be executed by /core/brain/main.py and receives request string"""
response = 'You are not allowed to send broadcast messages.'
email = None
sender = self.req_obj.get('sender', '')
if sender:
email = sender.split('/')[0]
sess = Session()
#exctract uuid
uuid = self.req_obj.pop('uuid', '')
if email:
#find user profile by primary email
profile = sess.query(Profile).filter(Profile.email == email).one()
elif uuid:
#find user profile by uuid
profile = sess.query(Profile).filter(Profile.uuid == uuid).one()
else:
response = 'Can not authenticate your id, are you registered ?'
return { 'text' : response, 'jmsg' : response, 'type': 'response' }
if profile.type != 'admin':
return { 'text' : response, 'jmsg' : response, 'type': 'response' }
logger.info('Start video broadcasting...')
proc = subprocess.Popen(
["motion"]
#,shell=False
#,stdin=subprocess.PIPE
#,stdout=subprocess.PIPE
#,stderr=subprocess.PIPE
)
#output, err = proc.communicate()
#logger.info("%s ", output)
#logger.info("%s", err)
response = 'Camera on.'
if self.req_from == 'jabber':
todo = { 'text' : response, 'jmsg' : response, 'type': 'response' }
self.response = todo
if self.req_from == 'julius':
bang()
todo = { 'say': response , 'text' : response ,'type': 'response' }
self.response = say(self.request.replace('say', '').upper())
return self.response
示例13: search_users_request
def search_users_request(request, uuid):
logger.info('Search for a request')
prefix = 'client-request-'
response = ''
#need cache results for an hour because a lot of users
#can have the same request
#hour = datetime.now().hour
minute = datetime.now().minute
key = prefix + datetime.now().strftime("%Y-%m-%d-") + str(minute)
old = prefix + datetime.now().strftime("%Y-%m-%d-") + str(minute - 1)
#use unix socket
r = redis.Redis(password=REDIS['password'],
unix_socket_path=REDIS['socket'])
existing = r.get(key)
sess = Session()
#find user profile by uuid
profile = sess.query(
Profile).filter(Profile.uuid == uuid).one()
#read for all for now
allowed_to_read_all = True
#here I need to know request to be public or not
if profile.type == 'admin':
allowed_to_read_all = True
if existing:
return existing
else:
if allowed_to_read_all:
requests = sess.query(ProfileRequest).filter(
ProfileRequest.request.like('%' + request + '%')).all()
else:
requests = sess.query(ProfileRequest).filter(
and_(
ProfileRequest.uuid == uuid,
ProfileRequest.request.like('%' + request + '%')
)
).all()
response = [req.request for req in requests]
response = "\n".join(response)
if r.set(key, response):
r.delete(old)
return response
示例14: run
def run(self):
"""default method"""
sender = self.req_obj.get('sender', '')
uuid = self.req_obj.get('uuid', '')
#######################################################################
# #
# get user profile #
# #
#######################################################################
sess = Session()
#exctract sender email
if sender:
email = sender.split('/')[0]
if email:
#find user profile by primary email
self.profile = sess.query(Profile).filter(
Profile.email == email).one()
elif uuid:
#find user profile by uuid
self.profile = sess.query(
Profile).filter(Profile.uuid == uuid).one()
logger.info(self.profile.email)
#######################################################################
# #
# prepare response #
# #
#######################################################################
myrg = random.SystemRandom()
length = 10
# If you want non-English characters, remove the [0:52]
alphabet = string.letters[0:52] + string.digits
pw = str().join(myrg.choice(alphabet) for _ in range(length))
response = pw
if self.req_from == 'jabber':
todo = {'text': response, 'jmsg': response, 'type': 'response'}
self.response = todo
if self.req_from == 'julius':
bang()
todo = {'say': response, 'text': response, 'type': 'response'}
self.response = say(self.request.replace('say', '').upper())
return self.response
示例15: run
def run(self):
"""default method"""
sender = self.req_obj.get('sender', '')
uuid = self.req_obj.get('uuid', '')
#######################################################################
# #
# get user profile #
# #
#######################################################################
sess = Session()
#exctract sender email
if sender:
email = sender.split('/')[0]
if email:
#find user profile by primary email
self.profile = sess.query(Profile).filter(
Profile.email == email).one()
elif uuid:
#find user profile by uuid
self.profile = sess.query(
Profile).filter(Profile.uuid == uuid).one()
logger.info(self.profile.email)
#######################################################################
# #
# prepare response #
# #
#######################################################################
response = self.profile.home_postcode
if not self.profile.home_postcode:
request_to_user = "I don't have your zip" +\
", but you can add it later with command: my zip is ..."
else:
todo = {'text': response, 'jmsg': response, 'type': 'response'}
if self.req_from == 'jabber':
self.response = todo
if self.req_from == 'julius':
bang()
todo = {'say': response, 'text': response, 'type': 'response'}
self.response = say(self.request.replace('say', '').upper())
return self.response