This directory contains Python scripts to create new communities in the PyNewsServer database with properly hashed passwords.
Usage:
python scripts/create_community.py <username> <email> <password>Example:
python scripts/create_community.py john_doe [email protected] mypassword123Features:
- Takes command line arguments for username, email, and password
- Automatically hashes the password using the
hash_passwordfunction fromapp.services.auth - Creates the community record in the database
- Returns success confirmation with community details
Usage:
python scripts/add_community.pyFeatures:
- Interactive prompt for username, email, and password input
- Confirmation step before creating the community
- Password is hidden in the confirmation display
- Uses the same
hash_passwordfunction for security
Usage:
python scripts/example_create_community.pyFeatures:
- Demonstrates how to create a community programmatically
- Shows the password hashing process step by step
- Good for understanding the implementation
- Creates a sample community with hardcoded values
- All scripts use the
hash_passwordfunction fromapp.services.auth - Passwords are hashed using bcrypt with salt before storage
- Plain text passwords are never stored in the database
- Scripts automatically initialize the database if it doesn't exist
- Uses the same async database session management as the main application
- All database operations are handled asynchronously
- Python virtual environment must be activated
- All dependencies from
requirements.txtmust be installed - Scripts must be run from the project root directory
If you have a virtual environment set up (recommended):
# Activate the virtual environment first
source .venv/bin/activate # On Linux/Mac
# or
.venv\Scripts\activate # On Windows
# Then run any script
python scripts/create_community.py username email passwordOr use the full path to the Python executable:
/path/to/your/project/.venv/bin/python scripts/create_community.py username email passwordCreating community for user: john_doe
✅ Community created successfully!
ID: 1
Username: john_doe
Email: [email protected]
Created at: 2025-10-14 12:02:15.778722
These scripts use the same:
- Database models (
app.services.database.models.communities.Community) - Authentication functions (
app.services.auth.hash_password) - Database session management (
app.services.database.database)
This ensures consistency with the main application's authentication and data handling.