Last active
December 22, 2024 19:15
-
-
Save patriciojlg/1f7ebea1e1dcfa32297d330dec5e930d to your computer and use it in GitHub Desktop.
scrapy-template
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
#!/bin/bash | |
echo "Ingrese el nuevo nombre para el proyecto Scrapy:" | |
read PROJECT_NAME | |
# Crear el proyecto base de Scrapy | |
scrapy startproject $PROJECT_NAME | |
# Navegar al directorio del proyecto | |
cd $PROJECT_NAME || exit | |
# Crear carpetas adicionales | |
mkdir -p $PROJECT_NAME/models | |
mkdir -p $PROJECT_NAME/playwright | |
mkdir -p tests/dev | |
# Crear archivos adicionales | |
touch $PROJECT_NAME/models/__init__.py | |
touch $PROJECT_NAME/models/item.py | |
touch $PROJECT_NAME/playwright/__init__.py | |
touch $PROJECT_NAME/playwright/browser.py | |
touch tests/dev/__init__.py | |
touch tests/dev/test_integration.py | |
touch tests/dev/test_pw.py | |
touch tests/test_integration.py | |
touch tests/test_pw.py | |
touch pytest.ini | |
touch Makefile | |
touch docker-compose.yml | |
touch Dockerfile | |
# Generar contenido en algunos archivos clave | |
cat > pytest.ini <<EOL | |
[pytest] | |
testpaths = tests | |
EOL | |
cat > Makefile <<EOL | |
test: | |
\tpytest | |
lint: | |
\tblack $PROJECT_NAME | |
EOL | |
cat > Dockerfile <<EOL | |
FROM python:3.11-slim | |
WORKDIR /app | |
COPY requirements.txt . | |
RUN pip install --no-cache-dir -r requirements.txt | |
COPY . . | |
CMD ["pytest"] | |
EOL | |
cat > docker-compose.yml <<EOL | |
version: '3.8' | |
services: | |
app: | |
build: . | |
command: pytest | |
volumes: | |
- .:/app | |
EOL | |
cat > $PROJECT_NAME/models/item.py <<EOL | |
from pydantic import BaseModel | |
class Item(BaseModel): | |
title: str | |
price: float | |
description: str | |
image: str | |
url: str | |
created_at: str | |
updated_at: str | |
@classmethod | |
def from_dict(cls, adict): | |
return cls(**adict) | |
EOL | |
cat > $PROJECT_NAME/playwright/browser.py <<EOL | |
from playwright.sync_api import sync_playwright | |
class Google: | |
def __init__(self): | |
pass | |
def start_google(self): | |
title = None | |
with sync_playwright() as p: | |
browser = p.chromium.launch() | |
page = browser.new_page() | |
page.goto("https://google.com") | |
title = page.title() | |
return title | |
EOL | |
echo "Proyecto $PROJECT_NAME creado exitosamente." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment