コード例 #1
0
ファイル: init.py プロジェクト: xingkaixin/distributionfile
def init_repo_data():
    import arrow
    import uuid
    session = DBSession()
    for i in range(1, 10):
        f = FileRouteModule()
        f.id = int(i)
        f.src_path = '/Users/Kevin/workspace/distributionfile/data'
        f.src_name = i
        f.src_extension = 'txt'
        f.retry_times = 0
        f.retry_interval = 0
        f.create_dt = arrow.utcnow().to('local').naive
        f.update_dt = arrow.utcnow().to('local').naive
        f.valid_from = arrow.utcnow().to('local').naive
        f.valid_to = arrow.utcnow().to('local').replace(days=365).naive
        f.tar_path = 'tmp/'
        f.tar_name = '{file}_{YMD}'.format(file=i, YMD='{YMD}')
        f.transtype = 'SFTP'
        f.ftpname = '10.8.4.116'
        session.add(f)

    f = session.query(FileRouteModule).get(9)
    f.tar_name = '9_{YM}'

    session.commit()
    session.close()
コード例 #2
0
ファイル: admin.py プロジェクト: devdeen/telegram_admin
def update_ban_list():
    logging.debug('update ban list ing')
    session = DBSession()
    db_admin = session.query(User).filter_by(isban=True).all()
    global ban_list
    ban_list = [int(user.id) for user in db_admin]
    logging.debug(f"ban list {ban_list}")
    session.close()
コード例 #3
0
ファイル: admin.py プロジェクト: devdeen/telegram_admin
def update_admin_list():
    logging.debug('update admin list ing')
    session = DBSession()
    db_admin = session.query(User.id).filter_by(isadmin=True).all()
    global admin_list
    admin_list = ADMIN + [int(user.id) for user in db_admin]
    logging.debug(f"admin list {admin_list}")
    session.close()
コード例 #4
0
def forward_group(bot, update):
    session = DBSession()
    users = session.query(Group).all()
    for user in users:
        update.message.forward(user.id)
        sleep(SEND_SLEEP)
    bot.send_message(chat_id=update.message.chat_id, text=USER_FORWARD_STOP)
    session.close()
    return ConversationHandler.END
コード例 #5
0
 def wrapper(bot, update, *args, **kwargs):
     session = DBSession()
     user = session.query(User).filter(
         User.id == update.message.chat_id).first()
     session.close()
     if user is None:
         bot.send_message(
             chat_id=update.message.chat_id,
             text=NO_BIND_MSG)
         return
     return func(bot, update,  *args, **kwargs)
コード例 #6
0
ファイル: command.py プロジェクト: devdeen/telegram_admin
def start(bot, update):
    """
    send start info
    """
    bot.send_message(chat_id=update.message.chat_id, text=START_MSG)
    session = DBSession()
    user = session.query(User).filter_by(
        id=update.message.from_user['id']).first()
    if user is None:
        session.add(User(id=update.message.from_user['id']))
    session.commit()
    session.close()
コード例 #7
0
def send_user(bot, update):
    session = DBSession()
    users = session.query(User).all()
    if not (Filters.text(update.message) | Filters.sticker(update.message)
            | Filters.photo(update.message) | Filters.video(update.message)
            | Filters.document(update.message)):
        bot.send_message(chat_id=update.message.id, text=NO_SUPPORT_FORMAT)
        return
    send_admin_msg(users=users, bot=bot, update=update)
    bot.send_message(chat_id=update.message.chat_id, text=USER_FORWARD_STOP)
    session.close()
    return ConversationHandler.END
コード例 #8
0
def send_group(bot, update):
    """
    :param bot:
    :type bot: Bot
    :param update:
    :type update: Update
    :return
    """
    session = DBSession()
    groups = session.query(Group).all()
    send_admin_msg(users=groups, bot=bot, update=update)
    bot.send_message(chat_id=update.message.chat_id, text=USER_FORWARD_STOP)
    session.close()
    return ConversationHandler.END
コード例 #9
0
ファイル: command.py プロジェクト: devdeen/telegram_admin
def globalban_list(bot, update):
    """
    show globalban user list
    :param bot:
    :type bot: Bot
    :param update:
    :type update: Update
    :return:
    """
    session = DBSession()
    datas = session.query(User).filter_by(isban=True).all()
    ret_text = ""
    for data in datas:
        ret_text = ret_text + GLOBAL_BAN_FORMAT.format(user_id=data.id)
    session.close()
    if ret_text == "":
        bot.send_message(chat_id=update.message.chat_id, text=NO_INFO_MSG)
        return
    bot.send_message(chat_id=update.message.chat_id,
                     text=ret_text,
                     parse_mode=ParseMode.MARKDOWN)
コード例 #10
0
ファイル: command.py プロジェクト: devdeen/telegram_admin
def get_groups(bot, update):
    """
    :param bot:
    :type bot: Bot
    :param update:
    :type update: Update
    :return:
    """
    session = DBSession()
    groups = session.query(Group).all()
    if groups is None:
        bot.send_message(chat_id=update.message.chat_id, text=NO_INFO_MSG)
        session.close()
        return
    ret_text = ""
    for group in groups:
        ret_text = ret_text + GROUP_FORMAT.format(
            group_title=group.title, group_id=group.id, group_link=group.link)
    bot.send_message(chat_id=update.message.chat_id,
                     text=ret_text,
                     parse_mode=ParseMode.MARKDOWN)
    session.close()
コード例 #11
0
    def _blocked(self):
        self._p, self._f = os.path.split(self._filepath)
        self._f, self._ext = os.path.splitext(self._f)
        self._ext = self._ext.lower().replace('.', '')

        session = DBSession()

        logger.debug('Path:{path} File:{file}.{ext}'.format(
            path=self._p, file=self._f, ext=self._ext))

        tempate_f = getKeyName(self._f)

        if tempate_f:
            try:
                f = session.query(FileRouteModule).filter(FileRouteModule.src_path == self._p,
                                                          FileRouteModule.src_name == tempate_f).first()
                logger.debug(f)
                if f is None:
                    self.blocked = True
                    _f = session.query(FileRouteModule).filter(FileRouteModule.src_path == self._p,
                                                               FileRouteModule.src_name == '*', FileRouteModule.src_extension == self._ext).first()
                    if _f:
                        self.transtype = _f.transtype
                        self.ftpname = _f.ftpname
                        self.tar_path = _f.tar_path
                        self.tar_name = '{filenme}.{ext}'.format(
                            filename=self._f, ext=self._ext)
                        self.blocked = False
                elif f and f.src_extension.lower() != self._ext:
                    self.blocked = True
                else:
                    self.blocked = False

                    utcdt = arrow.utcnow().to('local')

                    # 目标目录生成
                    try:
                        tar_folder_dt_format_list = f.tar_folder_dt_format.split(
                            ',')
                        tar_folder_dt_format = tar_folder_dt_format_list[0]
                        tar_folder_dt_diff = int(tar_folder_dt_format_list[1])
                    except ValueError:
                        tar_folder_dt_diff = 0
                    except IndexError:
                        tar_folder_dt_diff = 0

                    if tar_folder_dt_format:
                        folder_timestamp = f.tar_path.format(DT=utcdt.replace(
                            days=tar_folder_dt_diff).format(tar_folder_dt_format))
                    else:
                        folder_timestamp = f.tar_path

                    self.tar_path = folder_timestamp

                    logger.debug(f.tar_name)
                    logger.debug(f.tar_dt_format)

                    # 目标文件名生成
                    try:
                        tar_dt_format_list = f.tar_dt_format.split(',')
                        tar_dt_format = tar_dt_format_list[0]
                        tar_dt_diff = int(tar_dt_format_list[1])
                    except ValueError:
                        tar_dt_diff = 0
                    except IndexError:
                        tar_dt_diff = 0
                    file_timestamp = f.tar_name.format(
                        DT=utcdt.replace(days=tar_dt_diff).format(tar_dt_format))
                    try:
                        file_timestamp = file_timestamp.decode('gbk')
                    except UnicodeDecodeError:
                        file_timestamp = unicode(file_timestamp).decode('gbk')
                    logger.debug(file_timestamp)
                    self.tar_name = '{filename}.{ext}'.format(
                        filename=file_timestamp, ext=f.src_extension)

                    self.transtype = f.transtype
                    self.ftpname = f.ftpname
            except:
                session.close()
                raise
            else:
                session.close()
        else:
            self.blocked = True
            logger.debug(
                'thi file name [{filename}] can re'.format(filename=self._f))