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
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
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