Esempio n. 1
0
def test_get_threads():
    responses.add(
        responses.GET,
        re.compile('https://www.reddit.com/r/dogs/top.json'),
        json={
            'data': {
                'children': [
                    {
                        'data': {
                            'subreddit': 'dogs',
                            'title': 'Cute Dogs',
                            'ups': 999,
                            'permalink': '/r/cute_dogs',
                            'url': '/r/cutedogs'
                        }
                    }
                ]
            }
        },
        status=200
    )

    threads = get_threads('dogs')

    assert len(threads) == 1
Esempio n. 2
0
def send_subreddit(bot, chat_id, subreddits):
    canais_message = ', '.join([f'r/{subreddit}' for subreddit in subreddits])
    bot.send_message(
        chat_id=chat_id,
        text=f'Procurando o que está bombando em {canais_message}...')
    threads = rc.get_threads(subreddits)
    filtered_threads = rc.filter_by_votes(threads, min_votes=500)
    threads = rc.filter_by_votes(filtered_threads)
    for thread in threads:
        bot.send_message(chat_id=chat_id,
                         text=DEFAULT_MESSAGE.format(**thread))
    if len(threads) == 0:
        bot.send_message(
            chat_id=chat_id,
            text=f'Não encontrei nada bombando em {canais_message}')
Esempio n. 3
0
def nada_para_fazer(bot, update, args):
    chat_id = update.message.chat_id

    joined_args = str.join(';', args)  # If you pass separeted we join using ; separator

    subreddits = joined_args.split(';')

    if len(subreddits) == 0 or len(args) == 0:
        bot.send_message(chat_id=chat_id,
                         text='Digite o termo da procura, ex: /nadaparafazer dogs;python')
        return

    for subreddit in subreddits:
        bot.send_message(chat_id=chat_id,
                         text=f'Procurando o que está bombando em r/{subreddit}...')
        threads = rc.get_threads(subreddit)
        filtered_threads = rc.filter_by_votes(threads, min_votes=5000)
        threads = rc.filter_by_votes(filtered_threads)
        for thread in threads:
            bot.send_message(chat_id=chat_id,
                             text=DEFAULT_MESSAGE.format(**thread))
        if len(threads) == 0:
            bot.send_message(chat_id=chat_id,
                             text=f'Não encontrei nada bombando em r/{subreddit}')
Esempio n. 4
0
def test_get_threads(mock_request_dog):

    threads = get_threads(['dogs'])

    assert len(threads) == 1
Esempio n. 5
0
def main(subreddits, min_votes):
    for subreddit in subreddits.split(';'):
        threads = get_threads(subreddit)
        filtred_threads = filter_by_votes(threads, min_votes=min_votes)
        print_subreddits(filtred_threads)
Esempio n. 6
0
def main(subreddits, min_votes):
    subreddits = subreddits.split(';')
    threads = get_threads(subreddits)
    filtred_threads = filter_by_votes(threads, min_votes=min_votes)
    print_subreddits(filtred_threads)