Exemple #1
0
    def test05_get_all_players(self):
        # Fake out the django table in our test db.
        c = self.db.cursor()
        c.execute("CREATE TABLE auth_user ( "
                  "  id INTEGER PRIMARY KEY, "
                  "  username VARCHAR(255), "
                  "  first_name VARCHAR(255) "
                  "); ")
        c.execute(
            "CREATE TABLE cardstories_userprofile ( "
            "  user_id INTEGER, "
            "  activity_notifications_disabled BOOL NOT NULL DEFAULT False "
            "); ")

        players = [(1, '*****@*****.**', 'John Johnson', False),
                   (2, '*****@*****.**', 'Bill Billson', True),
                   (88, '*****@*****.**', None, False)]

        for player in players:
            c.execute(
                'INSERT INTO auth_user (id, username, first_name) VALUES (?, ?, ?)',
                (player[0], player[1], player[2]))
            c.execute(
                'INSERT INTO cardstories_userprofile (user_id, activity_notifications_disabled) VALUES (?, ?)',
                (player[0], player[3]))

        result = aggregate.get_all_players(c)
        self.assertEquals(len(result), 3)
        self.assertEquals(result[0], players[0])
        self.assertEquals(result[1], players[1])
        # For players without first name present in the database, it shouold return
        # the part of the email before the '@' character in place of the name.
        self.assertEquals(result[2],
                          (88, '*****@*****.**', 'bigjoe99', False))
        c.close()
    def test05_get_all_players(self):
        # Fake out the django table in our test db.
        c = self.db.cursor()
        c.execute(
            "CREATE TABLE auth_user ( "
            "  id INTEGER PRIMARY KEY, "
            "  username VARCHAR(255), "
            "  first_name VARCHAR(255) "
            "); ")

        players = [
            (1, '*****@*****.**', 'John Johnson'),
            (2, '*****@*****.**', 'Bill Billson'),
            (88, '*****@*****.**', None)
        ]

        for player in players:
            c.execute('INSERT INTO auth_user (id, username, first_name) VALUES (?, ?, ?)', player)

        result = aggregate.get_all_players(c)
        self.assertEquals(len(result), 3)
        self.assertEquals(result[0], players[0])
        self.assertEquals(result[1], players[1])
        # For players without first name present in the database, it shouold return
        # the part of the email before the '@' character in place of the name.
        self.assertEquals(result[2], (88, '*****@*****.**', 'bigjoe99'))
        c.close()
Exemple #3
0
    def test05_get_all_players(self):
        # Fake out the django table in our test db.
        c = self.db.cursor()
        c.execute(
            "CREATE TABLE auth_user ( "
            "  id INTEGER PRIMARY KEY, "
            "  username VARCHAR(255), "
            "  first_name VARCHAR(255) "
            "); ")
        c.execute(
            "CREATE TABLE cardstories_userprofile ( "
            "  user_id INTEGER, "
            "  activity_notifications_disabled BOOL NOT NULL DEFAULT False "
            "); ")

        players = [
            (1, '*****@*****.**', 'John Johnson', False),
            (2, '*****@*****.**', 'Bill Billson', True),
            (88, '*****@*****.**', None, False)
        ]

        for player in players:
            c.execute('INSERT INTO auth_user (id, username, first_name) VALUES (?, ?, ?)', (player[0], player[1], player[2]))
            c.execute('INSERT INTO cardstories_userprofile (user_id, activity_notifications_disabled) VALUES (?, ?)', (player[0], player[3]))

        result = aggregate.get_all_players(c)
        self.assertEquals(len(result), 3)
        self.assertEquals(result[0], players[0])
        self.assertEquals(result[1], players[1])
        # For players without first name present in the database, it shouold return
        # the part of the email before the '@' character in place of the name.
        self.assertEquals(result[2], (88, '*****@*****.**', 'bigjoe99', False))
        c.close()
Exemple #4
0
def loop(ws_db_path, django_db_path, email_list=None, verbose=False):
    django_conn = sqlite3.connect(django_db_path)
    cursor = django_conn.cursor()
    players_list = aggregate.get_all_players(cursor)
    aggregate.seed_playerid2name(players_list)
    cursor.close()
    django_conn.close()

    smtp = send.smtp_open()
    ws_conn = sqlite3.connect(ws_db_path)
    cursor = ws_conn.cursor()

    count = 0

    for id, email, name, unsubscribed in players_list:
        if email_list and not email in email_list:
            continue
        if unsubscribed:
            continue
        game_ids = aggregate.get_player_game_ids(cursor, id)
        last_active = aggregate.get_players_last_activity(cursor, id)
        yesterday = datetime.now() - timedelta(days=1)
        recent_game_activities = aggregate.get_game_activities(
            cursor, game_ids, id, happened_since=yesterday)

        should_send = should_send_email(last_active, recent_game_activities)
        if should_send:
            context = get_context(cursor, id, game_ids, last_active)
            # Don't send if there isn't any new info in the context.
            if not is_context_empty(context):
                if verbose:
                    print 'Sending email to %s' % email
                send.send_mail(smtp, email, context)
                count += 1

    cursor.close()
    ws_conn.close()
    smtp.close()

    return count
Exemple #5
0
def loop(ws_db_path, django_db_path, email_list=None, verbose=False):
    django_conn = sqlite3.connect(django_db_path)
    cursor = django_conn.cursor()
    players_list = aggregate.get_all_players(cursor)
    aggregate.seed_playerid2name(players_list)
    cursor.close()
    django_conn.close()

    smtp = send.smtp_open()
    ws_conn = sqlite3.connect(ws_db_path)
    cursor = ws_conn.cursor()

    count = 0

    for id, email, name, unsubscribed in players_list:
        if email_list and not email in email_list:
            continue
        if unsubscribed:
            continue
        game_ids = aggregate.get_player_game_ids(cursor, id)
        last_active = aggregate.get_players_last_activity(cursor, id)
        yesterday = datetime.now() - timedelta(days=1)
        recent_game_activities = aggregate.get_game_activities(cursor, game_ids, id, happened_since=yesterday)

        should_send = should_send_email(last_active, recent_game_activities)
        if should_send:
            context = get_context(cursor, id, game_ids, last_active)
            # Don't send if there isn't any new info in the context.
            if not is_context_empty(context):
                if verbose:
                    print 'Sending email to %s' % email
                send.send_mail(smtp, email, context)
                count += 1

    cursor.close()
    ws_conn.close()
    smtp.close()

    return count
Exemple #6
0
def loop(ws_db_path, django_db_path):
    django_conn = sqlite3.connect(django_db_path)
    cursor = django_conn.cursor()
    players_list = aggregate.get_all_players(cursor)
    aggregate.seed_playerid2name(players_list)
    cursor.close()
    django_conn.close()

    ws_conn = sqlite3.connect(ws_db_path)
    cursor = ws_conn.cursor()

    count = 0
    for id, email, name in players_list:
        last_active = aggregate.get_players_last_activity(cursor, id)
        if should_send(id, last_active):
            context = get_context(cursor, id, last_active)
            # TODO: Make send_mail work something like this:
            send.send_mail(email, name, context)
            count += 1

    cursor.close()
    ws_conn.close()

    return count