meal-order-manager/scripts/seed_roster.py

59 lines
1.5 KiB
Python
Raw Normal View History

"""
Seeds the employee roster into DynamoDB from config.json.
Usage: python3 scripts/seed_roster.py
Each employee needs: name, email, and slack_user_id (for DM reminders).
To find Slack user IDs, use the Slack API:
curl -s -H "Authorization: Bearer $TOKEN" \
"https://slack.com/api/users.lookupByEmail?email=name@seahavenind.com" \
| jq .user.id
"""
import json
import os
import sys
from pathlib import Path
import boto3
PROJECT_ROOT = Path(__file__).resolve().parents[1]
CONFIG_PATH = PROJECT_ROOT / "config.json"
TABLE_NAME = os.environ.get("TABLE_NAME", "meal-order-manager-orders")
def main():
with open(CONFIG_PATH) as f:
config = json.load(f)
roster = config.get("roster", [])
if not roster:
print("No roster found in config.json", file=sys.stderr)
sys.exit(1)
for emp in roster:
if "slack_user_id" not in emp:
emp["slack_user_id"] = ""
table = boto3.resource("dynamodb").Table(TABLE_NAME)
from datetime import datetime
table.put_item(
Item={
"PK": "CONFIG",
"SK": "ROSTER",
"employees": roster,
"updated_at": datetime.now().isoformat(),
}
)
print(f"Seeded {len(roster)} employees to DynamoDB")
for emp in roster:
sid = emp.get("slack_user_id", "")
status = "ready" if sid else "MISSING slack_user_id"
print(f" {emp['name']} ({emp['email']}) — {status}")
if __name__ == "__main__":
main()