Beispiel #1
0
def next_channels(update, context):
    query = update.callback_query
    if context.user_data['current_channel_page'] == math.ceil(
            len(Channel.get_all()) / 25):
        query.answer('صفحه بعد وجود ندارد')
    else:
        query.answer()
        context.user_data['current_channel_page'] += 1
        cp = context.user_data['current_channel_page']
        channels = Channel.get_all()[(cp - 1) * 25:cp * 25]
        return show(update, context, channels)
Beispiel #2
0
def add_channel(update, context):
    temp = update.message.reply_text('لطفا صبر کنید...')
    try:
        channel_sent_list = update.effective_message.text.split('\n')
    except ValueError:
        update.message.reply_text('ورودی اشتباه')
        return ADD_CHANNELS

    channel_store_list = []
    for channel in Channel.get_all():
        channel_store_list.append(channel.username)
    for username in channel_sent_list:
        if username.__contains__('t.me') or username.__contains__(
                'telegram.me'):
            try:
                username = '******' + \
                    re.search(r'\/\w{5,}', username).group(0).replace('/', '')
            except Exception:
                continue
        if username not in channel_store_list:
            channel_name = get_channel_name(username)
            if channel_name:
                Channel(username=username, name=channel_name.get_text()).add()
            else:
                update.message.reply_text(
                    'کانال {} وجود ندارد'.format(username))
    update.message.bot.edit_message_text(
        chat_id=update.message.chat_id,
        message_id=temp.message_id,
        text='اکنون /done را برای ذخیره سازی کانال ها ارسال کنید')
    return ADD_CHANNELS
Beispiel #3
0
def prev_channels(update, context):
    query = update.callback_query
    if context.user_data['current_channel_page'] == 1:
        query.answer('صفحه قبل وجود ندارد')
    else:
        query.answer()
        context.user_data['current_channel_page'] -= 1
        cp = context.user_data['current_channel_page']
        channels = Channel.get_all()[(cp - 1) * 25:cp * 25]
        return show(update, context, channels)
Beispiel #4
0
def show(update, context, channels):
    current_page = context.user_data['current_channel_page']
    pages = math.ceil(len(Channel.get_all()) / 25)
    show_channels = ""
    i = 1
    for channel in channels:
        show_channels += "{0}. {1} \n".format(i, channel.username)
        context.user_data['channels_dict'].update({i: channel})
        i += 1
    text = "تعداد کانال ها: {0} | "\
        "صفحه {1} از {2}\n"\
        "کانال های موجود: \n".format(
            len(Channel.get_all()), current_page, pages) + show_channels

    reply_markup = context.user_data['channel_reply_markup']
    if not update.message:
        update = update.callback_query
        update.edit_message_text(text, reply_markup=reply_markup)
    else:
        update.message.reply_text(text, reply_markup=reply_markup)
    return CHANNELS
Beispiel #5
0
def channels(update, context):
    context.user_data['channels_dict'] = {}
    context.user_data['remove_channels'] = []

    if Admin.get_by_username(update.message.from_user.username).is_super:
        keyboard = super_keyboard
    else:
        keyboard = normal_keyboard

    context.user_data['channel_reply_markup'] = InlineKeyboardMarkup(keyboard)
    cp = context.user_data['current_channel_page'] = 1
    channels = Channel.get_all()[(cp - 1) * 25:cp * 25]
    return show(update, context, channels)
Beispiel #6
0
def start_process(update, context):
    context.user_data['me'] = Admin.get_by_username(
        update.message.from_user.username)
    context.user_data['query'] = update.effective_message.text
    if Channel.get_all() == []:
        update.message.reply_text(
            'شما ابتدا باید برای جستجو کانالی تعیین کنید')
        return SELECTING_ACTION

    keyboard = [[
        InlineKeyboardButton("امروز", callback_data='1'),
        InlineKeyboardButton("یک هفته اخیر", callback_data='2')
    ], [InlineKeyboardButton("یک ماه اخیر", callback_data='3')],
                [InlineKeyboardButton("سه ماه اخیر", callback_data='4')],
                [InlineKeyboardButton("بازگشت به خانه", callback_data='0')]]

    reply_markup = InlineKeyboardMarkup(keyboard)

    update.message.reply_text('بازه‌ی جستجو را مشخص کنید',
                              reply_markup=reply_markup)

    return SET_DATE
Beispiel #7
0
                Post(caption=get_caption(soup),
                     raw_caption=caption_normalization(get_caption(soup)),
                     channel_name=channel.name,
                     views=float_to_int(get_views(soup)),
                     url=root_url + str(i),
                     date=get_date(soup),
                     format=get_format(soup),
                     duration=get_duration(soup)).add()
                print('added')

                # skip album posts
                if is_grouped(soup):
                    lai = get_album_last_index(soup)
                    print(lai)
                    i -= i - lai
                    print(i)
                    index += i - lai
                    if rep == lai:
                        i -= 1
                    rep = lai
            i -= 1
            time.sleep(0.3)

    s1.enter(6000, 1, crawl_channels, (channels, ))
    print(datetime.datetime.now().time(), ' Everything is up to date.')


s1.enter(0, 1, crawl_channels, (Channel.get_all(), ))

s1.run()