Пример #1
0
def test_remove_all_reminders(database, reddit):
    utils.debug_time = utils.parse_datetime_string("2019-01-01 12:00:00")
    message = reddit_test.RedditObject(body=f"RemoveAll!", author="Watchful1")
    messages.process_message(message, reddit, database)
    assert "Deleted" not in message.get_first_child().body

    reminder1 = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user=database.get_or_add_user("Watchful1"),
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-04 05:00:00"))
    reminder2 = Reminder(
        source="https://www.reddit.com/message/messages/YYYYY",
        message="FFFFF",
        user=database.get_or_add_user("Watchful1"),
        requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-02-05 07:00:00"))
    reminder3 = Reminder(
        source="https://www.reddit.com/message/messages/ZZZZZ",
        message="JJJJJ",
        user=database.get_or_add_user("Watchful2"),
        requested_date=utils.parse_datetime_string("2019-03-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-03-05 07:00:00"))
    database.add_reminder(reminder1)
    database.add_reminder(reminder2)
    database.add_reminder(reminder3)

    message = reddit_test.RedditObject(body=f"RemoveAll!", author="Watchful1")
    messages.process_message(message, reddit, database)
    body = message.get_first_child().body
    assert "Deleted **2** reminders." in body

    assert len(database.get_all_user_reminders("Watchful1")) == 0
    assert len(database.get_all_user_reminders("Watchful2")) == 1
Пример #2
0
def process_cakeday_message(message, reddit, database):
    log.info("Processing cakeday")

    if database.user_has_cakeday_reminder(message.author.name):
        log.info("Cakeday already exists")
        return ["It looks like you already have a cakeday reminder set."
                ], False

    next_anniversary = utils.get_next_anniversary(message.author.created_utc)

    reminder = Reminder(source=utils.message_link(message.id),
                        message=static.CAKEDAY_MESSAGE,
                        user=database.get_or_add_user(message.author.name),
                        requested_date=utils.datetime_from_timestamp(
                            message.created_utc),
                        target_date=next_anniversary,
                        recurrence="1 year",
                        defaulted=False)

    database.add_reminder(reminder)
    database.commit()

    log.info(
        f"Cakeday reminder created: {reminder.id} : {utils.get_datetime_string(reminder.target_date)}"
    )

    bldr = reminder.render_message_confirmation(
        None, pushshift_minutes=reddit.get_effective_pushshift_lag())
    return [''.join(bldr)], True
Пример #3
0
def parse_comment(comment, database, count_string):
    if comment['author'] == static.ACCOUNT_NAME:
        log.debug("Comment is from remindmebot")
        return None

    log.info(
        f"{count_string}: Processing comment {comment['id']} from u/{comment['author']}"
    )
    body = comment['body'].lower()
    if f"{static.TRIGGER_LOWER}!" not in body and f"!{static.TRIGGER_LOWER}" not in body:
        log.debug("Command not in comment")
        return None

    time = utils.find_reminder_time(comment['body'])

    message_text = utils.find_reminder_message(comment['body'])

    reminder = Reminder(
        source=utils.reddit_link(comment['permalink']),
        message=message_text,
        user=comment['author'],
        requested_date=utils.datetime_from_timestamp(comment['created_utc']),
        time_string=time,
        timezone=database.get_settings(comment['author']).timezone)
    if not reminder.valid:
        return None

    if not database.save_reminder(reminder):
        reminder.result_message = "Something went wrong saving the reminder"
        reminder.valid = False
        log.warning(reminder.result_message)

    return reminder
Пример #4
0
def process_remind_me(message, database):
    log.info("Processing RemindMe message")
    time = utils.find_reminder_time(message.body)

    message_text = utils.find_reminder_message(message.body)

    reminder = Reminder(
        source=utils.message_link(message.id),
        message=message_text,
        user=message.author.name,
        requested_date=utils.datetime_from_timestamp(message.created_utc),
        time_string=time,
        timezone=database.get_settings(message.author.name).timezone)
    if not reminder.valid:
        log.debug("Reminder not valid, returning")
        return [reminder.result_message]

    if not database.save_reminder(reminder):
        log.info("Something went wrong saving the reminder")
        return ["Something went wrong saving the reminder"]

    log.info(
        f"Reminder created: {reminder.db_id} : {utils.get_datetime_string(reminder.target_date)}"
    )

    return reminder.render_message_confirmation()
Пример #5
0
def test_get_reminders(database, reddit):
    utils.debug_time = utils.parse_datetime_string("2019-01-01 12:00:00")
    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body
    assert "You don't have any reminders." in result

    reminders = [
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message="KKKKK",
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-04 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/YYYYY",
            message="FFFFF",
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
            target_date=utils.parse_datetime_string("2019-02-05 07:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/ZZZZZ",
            message="GGGGG",
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
            target_date=utils.parse_datetime_string("2019-02-05 07:00:00"),
            recurrence="one day")
    ]
    for reminder in reminders:
        database.add_reminder(reminder)

    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body

    assert "Click here to delete all your reminders" in result
    assert "|Source|Message|Date|In|Repeat|Remove|" in result
    assert "|Source|Message|Date|In|Remove|" in result

    assert reminders[0].source in result
    assert reminders[0].message in result
    assert "01-04 05" in result

    assert reminders[1].source in result
    assert reminders[1].message in result
    assert "02-05 07" in result

    assert reminders[2].recurrence in result

    user = database.get_or_add_user(user_name="Watchful1")
    user.timezone = "America/Los_Angeles"
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "Your timezone is currently set to: `America/Los_Angeles`" in result
    assert "01-03 21" in result
    assert "02-04 23" in result
Пример #6
0
def test_send_reminders(database, reddit):
	reminders = [
		Reminder(
			source="https://www.reddit.com/message/messages/XXXXX",
			message="KKKKK",
			user="******",
			requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
			target_date=utils.parse_datetime_string("2019-01-05 05:00:00")
		),
		Reminder(
			source="https://www.reddit.com/message/messages/XXXXX",
			message="KKKKK",
			user="******",
			requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
			target_date=utils.parse_datetime_string("2019-01-06 05:00:00")
		),
		Reminder(
			source="https://www.reddit.com/message/messages/XXXXX",
			message="KKKKK",
			user="******",
			requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
			target_date=utils.parse_datetime_string("2019-01-07 05:00:00")
		),
		Reminder(
			source="https://www.reddit.com/message/messages/XXXXX",
			message="KKKKK",
			user="******",
			requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
			target_date=utils.parse_datetime_string("2019-01-08 05:00:00")
		),
		Reminder(
			source="https://www.reddit.com/message/messages/XXXXX",
			message="KKKKK",
			user="******",
			requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
			target_date=utils.parse_datetime_string("2019-01-09 05:00:00")
		)
	]
	for reminder in reminders:
		database.save_reminder(reminder)

	utils.debug_time = utils.parse_datetime_string("2019-01-05 12:00:00")
	notifications.send_reminders(reddit, database)

	assert len(database.get_user_reminders("Watchful1")) == 4

	utils.debug_time = utils.parse_datetime_string("2019-01-08 12:00:00")
	notifications.send_reminders(reddit, database)

	assert len(database.get_user_reminders("Watchful1")) == 1
Пример #7
0
def test_get_reminders(database, reddit):
    utils.debug_time = utils.parse_datetime_string("2019-01-01 12:00:00")
    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body
    assert "You don't have any reminders." in result

    reminder1 = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user="******",
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-04 05:00:00"))
    reminder2 = Reminder(
        source="https://www.reddit.com/message/messages/YYYYY",
        message="FFFFF",
        user="******",
        requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-02-05 07:00:00"))
    database.save_reminder(reminder1)
    database.save_reminder(reminder2)
    cakeday = Cakeday(
        user="******",
        date_time=utils.parse_datetime_string("2019-05-05 15:25:17"))
    database.add_cakeday(cakeday)

    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body

    assert "Click here to delete all your reminders" in result

    assert "Happy cakeday!" in result

    assert reminder1.source in result
    assert reminder1.message in result
    assert "01-04 05" in result

    assert reminder2.source in result
    assert reminder2.message in result
    assert "02-05 07" in result

    database.save_settings(
        UserSettings(user="******", timezone="America/Los_Angeles"))
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "Your timezone is currently set to: `America/Los_Angeles`" in result
    assert "01-03 21" in result
    assert "02-04 23" in result
Пример #8
0
def test_get_long_reminders(database, reddit):
    utils.debug_time = utils.parse_datetime_string("2019-01-01 12:00:00")
    user = database.get_or_add_user("Watchful1")
    requested_date = utils.parse_datetime_string("2019-01-01 04:00:00")
    target_date = utils.parse_datetime_string("2019-01-01 04:00:00")
    for i in range(60):
        database.add_reminder(
            Reminder(source=f"https://www.reddit.com/message/messages/XXX{i}",
                     message=f"{i}" * 50,
                     user=user,
                     requested_date=requested_date,
                     target_date=target_date + timedelta(days=1)))

    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)
    assert len(message.children) == 3
    assert "Click here to delete all your reminders" in message.children[
        0].body
    assert "Click here to delete all your reminders" not in message.children[
        1].body
    assert "Click here to delete all your reminders" not in message.children[
        2].body
    assert "|Source|Message|Date|In|Remove|" in message.children[0].body
    assert "|Source|Message|Date|In|Remove|" in message.children[1].body
    assert "|Source|Message|Date|In|Remove|" in message.children[2].body
    assert "[^(Info)]" not in message.children[0].body
    assert "[^(Info)]" not in message.children[1].body
    assert "[^(Info)]" in message.children[2].body
Пример #9
0
def test_send_recurring_reminder_limit(database, reddit):
    old_limit = static.RECURRING_LIMIT
    static.RECURRING_LIMIT = 3
    reminder = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user=database.get_or_add_user("Watchful1"),
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-05 05:00:00"),
        recurrence="one day")
    database.add_reminder(reminder)

    utils.debug_time = utils.parse_datetime_string("2019-01-04 12:00:00")
    for i in range(static.RECURRING_LIMIT + 1):
        utils.debug_time = utils.debug_time + timedelta(days=1)
        notifications.send_reminders(reddit, database)
        assert "I've sent you at least" not in reddit.sent_messages[-1].body
        assert i + 1 == database.get_or_add_user("Watchful1").recurring_sent

    utils.debug_time = utils.debug_time + timedelta(days=1)
    notifications.send_reminders(reddit, database)
    assert "I've sent you at least" in reddit.sent_messages[-1].body
    reminders = database.get_all_user_reminders("Watchful1")
    assert len(reminders) == 0

    static.RECURRING_LIMIT = old_limit
Пример #10
0
def process_remind_me(message, reddit, database, recurring):
    log.info("Processing RemindMe message")
    trigger = static.TRIGGER_RECURRING_LOWER if recurring else static.TRIGGER_LOWER
    time = utils.find_reminder_time(message.body, trigger)

    message_text = utils.find_reminder_message(message.body, trigger)

    reminder, result_message = Reminder.build_reminder(
        source=utils.message_link(message.id),
        message=message_text,
        user=database.get_or_add_user(message.author.name),
        requested_date=utils.datetime_from_timestamp(message.created_utc),
        time_string=time,
        recurring=recurring)
    if reminder is None:
        log.debug("Reminder not valid, returning")
        return [result_message], False

    database.add_reminder(reminder)
    database.commit()

    log.info(
        f"Reminder created: {reminder.id} : {utils.get_datetime_string(reminder.target_date)}"
    )

    bldr = reminder.render_message_confirmation(
        result_message, pushshift_minutes=reddit.get_effective_pushshift_lag())
    return [''.join(bldr)], True
Пример #11
0
    def get_reminder(self, reminder_id):
        log.debug(f"Fetching reminder by id: {reminder_id}")
        c = self.dbConn.cursor()
        c.execute(
            '''
			SELECT rm.ID, rm.Source, rm.RequestedDate, rm.TargetDate, rm.Message, rm.User, rm.Defaulted, us.TimeZone
			FROM reminders rm
				LEFT JOIN user_settings us
					ON us.User = rm.User
			WHERE rm.ID = ?
			''', (reminder_id, ))

        result = c.fetchone()
        if result is None or len(result) == 0:
            log.debug("Reminder not found")
            return None

        reminder = Reminder(source=result[1],
                            target_date=utils.parse_datetime_string(result[3]),
                            message=result[4],
                            user=result[5],
                            db_id=result[0],
                            requested_date=utils.parse_datetime_string(
                                result[2]),
                            defaulted=result[6] == 1,
                            timezone=result[7])

        return reminder
Пример #12
0
def test_send_recurring_reminder(database, reddit):
    reminder = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user=database.get_or_add_user("Watchful1"),
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-05 05:00:00"),
        recurrence="one day")
    database.add_reminder(reminder)

    utils.debug_time = utils.parse_datetime_string("2019-01-05 12:00:00")
    notifications.send_reminders(reddit, database)

    assert len(reddit.sent_messages) == 1

    message_body = reddit.sent_messages[0].body
    assert "I'm here to remind you" in message_body
    assert reminder.message in message_body
    assert "The source comment or message" in message_body
    assert reminder.source in message_body
    assert "This is a repeating reminder. I'll message you again in " in message_body
    assert reminder.recurrence in message_body

    reminders = database.get_all_user_reminders("Watchful1")
    assert len(reminders) == 1
    assert reminders[0].target_date == utils.parse_datetime_string(
        "2019-01-06 05:00:00")
Пример #13
0
    def get_pending_reminders(self, count, timestamp):
        log.debug("Fetching pending reminders")
        c = self.dbConn.cursor()
        results = []
        for row in c.execute(
                '''
			SELECT rm.ID, rm.Source, rm.RequestedDate, rm.TargetDate, rm.Message, rm.User, rm.Defaulted, us.TimeZone
			FROM reminders rm
				LEFT JOIN user_settings us
					ON us.User = rm.User
			WHERE rm.TargetDate < ?
			ORDER BY rm.TargetDate
			LIMIT ?
			''', (utils.get_datetime_string(timestamp), count)):
            reminder = Reminder(
                source=row[1],
                target_date=utils.parse_datetime_string(row[3]),
                message=row[4],
                user=row[5],
                db_id=row[0],
                requested_date=utils.parse_datetime_string(row[2]),
                defaulted=row[6] == 1,
                timezone=row[7])
            results.append(reminder)

        log.debug(f"Found reminders: {len(results)}")
        return results
Пример #14
0
def test_remove_reminder(database, reddit):
    reminder1 = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user="******",
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-04 05:00:00"))
    reminder2 = Reminder(
        source="https://www.reddit.com/message/messages/YYYYY",
        message="FFFFF",
        user="******",
        requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-02-05 07:00:00"))
    reminder3 = Reminder(
        source="https://www.reddit.com/message/messages/ZZZZZ",
        message="JJJJJ",
        user="******",
        requested_date=utils.parse_datetime_string("2019-03-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-03-05 07:00:00"))
    database.save_reminder(reminder1)
    database.save_reminder(reminder2)
    database.save_reminder(reminder3)

    message = reddit_test.RedditObject(body=f"Remove! test",
                                       author="Watchful2")
    messages.process_message(message, reddit, database)
    assert "I couldn't find a reminder id to remove." in message.get_first_child(
    ).body

    message = reddit_test.RedditObject(body=f"Remove! {reminder1.db_id}",
                                       author="Watchful2")
    messages.process_message(message, reddit, database)
    assert "It looks like you don't own this reminder or it doesn't exist." in message.get_first_child(
    ).body

    message = reddit_test.RedditObject(body=f"Remove! {reminder1.db_id}",
                                       author="Watchful1")
    messages.process_message(message, reddit, database)
    assert "Reminder deleted." in message.get_first_child().body

    assert len(database.get_user_reminders("Watchful1")) == 1
    assert len(database.get_user_reminders("Watchful2")) == 1
Пример #15
0
def test_reset_recurring_reminder_limit(database, reddit):
    reminder = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user=database.get_or_add_user("Watchful1"),
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-05 05:00:00"),
        recurrence="one day")
    database.add_reminder(reminder)

    utils.debug_time = utils.parse_datetime_string("2019-01-05 12:00:00")
    notifications.send_reminders(reddit, database)
    assert database.get_or_add_user("Watchful1").recurring_sent == 1

    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)

    assert database.get_or_add_user("Watchful1").recurring_sent == 0
Пример #16
0
def test_send_reminder(database, reddit):
	reminder = Reminder(
			source="https://www.reddit.com/message/messages/XXXXX",
			message="KKKKK",
			user="******",
			requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
			target_date=utils.parse_datetime_string("2019-01-05 05:00:00")
		)
	database.save_reminder(reminder)

	utils.debug_time = utils.parse_datetime_string("2019-01-05 12:00:00")
	notifications.send_reminders(reddit, database)

	assert len(reddit.sent_messages) == 1

	message_body = reddit.sent_messages[0].body
	assert "I'm here to remind you" in message_body
	assert reminder.message in message_body
	assert "The source comment or message" in message_body
	assert reminder.source in message_body
Пример #17
0
def parse_comment(comment, database, count_string, reddit):
    if comment['author'] == static.ACCOUNT_NAME:
        log.debug("Comment is from remindmebot")
        return None, None
    if comment['author'] in static.BLACKLISTED_ACCOUNTS:
        log.debug("Comment is from a blacklisted account")
        return None, None

    log.info(
        f"{count_string}: Processing comment {comment['id']} from u/{comment['author']}"
    )
    body = comment['body'].lower().strip()
    recurring = False
    cakeday = False
    allow_default = True
    if trigger_in_text(body, static.TRIGGER_RECURRING_LOWER):
        log.debug("Recurring reminder comment")
        recurring = True
        trigger = static.TRIGGER_RECURRING_LOWER
    elif trigger_in_text(body, static.TRIGGER_LOWER):
        log.debug("Regular comment")
        trigger = static.TRIGGER_LOWER
    elif trigger_start_of_line(body, static.TRIGGER_CAKEDAY_LOWER):
        log.debug("Cakeday comment")
        cakeday = True
        recurring = True
        trigger = static.TRIGGER_CAKEDAY_LOWER
    elif trigger_start_of_line(body, static.TRIGGER_SPLIT_LOWER):
        log.debug("Regular split comment")
        trigger = static.TRIGGER_SPLIT_LOWER
        allow_default = False
    else:
        log.debug("Command not in comment")
        return None, None

    target_date = None
    if cakeday:
        if database.user_has_cakeday_reminder(comment['author']):
            log.info("Cakeday already exists")
            return None, None

        target_date = utils.get_next_anniversary(
            reddit.get_user_creation_date(comment['author']))
        message_text = static.CAKEDAY_MESSAGE
        time = "1 year"

    else:
        time = utils.find_reminder_time(comment['body'], trigger)
        message_text = utils.find_reminder_message(comment['body'], trigger)

    reminder, result_message = Reminder.build_reminder(
        source=utils.reddit_link(comment['permalink']),
        message=message_text,
        user=database.get_or_add_user(comment['author']),
        requested_date=utils.datetime_from_timestamp(comment['created_utc']),
        time_string=time,
        recurring=recurring,
        target_date=target_date,
        allow_default=allow_default)
    if reminder is None:
        return None, None

    if cakeday:
        counters.replies.labels(source='comment', type='cake').inc()
    elif recurring:
        counters.replies.labels(source='comment', type='repeat').inc()
    elif not allow_default:
        counters.replies.labels(source='comment', type='split').inc()
    else:
        counters.replies.labels(source='comment', type='single').inc()

    database.add_reminder(reminder)

    reminder.user.recurring_sent = 0

    return reminder, result_message
Пример #18
0
def test_update_incorrect_comments(database, reddit):
    comment_id1 = reddit_test.random_id()
    thread_id1 = reddit_test.random_id()
    comment1 = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id1,
        link_id="t3_" + thread_id1,
        permalink=f"/r/test/{thread_id1}/_/{comment_id1}/",
        subreddit="test")
    reddit.add_comment(comment1)
    comments.process_comment(comment1.get_pushshift_dict(), reddit, database)

    comment_id2 = reddit_test.random_id()
    thread_id2 = reddit_test.random_id()
    comment2 = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id2,
        link_id="t3_" + thread_id2,
        permalink=f"/r/test/{thread_id2}/_/{comment_id2}/",
        subreddit="test")
    reddit.add_comment(comment2)
    comments.process_comment(comment2.get_pushshift_dict(), reddit, database)

    comment_id3 = reddit_test.random_id()
    thread_id3 = reddit_test.random_id()
    comment3 = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id3,
        link_id="t3_" + thread_id3,
        permalink=f"/r/test/{thread_id3}/_/{comment_id3}/",
        subreddit="test")
    reddit.add_comment(comment3)
    comments.process_comment(comment3.get_pushshift_dict(), reddit, database)

    reminders = [
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment1.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-05 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment1.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-06 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment1.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-07 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment2.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-08 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment2.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-09 05:00:00"))
    ]
    for reminder in reminders:
        database.add_reminder(reminder)

    comments.update_comments(reddit, database)

    assert "3 OTHERS CLICKED THIS LINK" in reddit.get_comment(
        comment_id1).get_first_child().body
    assert "2 OTHERS CLICKED THIS LINK" in reddit.get_comment(
        comment_id2).get_first_child().body
    assert "CLICK THIS LINK" in reddit.get_comment(
        comment_id3).get_first_child().body
Пример #19
0
default_comment = "Hello, I'm here to remind you to see the parent comment!"
info_page = "http://np.reddit.com/r/RemindMeBot/comments/24duzp/remindmebot_info/"

startTime = time.perf_counter()
loop = 0
count_default_comment = 0
count_info_page = 0
for row in old_c.execute('''
	SELECT permalink, message, new_date, origin_date, userID
	FROM message_date
	'''):
    loop += 1
    reminder = Reminder(source=row[0],
                        target_date=utils.parse_datetime_string(row[2]),
                        message=row[1],
                        user=row[4],
                        requested_date=utils.parse_datetime_string(row[3]))
    try:
        if isinstance(reminder.message, (bytes, bytearray)):
            reminder.message = reminder.message.decode("utf-8")
        reminder.message = reminder.message.strip(' "')
        if reminder.message == default_comment:
            count_default_comment += 1
            reminder.message = None

        if isinstance(reminder.source, (bytes, bytearray)):
            reminder.source = reminder.source.decode("utf-8")
        if reminder.source == info_page:
            count_info_page += 1
            reminder.source = "Unfortunately I couldn't find a source for this reminder. " \
Пример #20
0
	def get_incorrect_comments(self, count):
		log.debug(f"Fetching incorrect comments")
		c = self.dbConn.cursor()
		results = []
		for row in c.execute('''
			SELECT cm.ID,
				cm.ThreadID,
				cm.CommentID,
				cm.ReminderId,
				cm.CurrentCount,
				cm.User,
				cm.Source,
				rm.ID,
				rm.Source,
				rm.RequestedDate,
				rm.TargetDate,
				rm.Message,
				rm.User,
				rm.Defaulted,
				rm.TimeZone,
				rm.NewCount
			FROM comments cm
			LEFT JOIN
				(
					SELECT rm1.ID,
						rm1.Source,
						rm1.RequestedDate,
						rm1.TargetDate,
						rm1.Message,
						rm1.User,
						rm1.Defaulted,
						us.TimeZone,
						count(*) as NewCount
					FROM reminders rm1
						INNER JOIN reminders rm2
							ON rm1.Source = rm2.Message
						LEFT JOIN user_settings us
							ON us.User = rm1.User
					GROUP BY rm1.ID
				) AS rm
					ON cm.ReminderId = rm.ID
			WHERE rm.NewCount != cm.CurrentCount
			LIMIT ?
			''', (count,)):
			db_comment = DbComment(
				thread_id=row[1],
				comment_id=row[2],
				reminder_id=row[3],
				user=row[5],
				source=row[6],
				current_count=row[4],
				db_id=row[0]
			)
			reminder = Reminder(
				source=row[8],
				target_date=utils.parse_datetime_string(row[10]),
				message=row[11],
				user=row[12],
				db_id=row[7],
				requested_date=utils.parse_datetime_string(row[9]),
				count_duplicates=row[15],
				thread_id=row[1],
				timezone=row[14],
				defaulted=row[13] == 1
			)
			results.append((db_comment, reminder))

		log.debug(f"Found incorrect comments: {len(results)}")
		return results