Exemplo n.º 1
0
    def handle_init(self):
        print '[INFO] Handle init'

        # 获取聚爱网公众号ID,定时发送消息,保持接受公众号的消息推送
        if self.juai_id == '':
            self.juai_id = self.get_public_id(u'聚爱网')

        try:
            #保存在线机器人信息
            mysql.execute_sql(
                'insert into ot_robot (uid, name, avatar, status) values (%s,%s,%s,%s)',
                (self.my_account['UserName'], self.my_account['NickName'],
                 self.my_account['HeadImgUrl'], 1))

            #保存机器人的群列表
            sql = 'insert into ot_robot_group (uid, gid, name, avatar) values (%s,%s,%s,%s)'
            for group in self.group_list:
                name = ''
                if group['RemarkName'] != '':
                    name = group['RemarkName']
                elif group['NickName'] != '':
                    name = group['NickName']
                elif group['DisplayName'] != '':
                    name = group['DisplayName']
                mysql.execute_sql(
                    sql, (self.my_account['UserName'], group['UserName'],
                          self.to_unicode(name), group['HeadImgUrl']))

        except Exception as e:
            print '[ERROR] ' + e.message, traceback.format_exc()
Exemplo n.º 2
0
def main():
    try:
        sql = "delete from ot_robot"
        mysql.execute_sql(sql)
        sql = "delete from ot_robot_group"
        mysql.execute_sql(sql)

        print ("[INFO] Clear boot finished.")
    except Exception as e:
        print e.message, traceback.format_exc()
Exemplo n.º 3
0
    def handle_exit(self):
        print '[INFO] Handle exit'

        try:
            sql = "update ot_robot set status = 0 where uid = '%s'" % (
                self.my_account['UserName'])
            mysql.execute_sql(sql)

            sql = "delete from ot_robot_group where uid = '%s'" % (
                self.my_account['UserName'])
            mysql.execute_sql(sql)
        except Exception as e:
            print '[ERROR] ' + e.message, traceback.format_exc()
Exemplo n.º 4
0
def empi_init(table):
    with execute_sql() as cursor:
        try:
            cursor.execute("alter table %s drop PRIMARY KEY" % table)
        except pymysql.err.InternalError:
            pass
        cursor.execute("delete from zmap_r_patient_backup")
        cursor.execute("insert into zmap_r_patient_backup select * from %s" % table)
        cursor.execute("update %s set confidence=''" % table)
        cursor.execute("update %s set confirm_status=''" % table)
        cursor.execute("update %s set confirm_person=''" % table)
        cursor.execute("alter table %s drop column empi_id" % table)
        cursor.execute("alter table %s add empi_id bigint PRIMARY KEY  AUTO_INCREMENT" % table)
        cursor.execute("Alter table %s change empi_id empi_id  VARCHAR(200)" % table)
        cursor.execute("alter table %s drop PRIMARY KEY" % table)
        cursor.execute("update %s set empi_id=LPAD(empi_id,9,'0')" % table)
        cursor.execute("alter table %s add PRIMARY KEY (patient_id)" % table)
        try:
            cursor.execute("CREATE INDEX index_id_card ON %s (id_card)" % table)
        except pymysql.err.InternalError:
            pass
        try:
            cursor.execute("CREATE INDEX index_birthday ON %s (patient_name,birthday)" % table)
        except pymysql.err.InternalError:
            pass
        try:
            update_empi_id("CREATE INDEX index_empi_id ON %s (empi_id)" % table)
        except pymysql.err.InternalError:
            pass
Exemplo n.º 5
0
def data_set(sql):
    with execute_sql() as cursor:
        cursor.execute(sql)
        row = cursor.fetchone()
        while row:
            yield row
            row = cursor.fetchone()
Exemplo n.º 6
0
    def do_task(self):
        try:
            sql = "select id,task from ot_robot_task where uid = '%s' and status = 0 order by id limit 1" % self.my_account[
                'UserName']
            task = mysql.get_one(sql)
            if task is not None:
                # 下线
                if task[1] == 'OFFLINE':
                    self.status = 'wait4loginout'
                # 休眠
                elif task[1] == 'SLEEP':
                    self.sleep = 1
                # 唤醒
                elif task[1] == 'WEAKUP':
                    self.sleep = 0
                else:
                    # 通过ID转发消息
                    matchs = re.match(r'^TURN\|(@\S+)\|([\S \n\r\t]+)$',
                                      task[1], re.M)
                    if matchs:
                        content = matchs.group(2).replace('\\n', '\n').replace(
                            '[F]', u'🚺').replace('[M]', u'🚹')
                        self.send_msg_by_uid(content, matchs.group(1))
                    else:
                        # 通过昵称转发消息
                        matchs = re.match(r'^TURN\|([\S ]+)\|([\S \n\r\t]+)$',
                                          task[1], re.M)
                        if matchs:
                            content = matchs.group(2).replace(
                                '\\n',
                                '\n').replace('[F]',
                                              u'🚺').replace('[M]', u'🚹')
                            self.send_msg(matchs.group(1), content)
                        else:
                            #TODO:加用户进群
                            matchs = re.match(
                                r'^ADD_GROUP\|([\S ]+)\|([\S ]+)$', task[1])
                            if matchs:
                                pass

                sql = "update ot_robot_task set status = 1 where id = %s" % task[
                    0]
                mysql.execute_sql(sql)
        except Exception as e:
            print '[ERROR] ' + e.message, traceback.format_exc()
Exemplo n.º 7
0
def update():  # 暂时废弃的功能
    command = "vboxmanage list vms"
    return_tuple = operation.use_shell.shell(command)
    vm_regex = re.compile(r'"(.*?)"\s*\{(.*?)\}')

    # 将数据库中没有的虚拟机加入到数据库
    for match in vm_regex.finditer(return_tuple[0]):
        result = mysql.execute_sql("SELECT * FROM vm_user \
                          WHERE vm_uuid = '%s'" % (match.group(2)))
        if result == ():
            mysql.execute_sql("INSERT INTO vm_user \
                      (vm_name, vm_uuid, vm_type) \
                      VALUES ('%s', '%s', '%s')" % (match.group(1), match.group(2), "nouser"))

    # 删除数据库中已经失效的虚拟机
    vm_list = mysql.execute_sql("SELECT * FROM vm_user")
    for line in vm_list:
        match = re.search(line[0], return_tuple[0])
        if not match:
            mysql.execute_sql("DELETE FROM vm_user \
                              WHERE vm_uuid = '%s'" % (line[0]))
        else:
            vminfo_tuple = operation.use_shell.shell("vboxmanage showvminfo %s --machinereadable" % (line[0]))
            match = re.search(r'macaddress1="(.*?)"', vminfo_tuple[0])
            print match.group(1)
Exemplo n.º 8
0
def counter(sql):
    with execute_sql() as cursor_counter:
        cursor_counter.execute(sql)
        return cursor_counter.fetchall()[0][0]
Exemplo n.º 9
0
def update_empi_id(sql):
    with execute_sql() as cursor_update:
        cursor_update.execute(sql)
Exemplo n.º 10
0
#!/usr/bin/env python
# coding=utf-8

from mysql import execute_sql
from mysql import fetchall_sql as fcal


if __name__ == '__main__':
    sql = 'select * from m_tblog_travelrecord;'
    # execute_sql(sql)
    for r in fcal(sql):
        print r
    # baseid = 10000000
    baseid = 1
    for i in range(1000000):
        k = baseid + i
        # print("INSERT INTO m_tblog_travelrecord (`id`, `sPlace`) VALUES(%s, 'xxx');" % k)
        execute_sql("INSERT INTO m_tblog_travelrecord (`id`, `sPlace`) VALUES(%s, 'xxx');" % k)
    # try:
    #     execute_sql(sql)
    # except:
    #     print 'error'