Пример #1
0
    def has_already_run(self):
        """检查任务是否已经执行过

        @override
        首先获取当前应该判断那个月
        然后看看这个月是否已经执行过了
        """
        try:
            target_month, target_year = get_target_month_year()

            session = db.get_session()
            pushed_log_list = session.query(Push_log).\
                filter(Push_log.task_id == self.task_id).\
                filter(Push_log.push_plugin == self.get_task_plugin_name()).\
                filter(Push_log.push_user == self.user).\
                filter(func.month(Push_log.push_datetime) == target_month).\
                filter(func.year(Push_log.push_datetime) == target_year).\
                all()

            pushed_log_num = len(pushed_log_list)
            LOG.debug("[task_name: %s] [task_id: %d], pushed_log_list length is %d",
                      self.get_task_plugin_name(), self.task_id,
                      pushed_log_num)

            if pushed_log_num > 0:
                return True
            return False
        finally:
            session.close()
Пример #2
0
    def has_already_run(self):
        """检查任务是否已经执行过

        凡是推送完毕才叫执行完
        """
        try:
            date_str_to_check = self.date_str_of_checking_push_log()

            session = db.get_session()
            pushed_log_list = session.query(Push_log).filter(
                Push_log.task_id == self.task_id
            ).filter(Push_log.push_plugin == self.get_task_plugin_name(
            )).filter(Push_log.push_user == self.user).filter(
                cast(Push_log.push_datetime, DATE) == date_str_to_check).all()

            pushed_log_num = len(pushed_log_list)
            LOG.debug(
                "[task_name: %s] [task_id: %d], pushed_log_list length is %d",
                self.get_task_plugin_name(), self.task_id, pushed_log_num)

            if pushed_log_num > 0:
                return True
            return False
        finally:
            session.close()
Пример #3
0
    def post_push_warning_text(self):
        """推送天气告警之后要执行的函数

        主要分为保存天气日志和保存推送记录
        以后可以改成每查询一次API就记录一次
        不用等到推送时候再记录
        包括查询结果不符合推送条件的,也可以记录
        """
        # 保存天气日志
        info = weather_info.Weather_info()
        info.city_alias = self.city_alias
        info.city_id = self.city_id
        info.city_name = self.city_alias
        info.today_temperature_high = self.get_today_high()
        info.today_temperature_low = self.get_today_low()
        info.tomorrow_temperature_high = self.get_tomorrow_high()
        info.tomorrow_temperature_low = self.get_tomorrow_low()
        info.text_day = self.get_tomorrow_day_text()
        info.text_night = self.get_tomorrow_night_text()

        pushlog = push_log.Push_log()
        pushlog.push_method = self.task.push_method
        pushlog.push_user = self.task.user
        pushlog.push_plugin = "weather"
        pushlog.plugin_push_reason = "bad weather"
        pushlog.task_id = self.task.task_id

        session = db.get_session()
        try:
            session.add(info)
            session.add(pushlog)
            session.commit()
        finally:
            session.close()
Пример #4
0
    def get_all_tasks(cls):
        """获取所有任务

        通过classmethod的方法,获取各个task的cls
        以便数据库查询
        """
        try:
            session = db.get_session()
            task_list = session.query(cls).all()
            return task_list
        finally:
            session.close()
Пример #5
0
    def get_user_by_username(username=None):
        """根据用户名获取用户

        [description]

        Keyword Arguments:
            username {[type]} -- [description] (default: {None})

        Returns:
            [type] -- [description]
        """
        try:
            session = db.get_session()
            user = session.query(Users).filter(
                Users.username == username).one()
            return user
        finally:
            session.close()