Last active
August 19, 2024 13:34
-
-
Save pitvfx/e95318f4084f9ff1c1ac07705d2de62f to your computer and use it in GitHub Desktop.
error fixes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM Check if pyenv is installed, else exit with an error message | |
where /q pyenv >nul 2>nul | |
if %errorlevel% neq 0 ( | |
echo Error: pyenv is not installed. Please install pyenv and try again. | |
exit /b 1 | |
) | |
REM Check if pipenv is installed, else exit with an error message | |
where /q pipenv | |
if %errorlevel% neq 0 ( | |
echo Error: pipenv is not installed. Please install pipenv and try again. | |
exit /b 1 | |
) | |
REM Ask the user which Python version to use | |
set /p python_version=Enter the Python version to use (press Enter for default): | |
REM Ask for the project name | |
set /p project_name=Enter the Django project name: | |
REM Create a directory for the project | |
mkdir %project_name% | |
cd %project_name% | |
REM Create an empty Pipfile | |
echo. > Pipfile | |
REM Install python via pipenv if a version number is given | |
if not "%python_version%" == "" ( | |
call pyenv install %python_version% | |
set path=%pyenv%versions\%python_version%;%path% | |
call pipenv install --python %python_version% | |
) | |
REM Install Django using pipenv and django-debug-toolbar for development | |
call pipenv install django | |
call pipenv install django-debug-toolbar --dev | |
REM Create a Django projectblog | |
call pipenv run django-admin startproject %project_name% . | |
REM Ask for the app name and create the app | |
set /p app_name=Enter the Django app name: | |
call pipenv run python manage.py startapp %app_name% | |
REM Add the app to project settings | |
echo INSTALLED_APPS += ['%app_name%'] >> %project_name%/settings.py | |
REM Apply migrations | |
call pipenv run python manage.py migrate | |
REM Ask for superuser name and create one with password "password" | |
set /p superuser_name=Enter the superuser name: | |
set DJANGO_SUPERUSER_PASSWORD=password | |
call pipenv run python manage.py createsuperuser --username %superuser_name% --email %superuser_name%@localhost --noinput | |
echo Superuser %superuser_name% created with password 'password'. | |
REM Create a runserver.bat file with the command to run the server | |
echo pipenv run python manage.py runserver > runserver.bat | |
REM Execute the runserver.bat script in another terminal window | |
start "Django Server" runserver.bat | |
timeout 1 > nul | |
REM Start web browser | |
start http://localhost:8000/admin/ | |
REM This will exit the shell and activate the virtual environment | |
call pipenv shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import argparse | |
from fasthtml.components import html2ft | |
def main(): | |
# Set up the argument parser | |
parser = argparse.ArgumentParser(description='Process an HTML file and output a Python file.') | |
parser.add_argument('filename', help='The name of the HTML file (without extension) located in the src folder.') | |
parser.add_argument('--output-dir', default='.', help='Optional output directory for the .py file (default is root).') | |
# Parse the arguments | |
args = parser.parse_args() | |
filename = args.filename | |
output_dir = args.output_dir | |
html_file = os.path.join('src', f"{filename}.html") | |
# Check if the HTML file exists | |
if not os.path.exists(html_file): | |
print(f"Error: {html_file} does not exist.") | |
sys.exit(1) | |
# Ensure the output directory exists | |
if not os.path.exists(output_dir): | |
os.makedirs(output_dir) | |
# Read the HTML file content | |
with open(html_file, 'r') as f: | |
html_content = f.read() | |
# Process the content through html2ft | |
processed_content = html2ft(html_content) | |
# Write the result to a .py file in the specified output directory | |
py_file = os.path.join(output_dir, f"{filename}.py") | |
with open(py_file, 'w') as f: | |
f.write("from fasthtml.components import *\n\n") | |
f.write(processed_content) | |
print(f"Processed content saved to {py_file}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment