Пример #1
0
def get_context(cursor, player_id, last_active):
    game_ids = aggregate.get_player_game_ids(cursor, player_id)
    game_activities = aggregate.get_game_activities(cursor, game_ids, player_id, happened_since=last_active)
    available_games = aggregate.get_available_games(cursor, created_since=last_active, exclude_game_ids=game_ids)
    completed_games = aggregate.get_completed_games(cursor, completed_since=last_active, exclude_game_ids=game_ids)

    context = {'game_activities': game_activities,
               'available_games': available_games,
               'completed_games': completed_games}

    return context
Пример #2
0
    def test01_get_player_game_ids(self):
        c = self.db.cursor()
        player_id = 1231
        game_ids = [34, 64, 322, 340]
        # fill in some game_ids for player.
        for game_id in game_ids:
            c.execute('insert into player2game (player_id, game_id) values (?, ?)', [player_id, game_id])
        # fill in some bogus ones.
        c.execute('insert into player2game (player_id, game_id) values (?, ?)', [player_id + 3, game_ids[0]])
        c.execute('insert into player2game (player_id, game_id) values (?, ?)', [player_id + 2, game_ids[0]])
        c.execute('insert into player2game (player_id, game_id) values (?, ?)', [player_id + 2, game_ids[0] + 12])

        result = aggregate.get_player_game_ids(c, player_id)
        self.assertEquals(sorted(result), sorted(game_ids))
Пример #3
0
    def test01_get_player_game_ids(self):
        c = self.db.cursor()
        player_id = 1231
        game_ids = [34, 64, 322, 340]
        # fill in some game_ids for player.
        for game_id in game_ids:
            c.execute(
                'insert into player2game (player_id, game_id) values (?, ?)',
                [player_id, game_id])
        # fill in some bogus ones.
        c.execute('insert into player2game (player_id, game_id) values (?, ?)',
                  [player_id + 3, game_ids[0]])
        c.execute('insert into player2game (player_id, game_id) values (?, ?)',
                  [player_id + 2, game_ids[0]])
        c.execute('insert into player2game (player_id, game_id) values (?, ?)',
                  [player_id + 2, game_ids[0] + 12])

        result = aggregate.get_player_game_ids(c, player_id)
        self.assertEquals(sorted(result), sorted(game_ids))
Пример #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
Пример #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