예제 #1
0
class User(db.Model, BaseMethod):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    email = db.Column(db.String(250), nullable=True, unique=True)
    password_hash = db.Column(db.String(128), nullable=False)
    name = db.Column(db.String(250), nullable=True)
    username = db.Column(db.String(32), index=True, nullable=False)
    active = db.Column(db.Integer, nullable=True, default=0)
    avatar = db.Column(db.String(128), nullable=True)
    handle_id = db.Column(db.Integer, nullable=True)
    admin = db.Column(db.Boolean, nullable=True)
    creation_time = db.Column(db.TIMESTAMP,
                              server_default=db.func.current_timestamp(),
                              nullable=False)
    last_login = db.Column(db.TIMESTAMP,
                           server_default=db.func.current_timestamp(),
                           nullable=False)

    def get_hash(self, pwd):
        return pwd_context.encrypt(pwd)

    def to_dict(self):
        rst = {}
        rst['id'] = self.id
        rst['name'] = self.name
        rst['avatar'] = self.avatar
        rst['active'] = self.active
        rst['last_login'] = self.last_login
        rst['email'] = self.email
        rst['username'] = self.username
        rst['handle_id'] = self.handle_id
        rst['admin'] = self.admin
        return rst
예제 #2
0
class Server(db.Model, BaseMethod):
    '''server list'''
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32))
    ip = db.Column(db.String(16))
    port = db.Column(db.Integer)
    account = db.Column(db.String(32))
    pkey = db.Column(db.Text)

    user_id = db.Column(db.String(32), db.ForeignKey(User.id))
    user = db.relationship(User)

    add_time = db.Column(db.DateTime, default=datetime.datetime.now)

    deleted = db.Column(db.Boolean, default=False)

    def dict(self, with_pkey=False):
        rst = {}
        rst['id'] = self.id
        rst['name'] = self.name
        rst['ip'] = self.ip
        rst['port'] = self.port
        rst['account'] = self.account
        rst['pkey'] = with_pkey and self.pkey or ''
        rst['user_id'] = self.user_id
        rst['add_time'] = self.add_time
        return rst
예제 #3
0
class History(db.Model, BaseMethod):
    '''push history'''
    # md5, notice, output, push_name, push_email, success, add_time
    id = db.Column(db.Integer, primary_key=True)
    status = db.Column(
        db.String(1))  # 1:waiting, 2:ing, 3:error, 4:success, 5:except, other
    shell_log = db.Column(db.Text)  # hook shell log

    data = db.Column(db.Text)  # git push data
    push_user = db.Column(db.String(64))  # git push user(name<email>)
    add_time = db.Column(db.DateTime,
                         default=datetime.datetime.now)  # git push time

    webhook_id = db.Column(db.Integer, db.ForeignKey(WebHook.id))
    webhook = db.relationship(WebHook)

    def dict(self):
        rst = {}
        rst['id'] = self.id
        rst['status'] = self.status
        rst['shell_log'] = self.shell_log
        rst['data'] = self.data  # json
        rst['push_user'] = self.push_user
        rst['add_time'] = self.add_time

        rst['webhook_id'] = self.webhook_id
        return rst

    def updateStatus(self, status):
        self.status = status
        self.save()
예제 #4
0
파일: model.py 프로젝트: hustcc/TODO
class User(db.Model, BaseMethod):
    '''用户表'''
    id = db.Column(db.String(64), primary_key=True)
    uid = db.Column(db.String(32))
    name = db.Column(db.String(32))
    source = db.Column(db.String(8))  # github / qq

    last_login = db.Column(db.DateTime)
예제 #5
0
파일: model.py 프로젝트: zz38/git-webhook
class WebHook(db.Model, BaseMethod):
    '''webhook'''
    id = db.Column(db.Integer, primary_key=True)
    repo = db.Column(db.String(32))  # repo name
    branch = db.Column(db.String(32))  # repo branch
    shell = db.Column(db.Text)  # do what

    user_id = db.Column(db.String(32), db.ForeignKey(User.id))
    user = db.relationship(User)

    server_id = db.Column(db.Integer, db.ForeignKey(Server.id))
    server = db.relationship(Server)

    add_time = db.Column(db.DateTime, default=datetime.datetime.now)

    deleted = db.Column(db.Boolean, default=False)

    key = db.Column(db.String(32), unique=True)  # 用于webhook,保证私密,直接用 md5 salt

    # 1:waiting, 2:ing, 3:error, 4:success, 5:except, other
    status = db.Column(db.String(1))
    lastUpdate = db.Column(db.DateTime,
                           default=datetime.datetime.now)  # 最新执行时间

    def dict(self, with_key=False):
        rst = {}
        rst['id'] = self.id
        rst['repo'] = self.repo
        rst['branch'] = self.branch
        rst['shell'] = self.shell
        rst['user_id'] = self.user_id
        rst['server_id'] = self.server_id
        rst['server'] = self.server and self.server.dict() or {}
        rst['add_time'] = self.add_time
        rst['key'] = with_key and self.key or ''
        rst['status'] = self.status
        rst['lastUpdate'] = self.lastUpdate
        return rst

    def updateStatus(self, status):
        self.status = status
        self.lastUpdate = datetime.datetime.now()
        self.save()
        socketio.emit('webhook',
                      JsonUtil.object_2_json(self.dict()),
                      room=self.id)
예제 #6
0
파일: model.py 프로젝트: hustcc/TODO
class Todo(db.Model, BaseMethod):
    '''用户表'''
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(1024))
    add_time = db.Column(db.DateTime)
    completed = db.Column(db.Boolean)

    user_id = db.Column(db.String(64), db.ForeignKey('user.id'))

    def dict(self):
        rst = {}
        rst['id'] = self.id
        rst['title'] = self.title
        rst['add_time'] = self.add_time
        rst['completed'] = self.completed
        rst['user_id'] = self.user_id
        return rst
예제 #7
0
class RedisInfo(db.Model, BaseMethod):
    '''RedisInfo'''
    md5 = db.Column(db.String(32), primary_key=True)
    host = db.Column(db.String(32))
    port = db.Column(db.Integer, default=6379)
    password = db.Column(db.String(32))

    add_time = db.Column(db.DateTime, default=datetime.datetime.now)

    def dict(self):
        rst = {}
        rst['md5'] = self.md5
        rst['host'] = self.host
        rst['port'] = self.port
        rst['password'] = self.password
        rst['add_time'] = self.add_time
        return rst
예제 #8
0
class User(db.Model, BaseMethod):
    '''user'''
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(32), nullable=True)
    location = db.Column(db.String(32), nullable=True)
    avatar = db.Column(db.String(128), nullable=True)
    username = db.Column(db.String(32), index=True)
    password_hash = db.Column(db.String(128))
    email = db.Column(db.String(128), nullable=True)
    src = db.Column(db.String(4), default="gh", nullable=True)  # useless
    last_login = db.Column(db.DateTime, default=datetime.datetime.now)

    def dict(self):
        rst = {}
        rst['id'] = self.id
        rst['name'] = self.name
        rst['location'] = self.location
        rst['avatar'] = self.avatar
        rst['src'] = self.src
        rst['last_login'] = self.last_login
        rst['email'] = self.email
        rst['username'] = self.username
        return rst

    def hash_password(self, password):
        self.password_hash = pwd_context.encrypt(password)

    def verify_password(self, password):
        return pwd_context.verify(password, self.password_hash)
예제 #9
0
class User(db.Model, BaseMethod):
    '''user'''
    id = db.Column(db.String(32), primary_key=True)
    name = db.Column(db.String(32))
    location = db.Column(db.String(32))
    avatar = db.Column(db.String(128))

    src = db.Column(db.String(4), default="gh")
    last_login = db.Column(db.DateTime, default=datetime.datetime.now)

    def dict(self):
        rst = {}
        rst['id'] = self.id
        rst['name'] = self.name
        rst['location'] = self.location
        rst['avatar'] = self.avatar
        rst['src'] = self.src
        rst['last_login'] = self.last_login
        return rst
예제 #10
0
class Collaborator(db.Model, BaseMethod):
    '''Collaborator'''
    id = db.Column(db.Integer, primary_key=True)
    # webhook
    webhook_id = db.Column(db.Integer, db.ForeignKey(WebHook.id))
    webhook = db.relationship(WebHook)
    # user
    user_id = db.Column(db.String(32), db.ForeignKey(User.id))
    user = db.relationship(User)

    add_time = db.Column(db.DateTime, default=datetime.datetime.now)

    def dict(self):
        rst = {}
        rst['id'] = self.id
        rst['webhook_id'] = self.webhook_id
        rst['user_id'] = self.user_id
        rst['user'] = {}
        if self.user:
            rst['user'] = self.user.dict()
        rst['add_time'] = self.add_time
        return rst
예제 #11
0
class FlightInfo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.String(80))
    start_location = db.Column(db.String(120))
    end_location = db.Column(db.String(120))
    start_date = db.Column(db.String(120))
    return_date = db.Column(db.String(120))
    flight_type = db.Column(db.INTEGER)
    status = db.Column(db.INTEGER)
    complete = db.Column(db.Boolean)
    update_time = db.Column(db.DATETIME, default=datetime.datetime.utcnow())
    nlp = const.NLP

    def __init__(self,uid,start_location=None,end_location=None,flight_type=None,status=0):
        # 状态:0 :初始状态内容为空 1:缺少起始城市 2:缺少到达城市 3 缺少类型(往返或者单程)
        # 4:缺少出发时间 5缺少返回时间 6:完成
        self.uid = uid
        self.start_location = start_location
        self.end_location = end_location
        self.start_date = None
        self.return_date = None
        #航班类型1:单程 2:往返
        self.flight_type = flight_type
        self.status = status
        self.complete = False

    def save(self):
        db.session.add(self)
        db.session.commit()

    def get_qstr(self):
        q = QuestionStr()
        if self.status == 4:
            return ( u"您从" + self.start_location + u"到" + self.end_location +u"的行程" + q.get_question_str(self.status))
        if self.status == 5:
            return (u"您从" + self.end_location + u"返回" + self.start_location + u"的行程"+ q.get_question_str(self.status))
        if self.status == 6:
            return q.get_question_str(self.status) + self.start_location + u'到' + self.end_location + u'的机票'
        else:
            return q.get_question_str(self.status)

    def analyse(self,text):
        text = DateTransfer.date_transfer(text)
        self.__get_flight_info(text)
        self.__change_status()
        self.save()

    def get_dict(self):
        rst={}
        rst['origin'] = CitySearch.get_city_code(self.start_location)
        rst['destination'] = CitySearch.get_city_code(self.end_location)
        rst['departure_date'] = self.start_date
        if self.return_date is None:
            return rst
        else:
            rst['return_date']=self.return_date

    def __get_flight_type(self,text):
        result = self.nlp.tag(text)[0]['word']
        for d in result:
            if d == u"单程":
                self.flight_type = 1
                break
            if d == u"往返":
                self.flight_type = 2
                break

    def __get_flight_info(self, text):
        times = []
        locations = []
        result = self.nlp.ner(text)[0]
        words = result['word']
        entities = result['entity']
        for entity in entities:
            if entity[2] == "time":
                times.append(words[entity[0]:entity[1]])
            if entity[2] == "location":
                locations.append(words[entity[0]:entity[1]])
        self.__get_flight_type(text)
        if len(times) == 2:
            self.start_date = self.__date_trans(times[0])
            self.return_date = self.__date_trans(times[1])
        if self.return_date is None and self.start_date is not None and len(times) == 1:
            self.return_date = self.__date_trans(times[0])
        if self.start_date is None and len(times) == 1:
            self.start_date = self.__date_trans(times[0])
        if len(locations) == 2:
            self.start_location = "%s" % locations[0][0]
            self.end_location = "%s" % locations[1][0]
            return
        if len(locations) == 1 and self.start_location is None:
            self.start_location = "%s" % locations[0][0]
            return
        if len(locations) == 1 and self.start_location is not None:
            self.end_location = "%s" % locations[0][0]
            return

    def __date_trans(self,date):
        ret = u""
        for d in date:
            ret += d
        return ret

    def __change_status(self):
        if self.start_location is None:
            self.status = 1
            return
        if self.end_location is None:
            self.status = 2
            return
        if self.flight_type is None:
            self.status = 3
            return
        if self.start_date is None:
            self.status = 4
            return
        if self.flight_type == 2 and self.return_date is None:
            self.status = 5
            return
        self.status = 6
        return

    def change_complete(self):
        self.complete = True
        self.save()