Skip to content

jasonwu513/lucky_draw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lucky Draw

A flexible command-line lucky draw program written in Rust. Works with any CSV file format.

Features

  • Dynamic CSV Support: Works with any CSV file structure - no hardcoded columns
  • Flexible Column Selection: Choose which columns to display for winners
  • Privacy Masking: Mask sensitive data (email, names) with * characters
  • Multiple Winners: Draw any number of winners at once
  • Colored Output: Beautiful terminal output with colors

Installation

cargo build --release

The binary will be available at target/release/lucky_draw.

Usage

Running with Cargo

When using cargo run, add -- to separate cargo's arguments from the program's arguments:

cargo run -- [program arguments]
# Basic usage (draws 1 winner, shows all columns)
cargo run -- -f data.csv

# Draw 3 winners
cargo run -- -f data.csv -n 3

# Show specific columns only
cargo run -- -f data.csv -c "name,email,department"

# Enable privacy masking for sensitive columns
cargo run -- -f data.csv -c "name,email" -p "email,name"

# List available columns in a CSV file
cargo run -- -f data.csv --list-columns

Running the Compiled Binary

After building, you can run the binary directly without --:

# Debug build
./target/debug/lucky_draw -f data.csv -n 3

# Release build
./target/release/lucky_draw -f data.csv -n 3 -c "name,email" -p "email"

Options

Option Short Description
--file <FILE> -f CSV file path (default: eatDiary_app_survey.csv)
--num-winners <N> -n Number of winners to draw (default: 1)
--columns <COLS> -c Columns to display (comma-separated)
--privacy <COLS> -p Columns to mask with * (comma-separated)
--list-columns List all available columns from the CSV
--help -h Show help message

Privacy Masking

The privacy feature masks sensitive data while preserving length information:

Original Masked
John J**n
test@example.com t**t@example.com
Alexander A*******r

The number of * characters matches the number of hidden characters, allowing you to distinguish between different masked values.

Example Output

[OK] Successfully loaded 16 participants
[..] Drawing 2 winner(s)...
[**] Privacy columns: email, facebook_name

>>> Winner #1 <<<
==================================================
  |        facebook_name: J**n [masked]
  |                email: j**n@example.com [masked]
  |           occupation: Engineer
==================================================

>>> Winner #2 <<<
==================================================
  |        facebook_name: A*******r [masked]
  |                email: a***x@example.com [masked]
  |           occupation: Designer
==================================================

CSV Format

The program automatically reads the header row from your CSV file. Any valid CSV with headers will work:

name,email,department,join_date
John Doe,john@example.com,Engineering,2024-01-15
Jane Smith,jane@example.com,Marketing,2024-02-20

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages