/
Askoline
/
Homework03
Обзор
Документация
Войти
/
Askoline
/
Homework03
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
fill_files.py
123 строки
3 KB
Askoline
first_commit
05 авг 2026, 14:29
05 авг 2026, 14:29
a97374b
Код
Авторство
О чём код?
# -*- coding: utf-8 -*- # fill_files.py # Script to create all project files with content def create_all_files(): """Create all project files with content""" # config.py content config_content = '''# -*- coding: utf-8 -*- # config.py # Configuration for database connection import os from pathlib import Path from dotenv import load_dotenv # Load environment variables from .env file load_dotenv() # Base directory BASE_DIR = Path(__file__).parent # Database configuration DB_CONFIG = { "host": os.getenv("DB_HOST", "localhost"), "port": os.getenv("DB_PORT", "5432"), "user": os.getenv("DB_USER", "postgres"), "password": os.getenv("DB_PASSWORD", "postgres"), "database": os.getenv("DB_NAME", "bookstore"), } # Database URL for SQLAlchemy def get_database_url(): """Get database URL from environment or use SQLite by default""" db_type = os.getenv("DB_TYPE", "sqlite") if db_type == "postgresql": return f"postgresql://{DB_CONFIG['user']}:{DB_CONFIG['password']}@{DB_CONFIG['host']}:{DB_CONFIG['port']}/{DB_CONFIG['database']}" elif db_type == "mysql": return f"mysql+pymysql://{DB_CONFIG['user']}:{DB_CONFIG['password']}@{DB_CONFIG['host']}:{DB_CONFIG['port']}/{DB_CONFIG['database']}" else: # SQLite by default db_path = os.getenv("SQLITE_PATH", str(BASE_DIR / "bookstore.db")) return f"sqlite:///{db_path}" # Fixtures directory FIXTURES_DIR = BASE_DIR / "fixtures" # Create fixtures directory if it doesn"t exist FIXTURES_DIR.mkdir(exist_ok=True)''' # .env content env_content = '''# .env # Database configuration # Database type: sqlite, postgresql, mysql DB_TYPE=sqlite # For SQLite SQLITE_PATH=bookstore.db # For PostgreSQL/MySQL (if DB_TYPE is not sqlite) DB_HOST=localhost DB_PORT=5432 DB_USER=postgres DB_PASSWORD=postgres DB_NAME=bookstore''' # requirements.txt content requirements_content = '''sqlalchemy>=2.0.0 psycopg2-binary>=2.9.0 pymysql>=1.0.0 python-dotenv>=1.0.0''' # README.md content - используем обычные кавычки и экранирование readme_content = '''# Book Store Management System SQLAlchemy project for managing book sales. ## Setup 1. Install dependencies: pip install -r requirements.txt 2. Generate fixtures: python create_fixtures.py 3. Load data: python load_fixtures.py 4. Test query: python query_publisher_sales.py ## Database Configuration By default, it uses SQLite (bookstore.db). To use PostgreSQL, change DB_TYPE in .env file.''' # Create files with open('config.py', 'w', encoding='utf-8') as f: f.write(config_content) print("Created: config.py") with open('.env', 'w', encoding='utf-8') as f: f.write(env_content) print("Created: .env") with open('requirements.txt', 'w', encoding='utf-8') as f: f.write(requirements_content) print("Created: requirements.txt") with open('README.md', 'w', encoding='utf-8') as f: f.write(readme_content) print("Created: README.md") print("\nAll files created successfully!") if __name__ == "__main__": create_all_files()