viernes, 21 de junio de 2024

Python (VI) NO VA BIEN!!! Robocorp (I) Install rcc. Correr el primer ejemplo en el browser

 1. Instalar rcc

En https://github.com/robocorp/rcc?tab=readme-ov-file#installing-rcc-from-the-command-line dice literalmente:

Windows

  1. Open the command prompt
  2. Download: curl -o rcc.exe https://downloads.robocorp.com/rcc/releases/latest/windows64/rcc.exe
  3. Add to system path: Open Start -> Edit the system environment variables
  4. Test: rcc

macOS

Brew cask from Robocorp tap

  1. Update brew: brew update
  2. Install: brew install robocorp/tools/rcc
  3. Test: rcc

Upgrading: brew upgrade rcc

Linux

  1. Open the terminal
  2. Download: curl -o rcc https://downloads.robocorp.com/rcc/releases/latest/linux64/rcc
  3. Make the downloaded file executable: chmod a+x rcc
  4. Add to path: sudo mv rcc /usr/local/bin/
  5. Test: rcc

===================

2. Ejecutar el módulo de ejemplo del principiante

En https://robocorp.com/docs/courses/beginners-course-python/11-creating-pdf hay un fichero tasks.py que copiamos aquí.

from robocorp.tasks import task
from robocorp import browser

from RPA.HTTP import HTTP
from RPA.Excel.Files import Files
from RPA.PDF import PDF

@task
def robot_spare_bin_python():
    """Insert the sales data for the week and export it as a PDF"""
    browser.configure(
        slowmo=100,
    )
    open_the_intranet_website()
    log_in()
    download_excel_file()
    fill_form_with_excel_data()
    collect_results()
    export_as_pdf()
    log_out()

def open_the_intranet_website():
    """Navigates to the given URL"""
    browser.goto("https://robotsparebinindustries.com/")

def log_in():
    """Fills in the login form and clicks the 'Log in' button"""
    page = browser.page()
    page.fill("#username", "maria")
    page.fill("#password", "thoushallnotpass")
    page.click("button:text('Log in')")

def fill_and_submit_sales_form(sales_rep):
    """Fills in the sales data and click the 'Submit' button"""
    page = browser.page()

    page.fill("#firstname", sales_rep["First Name"])
    page.fill("#lastname", sales_rep["Last Name"])
    page.select_option("#salestarget", str(sales_rep["Sales Target"]))
    page.fill("#salesresult", str(sales_rep["Sales"]))
    page.click("text=Submit")

def download_excel_file():
    """Downloads excel file from the given URL"""
    http = HTTP()
    http.download(url="https://robotsparebinindustries.com/SalesData.xlsx", overwrite=True)

def fill_form_with_excel_data():
    """Read data from excel and fill in the sales form"""
    excel = Files()
    excel.open_workbook("SalesData.xlsx")
    worksheet = excel.read_worksheet_as_table("data", header=True)
    excel.close_workbook()

    for row in worksheet:
        fill_and_submit_sales_form(row)

def collect_results():
    """Take a screenshot of the page"""
    page = browser.page()
    page.screenshot(path="output/sales_summary.png")

def export_as_pdf():
    """Export the data to a pdf file"""
    page = browser.page()
    sales_results_html = page.locator("#sales-results").inner_html()

    pdf = PDF()
    pdf.html_to_pdf(sales_results_html, "output/sales_results.pdf")

def log_out():
    """Presses the 'Log out' button"""
    page = browser.page()
    page.click("text=Log out")

Para ello creamos una carpeta por ejemplo ~/MyPython/prova06_rcc

Copiamos el fichero anterior (tasks.py) en dicha carpeta

Copiamos el siguiente fichero conda.yaml que sale si hemos completado el tutorial indicado en dicha página

# For more details on the format and content:
# https://github.com/robocorp/rcc/blob/master/docs/recipes.md#what-is-in-condayaml
# Tip: Adding a link to the release notes of the packages helps maintenance and security.

channels:
- conda-forge

dependencies:
- python=3.10.12 # https://pyreadiness.org/3.10
- pip=23.2.1 # https://pip.pypa.io/en/stable/news
- robocorp-truststore=0.8.0 # https://pypi.org/project/robocorp-truststore/
- pip:
- rpaframework==28.0.0 # https://rpaframework.org/releasenotes.html
- robocorp==1.4.0 # https://pypi.org/project/robocorp
- robocorp-browser==2.2.1 # https://pypi.org/project/robocorp-browser

Opcionalmente podemos copiar los ficheros LICENSE y README.md

Copiamos el fichero robot.yaml

# For more details on the format and content:
# https://github.com/robocorp/rcc/blob/master/docs/recipes.md#what-is-in-robotyaml

tasks:
Run Task:
shell: python -m robocorp.tasks run tasks.py

environmentConfigs:
- environment_windows_amd64_freeze.yaml
- environment_linux_amd64_freeze.yaml
- environment_darwin_amd64_freeze.yaml
- conda.yaml

artifactsDir: output

PATH:
- .
PYTHONPATH:
- .
ignoreFiles:
- .gitignore

Nos situamos en dichar carpeta y ejecutamos el programa mediante "rcc run"

# Nos situamos y ejecutamos rcc

cd ~/MyPython/prova06_rcc
rcc run

Y ejecuta todo el proceso




No hay comentarios :

Publicar un comentario