Grouped emails - Carcassonne

Hi all,

I have been following the Carcassonne tutorial to implement at my work place - however, this will not be integrated in Slack, but rather just using the grouping function for games of the groups choice. I have enabled the grouping, but now would like to send emails directly to the groups to inform them of their randomly chosen groups.

I am able to send emails to the ‘player_rows’ which identifies everyone thats available to play - but I would like to isolate the emails to just the rows of groups.

Code Sample:

def announce_games(): 
  current_games = app_tables.users.search(enabled=True)
  player_rows = [game['email'] for game in current_games]
  for i, group in enumerate(current_games):
    random_id = random.sample(player_rows, k=3)[0]

    response = anvil.email.send(to= player_rows, 
          text=f"By royal degree you {str(len(player_rows))} citizens {random_id} you have been randomly chosen to start the royal game.")

The groups of players are stored in rows in ‘games’ with a column called ‘players’ I have tried various app_tables.games etc. but with no results!

Any assistance is greatly appreciated!

Thanks

Could you give an example of 1 or 2 rows in the app_table.games, so I can visualize it a bit better?

It seems like you want to send emails to specific groups of players based on their grouping in the “games” table. To achieve this, I think you might need to modify your code to retrieve the group-specific player rows and send emails to those players.

Here’s an updated version of your code that I think should achieve that:

import random

def announce_games(): 
    current_games = app_tables.games.search(enabled=True)
    
    for group in current_games:
        players = group['players']  # Assuming 'players' is a column in the 'games' table
        
        if len(players) >= 3:
            random_ids = random.sample(players, k=3)

            for player in random_ids:
                response = anvil.email.send(
                    to=player['email'], 
                    text=f"By royal decree, you, {player['name']}, have been randomly chosen to start the royal game in your group.")

I hope this helps! Let me know if you have any further questions.

1 Like