mirror of
https://github.com/jaypyles/Scraperr.git
synced 2025-10-30 05:57:12 +00:00
Compare commits
51 Commits
v1.0.8
...
d2bc9c53ff
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2bc9c53ff | ||
|
|
734974df83 | ||
|
|
b6dbd0dc82 | ||
|
|
d57dd0af1a | ||
|
|
23fccd7afb | ||
|
|
f89a460206 | ||
|
|
1169d48992 | ||
|
|
ff809d7833 | ||
|
|
41c7f6795c | ||
|
|
21c2155786 | ||
|
|
6d45bd129c | ||
|
|
3ab31bd186 | ||
|
|
e00c187e68 | ||
|
|
39c0d17e1e | ||
|
|
b66963ed33 | ||
|
|
813550e07c | ||
|
|
dcb4afe01b | ||
|
|
344d9036c3 | ||
|
|
96552cd1d1 | ||
|
|
d4ac85d206 | ||
|
|
a805b98ce3 | ||
|
|
eaf047ecd8 | ||
|
|
d43040fe08 | ||
|
|
f0813323f0 | ||
|
|
fb7986bccf | ||
|
|
a1664856a6 | ||
|
|
467244b7f8 | ||
|
|
b91a133b4d | ||
|
|
aeed81a6df | ||
|
|
d4edb9d93e | ||
|
|
5ebd96b62b | ||
|
|
d602d3330a | ||
|
|
6639e8b48f | ||
|
|
263e46ba4d | ||
|
|
f815a58efc | ||
|
|
50ec5df657 | ||
|
|
28de0f362c | ||
|
|
6b33723cac | ||
|
|
5c89e4d7d2 | ||
|
|
ed0828a585 | ||
|
|
1b8c8c779a | ||
|
|
267cc73657 | ||
|
|
92ff16d9c3 | ||
|
|
8b2e5dc9c3 | ||
|
|
7f1bc295ac | ||
|
|
031572325f | ||
|
|
48d3bf9214 | ||
|
|
e07abcd089 | ||
|
|
8a933b88a7 | ||
|
|
863dbcd044 | ||
|
|
de40181a6f |
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@@ -0,0 +1,4 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
50
.github/actions/push-to-helm/action.yaml
vendored
Normal file
50
.github/actions/push-to-helm/action.yaml
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
name: Publish Helm Chart
|
||||
description: Publish a Helm chart to a target repository
|
||||
|
||||
inputs:
|
||||
app-repo-token:
|
||||
required: true
|
||||
description: "The token for the target repository"
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Checkout app repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Helm
|
||||
uses: azure/setup-helm@v3
|
||||
|
||||
- name: Package Helm chart
|
||||
run: |
|
||||
mkdir -p packaged
|
||||
helm package helm -d packaged
|
||||
shell: bash
|
||||
|
||||
- name: Clone target Helm repo
|
||||
run: |
|
||||
git clone https://github.com/jaypyles/helm.git target-repo
|
||||
cd target-repo
|
||||
git config user.name "github-actions"
|
||||
git config user.email "github-actions@github.com"
|
||||
git fetch origin gh-pages # Fetch gh-pages explicitly
|
||||
git checkout gh-pages # Checkout gh-pages branch
|
||||
git pull origin gh-pages # Pull latest changes from gh-pages
|
||||
shell: bash
|
||||
|
||||
- name: Copy package and update index
|
||||
run: |
|
||||
APP_NAME="scraperr"
|
||||
mkdir -p target-repo/charts/$APP_NAME
|
||||
cp packaged/*.tgz target-repo/charts/$APP_NAME/
|
||||
cd target-repo/charts/$APP_NAME
|
||||
helm repo index . --url https://jaypyles.github.io/helm/charts/$APP_NAME
|
||||
shell: bash
|
||||
|
||||
- name: Commit and push to target repo
|
||||
run: |
|
||||
cd target-repo
|
||||
git add charts/
|
||||
git commit -m "Update $APP_NAME chart $(date +'%Y-%m-%d %H:%M:%S')" || echo "No changes"
|
||||
git push https://x-access-token:${{ inputs.app-repo-token }}@github.com/jaypyles/helm.git gh-pages
|
||||
shell: bash
|
||||
13
.github/actions/run-cypress-tests/action.yaml
vendored
13
.github/actions/run-cypress-tests/action.yaml
vendored
@@ -2,6 +2,13 @@ name: Run Cypress Tests
|
||||
|
||||
description: Run Cypress tests
|
||||
|
||||
inputs:
|
||||
openai_key:
|
||||
description: "OpenAI API key"
|
||||
required: true
|
||||
default: ""
|
||||
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
@@ -15,11 +22,13 @@ runs:
|
||||
|
||||
- name: Setup Docker project
|
||||
shell: bash
|
||||
run: make build up-dev
|
||||
env:
|
||||
OPENAI_KEY: ${{ inputs.openai_key }}
|
||||
run: make build-ci up-ci
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: npm install
|
||||
run: yarn install
|
||||
|
||||
- name: Wait for frontend to be ready
|
||||
shell: bash
|
||||
|
||||
32
.github/workflows/docker-image.yml
vendored
32
.github/workflows/docker-image.yml
vendored
@@ -1,19 +1,20 @@
|
||||
name: Docker Image
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Unit Tests"]
|
||||
types:
|
||||
- completed
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'master' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Get version from helm chart
|
||||
run: |
|
||||
VERSION=$(grep "version:" ./helm/Chart.yaml | cut -d: -f2 | tr -d ' ')
|
||||
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
||||
echo "Version is $VERSION"
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
@@ -29,7 +30,9 @@ jobs:
|
||||
context: .
|
||||
file: ./docker/frontend/Dockerfile
|
||||
push: true
|
||||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }}:latest
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/scraperr:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/scraperr:${{ env.VERSION }}
|
||||
|
||||
- name: Build and push api
|
||||
uses: docker/build-push-action@v5
|
||||
@@ -37,12 +40,27 @@ jobs:
|
||||
context: .
|
||||
file: ./docker/api/Dockerfile
|
||||
push: true
|
||||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/scraperr_api:latest
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/scraperr_api:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/scraperr_api:${{ env.VERSION }}
|
||||
|
||||
push-helm-chart:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Push Helm Chart
|
||||
uses: ./.github/actions/push-to-helm
|
||||
with:
|
||||
app-repo-token: ${{ secrets.GPAT_TOKEN }}
|
||||
|
||||
success-message:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build
|
||||
- push-helm-chart
|
||||
steps:
|
||||
- name: Send Discord Message
|
||||
uses: jaypyles/discord-webhook-action@v1.0.0
|
||||
|
||||
7
.github/workflows/unit-tests.yml
vendored
7
.github/workflows/unit-tests.yml
vendored
@@ -26,14 +26,19 @@ jobs:
|
||||
- name: Install project dependencies
|
||||
run: pdm install
|
||||
|
||||
- name: Install playwright
|
||||
run: pdm run playwright install
|
||||
|
||||
- name: Run tests
|
||||
run: PYTHONPATH=. pdm run pytest api/backend/tests
|
||||
run: PYTHONPATH=. pdm run pytest -v -ra api/backend/tests
|
||||
|
||||
cypress-tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./.github/actions/run-cypress-tests
|
||||
with:
|
||||
openai_key: ${{ secrets.OPENAI_KEY }}
|
||||
|
||||
success-message:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
16
.gitignore
vendored
16
.gitignore
vendored
@@ -188,4 +188,18 @@ postgres_data
|
||||
.vscode
|
||||
ollama
|
||||
data
|
||||
media
|
||||
|
||||
media/images
|
||||
media/videos
|
||||
media/audio
|
||||
media/pdfs
|
||||
media/spreadsheets
|
||||
media/presentations
|
||||
media/documents
|
||||
media/recordings
|
||||
media/download_summary.txt
|
||||
|
||||
cypress/screenshots
|
||||
cypress/videos
|
||||
|
||||
docker-compose.dev.local.yml
|
||||
2
.prettierignore
Normal file
2
.prettierignore
Normal file
@@ -0,0 +1,2 @@
|
||||
*.yaml
|
||||
*.yml
|
||||
1
FUNDING.yml
Normal file
1
FUNDING.yml
Normal file
@@ -0,0 +1 @@
|
||||
custom: ["https://www.buymeacoffee.com/jaypyles"]
|
||||
15
Makefile
15
Makefile
@@ -1,6 +1,6 @@
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
COMPOSE_DEV = docker compose -f docker-compose.yml -f docker-compose.dev.yml
|
||||
COMPOSE_DEV = docker compose -f docker-compose.yml -f docker-compose.dev.local.yml
|
||||
COMPOSE_PROD = docker compose -f docker-compose.yml
|
||||
|
||||
.PHONY: help deps build pull up up-dev down setup deploy
|
||||
@@ -17,6 +17,7 @@ help:
|
||||
@echo " make down - Stop and remove containers, networks, images, and volumes"
|
||||
@echo " make setup - Setup server with dependencies and clone repo"
|
||||
@echo " make deploy - Deploy site onto server"
|
||||
@echo " make cypress-start - Start Cypress"
|
||||
@echo ""
|
||||
|
||||
logs:
|
||||
@@ -51,3 +52,15 @@ setup:
|
||||
|
||||
deploy:
|
||||
ansible-playbook -i ./ansible/inventory.yaml ./ansible/deploy_site.yaml -v
|
||||
|
||||
build-ci:
|
||||
docker compose -f docker-compose.yml -f docker-compose.dev.yml build
|
||||
|
||||
up-ci:
|
||||
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --force-recreate
|
||||
|
||||
cypress-start:
|
||||
DISPLAY=:0 npx cypress open
|
||||
|
||||
cypress-run:
|
||||
npx cypress run
|
||||
129
README.md
129
README.md
@@ -1,104 +1,71 @@
|
||||

|
||||
|
||||
<div align="center">
|
||||
<img src="https://img.shields.io/badge/MongoDB-%234ea94b.svg?style=for-the-badge&logo=mongodb&logoColor=white" alt="MongoDB" />
|
||||
<img src="https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi" alt="FastAPI" />
|
||||
<img src="https://img.shields.io/badge/Next-black?style=for-the-badge&logo=next.js&logoColor=white" alt="Next JS" />
|
||||
<img src="https://img.shields.io/badge/tailwindcss-%2338B2AC.svg?style=for-the-badge&logo=tailwind-css&logoColor=white" alt="TailwindCSS" />
|
||||
<img src="https://github.com/jaypyles/www-scrape/blob/master/docs/logo_picture.png" alt="Scraperr Logo" width="250px">
|
||||
|
||||
**A powerful self-hosted web scraping solution**
|
||||
|
||||
<div>
|
||||
<img src="https://img.shields.io/badge/MongoDB-%234ea94b.svg?style=for-the-badge&logo=mongodb&logoColor=white" alt="MongoDB" />
|
||||
<img src="https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi" alt="FastAPI" />
|
||||
<img src="https://img.shields.io/badge/Next-black?style=for-the-badge&logo=next.js&logoColor=white" alt="Next JS" />
|
||||
<img src="https://img.shields.io/badge/tailwindcss-%2338B2AC.svg?style=for-the-badge&logo=tailwind-css&logoColor=white" alt="TailwindCSS" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
# Summary
|
||||
## 📋 Overview
|
||||
|
||||
Scraperr is a self-hosted web application that allows users to scrape data from web pages by specifying elements via XPath. Users can submit URLs and the corresponding elements to be scraped, and the results will be displayed in a table.
|
||||
Scrape websites without writing a single line of code.
|
||||
|
||||
From the table, users can download an excel sheet of the job's results, along with an option to rerun the job.
|
||||
> 📚 **[Check out the docs](https://scraperr-docs.pages.dev)** for a comprehensive quickstart guide and detailed information.
|
||||
|
||||
View the [docs](https://scraperr-docs.pages.dev) for a quickstart guide and more information.
|
||||
<div align="center">
|
||||
<img src="https://github.com/jaypyles/www-scrape/blob/master/docs/main_page.png" alt="Scraperr Main Interface" width="800px">
|
||||
</div>
|
||||
|
||||
## Features
|
||||
## ✨ Key Features
|
||||
|
||||
### Submitting URLs for Scraping
|
||||
- **XPath-Based Extraction**: Precisely target page elements
|
||||
- **Queue Management**: Submit and manage multiple scraping jobs
|
||||
- **Domain Spidering**: Option to scrape all pages within the same domain
|
||||
- **Custom Headers**: Add JSON headers to your scraping requests
|
||||
- **Media Downloads**: Automatically download images, videos, and other media
|
||||
- **Results Visualization**: View scraped data in a structured table format
|
||||
- **Data Export**: Export your results in markdown and csv formats
|
||||
- **Notifcation Channels**: Send completion notifcations, through various channels
|
||||
|
||||
- Submit/Queue URLs for web scraping
|
||||
- Add and manage elements to scrape using XPath
|
||||
- Scrape all pages within same domain
|
||||
- Add custom json headers to send in requests to URLs
|
||||
- Display results of scraped data
|
||||
- Download media found on the page (images, videos, etc.)
|
||||
## 🚀 Getting Started
|
||||
|
||||

|
||||
### Docker
|
||||
|
||||
### Managing Previous Jobs
|
||||
|
||||
- Download csv containing results
|
||||
- Rerun jobs
|
||||
- View status of queued jobs
|
||||
- Favorite and view favorited jobs
|
||||
|
||||

|
||||
|
||||
### User Management
|
||||
|
||||
- User login/signup to organize jobs (optional)
|
||||
|
||||

|
||||
|
||||
### Log Viewing
|
||||
|
||||
- View app logs inside of web ui
|
||||
|
||||

|
||||
|
||||
### Statistics View
|
||||
|
||||
- View a small statistics view of jobs ran
|
||||
|
||||

|
||||
|
||||
### AI Integration
|
||||
|
||||
- Include the results of a selected job into the context of a conversation
|
||||
- Currently supports:
|
||||
|
||||
1. Ollama
|
||||
2. OpenAI
|
||||
|
||||

|
||||
|
||||
## API Endpoints
|
||||
|
||||
Use this service as an API for your own projects. Due to this using FastAPI, a docs page is available at `/docs` for the API.
|
||||
|
||||

|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Q: When running Scraperr, I'm met with "404 Page not found".
|
||||
A: This is probably an issue with MongoDB related to running Scraperr in a VM. You should see something liks this in `make logs`:
|
||||
|
||||
```
|
||||
WARNING: MongoDB 5.0+ requires a CPU with AVX support, and your current system does not appear to have that!
|
||||
```bash
|
||||
make up
|
||||
```
|
||||
|
||||
To resolve this issue, simply set CPU host type to `host`. This can be done in Proxmox in the VM settings > Processor. [Related issue](https://github.com/jaypyles/Scraperr/issues/9).
|
||||
### Helm
|
||||
|
||||
## Legal and Ethical Considerations
|
||||
> Refer to the docs for helm deployment: https://scraperr-docs.pages.dev/guides/helm-deployment
|
||||
|
||||
When using Scraperr, please ensure that you:
|
||||
## ⚖️ Legal and Ethical Guidelines
|
||||
|
||||
1. **Check Robots.txt**: Verify allowed pages by reviewing the `robots.txt` file of the target website.
|
||||
2. **Compliance**: Always comply with the website's Terms of Service (ToS) regarding web scraping.
|
||||
When using Scraperr, please remember to:
|
||||
|
||||
**Disclaimer**: This tool is intended for use only on websites that permit scraping. The author is not responsible for any misuse of this tool.
|
||||
1. **Respect `robots.txt`**: Always check a website's `robots.txt` file to verify which pages permit scraping
|
||||
2. **Terms of Service**: Adhere to each website's Terms of Service regarding data extraction
|
||||
3. **Rate Limiting**: Implement reasonable delays between requests to avoid overloading servers
|
||||
|
||||
## License
|
||||
> **Disclaimer**: Scraperr is intended for use only on websites that explicitly permit scraping. The creator accepts no responsibility for misuse of this tool.
|
||||
|
||||
## 💬 Join the Community
|
||||
|
||||
Get support, report bugs, and chat with other users and contributors.
|
||||
|
||||
👉 [Join the Scraperr Discord](https://discord.gg/89q7scsGEK)
|
||||
|
||||
## 📄 License
|
||||
|
||||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
||||
|
||||
### Contributions
|
||||
## 👏 Contributions
|
||||
|
||||
Development made easy by developing from [webapp template](https://github.com/jaypyles/webapp-template). View documentation for extra information.
|
||||
Development made easier with the [webapp template](https://github.com/jaypyles/webapp-template).
|
||||
|
||||
Start development server:
|
||||
|
||||
`make deps build up-dev`
|
||||
To get started, simply run `make build up-dev`.
|
||||
6
api/backend/ai/agent/actions.py
Normal file
6
api/backend/ai/agent/actions.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class Action(TypedDict):
|
||||
type: str
|
||||
url: str
|
||||
91
api/backend/ai/agent/agent.py
Normal file
91
api/backend/ai/agent/agent.py
Normal file
@@ -0,0 +1,91 @@
|
||||
# STL
|
||||
import random
|
||||
from typing import Any
|
||||
|
||||
# PDM
|
||||
from camoufox import AsyncCamoufox
|
||||
from playwright.async_api import Page
|
||||
|
||||
# LOCAL
|
||||
from api.backend.ai.clients import ask_ollama, ask_open_ai, open_ai_key
|
||||
from api.backend.job.models import CapturedElement
|
||||
from api.backend.worker.logger import LOG
|
||||
from api.backend.ai.agent.utils import (
|
||||
parse_response,
|
||||
capture_elements,
|
||||
convert_to_markdown,
|
||||
)
|
||||
from api.backend.ai.agent.prompts import (
|
||||
EXTRACT_ELEMENTS_PROMPT,
|
||||
ELEMENT_EXTRACTION_PROMPT,
|
||||
)
|
||||
from api.backend.job.scraping.add_custom import add_custom_items
|
||||
from api.backend.job.scraping.collect_media import collect_media
|
||||
|
||||
ask_ai = ask_open_ai if open_ai_key else ask_ollama
|
||||
|
||||
|
||||
async def scrape_with_agent(agent_job: dict[str, Any]):
|
||||
LOG.info(f"Starting work for agent job: {agent_job}")
|
||||
pages = set()
|
||||
|
||||
if agent_job["job_options"]["proxies"]:
|
||||
proxy = random.choice(agent_job["job_options"]["proxies"])
|
||||
LOG.info(f"Using proxy: {proxy}")
|
||||
|
||||
async with AsyncCamoufox(headless=True) as browser:
|
||||
page: Page = await browser.new_page()
|
||||
|
||||
await add_custom_items(
|
||||
agent_job["url"],
|
||||
page,
|
||||
agent_job["job_options"]["custom_cookies"],
|
||||
agent_job["job_options"]["custom_headers"],
|
||||
)
|
||||
|
||||
try:
|
||||
await page.set_viewport_size({"width": 1920, "height": 1080})
|
||||
await page.goto(agent_job["url"], timeout=60000)
|
||||
|
||||
if agent_job["job_options"]["collect_media"]:
|
||||
await collect_media(agent_job["id"], page)
|
||||
|
||||
html_content = await page.content()
|
||||
markdown_content = convert_to_markdown(html_content)
|
||||
|
||||
response = await ask_ai(
|
||||
ELEMENT_EXTRACTION_PROMPT.format(
|
||||
extraction_prompt=EXTRACT_ELEMENTS_PROMPT,
|
||||
webpage=markdown_content,
|
||||
prompt=agent_job["prompt"],
|
||||
)
|
||||
)
|
||||
|
||||
xpaths = parse_response(response)
|
||||
|
||||
captured_elements = await capture_elements(page, xpaths)
|
||||
|
||||
final_url = page.url
|
||||
|
||||
pages.add((html_content, final_url))
|
||||
finally:
|
||||
await page.close()
|
||||
await browser.close()
|
||||
|
||||
name_to_elements = {}
|
||||
|
||||
for page in pages:
|
||||
for element in captured_elements:
|
||||
if element.name not in name_to_elements:
|
||||
name_to_elements[element.name] = []
|
||||
|
||||
name_to_elements[element.name].append(element)
|
||||
|
||||
scraped_elements: list[dict[str, dict[str, list[CapturedElement]]]] = [
|
||||
{
|
||||
page[1]: name_to_elements,
|
||||
}
|
||||
for page in pages
|
||||
]
|
||||
|
||||
return scraped_elements
|
||||
58
api/backend/ai/agent/prompts.py
Normal file
58
api/backend/ai/agent/prompts.py
Normal file
@@ -0,0 +1,58 @@
|
||||
EXTRACT_ELEMENTS_PROMPT = """
|
||||
You are an assistant that extracts XPath expressions from webpages.
|
||||
|
||||
You will receive HTML content in markdown format.
|
||||
|
||||
Each element in the markdown has their xpath shown above them in a path like:
|
||||
<!-- //div -->
|
||||
|
||||
Respond only with a list of general XPath expressions inside `<xpaths>...</xpaths>` tags.
|
||||
|
||||
You will also decide the decision of what to do next. If there is no decision available, return nothing for that section.
|
||||
"""
|
||||
|
||||
ELEMENT_EXTRACTION_PROMPT = """
|
||||
{extraction_prompt}
|
||||
|
||||
**Guidelines:**
|
||||
- Prefer shorter, more general XPaths like `//div[...]` or `//span[...]`.
|
||||
- Avoid overly specific or deep paths like `//div[3]/ul/li[2]/a`.
|
||||
- Do **not** chain multiple elements deeply (e.g., `//div/span/a`).
|
||||
- Use XPaths further down the tree when possible.
|
||||
- Do not include any extra explanation or text.
|
||||
- One XPath is acceptable if that's all that's needed.
|
||||
- Try and limit it down to 1 - 3 xpaths.
|
||||
- Include a name for each xpath.
|
||||
|
||||
<important>
|
||||
- USE THE MOST SIMPLE XPATHS POSSIBLE.
|
||||
- USE THE MOST GENERAL XPATHS POSSIBLE.
|
||||
- USE THE MOST SPECIFIC XPATHS POSSIBLE.
|
||||
- USE THE MOST GENERAL XPATHS POSSIBLE.
|
||||
</important>
|
||||
|
||||
**Example Format:**
|
||||
```xml
|
||||
<xpaths>
|
||||
- <name: insert_name_here>: <xpath: //div>
|
||||
- <name: insert_name_here>: <xpath: //span>
|
||||
- <name: insert_name_here>: <xpath: //span[contains(@text, 'example')]>
|
||||
- <name: insert_name_here>: <xpath: //div[contains(@text, 'example')]>
|
||||
- <name: insert_name_here>: <xpath: //a[@href]>
|
||||
- etc
|
||||
</xpaths>
|
||||
|
||||
<decision>
|
||||
<next_page>
|
||||
- //a[@href='next_page_url']
|
||||
</next_page>
|
||||
</decision>
|
||||
```
|
||||
|
||||
**Input webpage:**
|
||||
{webpage}
|
||||
|
||||
**Target content:**
|
||||
{prompt}
|
||||
|
||||
"""
|
||||
255
api/backend/ai/agent/utils.py
Normal file
255
api/backend/ai/agent/utils.py
Normal file
@@ -0,0 +1,255 @@
|
||||
# STL
|
||||
import re
|
||||
|
||||
# PDM
|
||||
from lxml import html, etree
|
||||
from playwright.async_api import Page
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job.models import CapturedElement
|
||||
from api.backend.job.utils.text_utils import clean_text
|
||||
|
||||
|
||||
def convert_to_markdown(html_str: str):
|
||||
parser = html.HTMLParser()
|
||||
tree = html.fromstring(html_str, parser=parser)
|
||||
root = tree.getroottree()
|
||||
|
||||
def format_attributes(el: etree._Element) -> str:
|
||||
"""Convert element attributes into a string."""
|
||||
return " ".join(f'{k}="{v}"' for k, v in el.attrib.items())
|
||||
|
||||
def is_visible(el: etree._Element) -> bool:
|
||||
style = el.attrib.get("style", "").lower()
|
||||
class_ = el.attrib.get("class", "").lower()
|
||||
|
||||
# Check for visibility styles
|
||||
if "display: none" in style or "visibility: hidden" in style:
|
||||
return False
|
||||
if "opacity: 0" in style or "opacity:0" in style:
|
||||
return False
|
||||
if "height: 0" in style or "width: 0" in style:
|
||||
return False
|
||||
|
||||
# Check for common hidden classes
|
||||
if any(
|
||||
hidden in class_
|
||||
for hidden in ["hidden", "invisible", "truncate", "collapse"]
|
||||
):
|
||||
return False
|
||||
|
||||
# Check for hidden attributes
|
||||
if el.attrib.get("hidden") is not None:
|
||||
return False
|
||||
if el.attrib.get("aria-hidden") == "true":
|
||||
return False
|
||||
|
||||
# Check for empty or whitespace-only content
|
||||
if not el.text and len(el) == 0:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def is_layout_or_decorative(el: etree._Element) -> bool:
|
||||
tag = el.tag.lower()
|
||||
|
||||
# Layout elements
|
||||
if tag in {"nav", "footer", "header", "aside", "main", "section"}:
|
||||
return True
|
||||
|
||||
# Decorative elements
|
||||
if tag in {"svg", "path", "circle", "rect", "line", "polygon", "polyline"}:
|
||||
return True
|
||||
|
||||
# Check id and class for layout/decorative keywords
|
||||
id_class = " ".join(
|
||||
[el.attrib.get("id", ""), el.attrib.get("class", "")]
|
||||
).lower()
|
||||
|
||||
layout_keywords = {
|
||||
"sidebar",
|
||||
"nav",
|
||||
"header",
|
||||
"footer",
|
||||
"menu",
|
||||
"advert",
|
||||
"ads",
|
||||
"breadcrumb",
|
||||
"container",
|
||||
"wrapper",
|
||||
"layout",
|
||||
"grid",
|
||||
"flex",
|
||||
"row",
|
||||
"column",
|
||||
"section",
|
||||
"banner",
|
||||
"hero",
|
||||
"card",
|
||||
"modal",
|
||||
"popup",
|
||||
"tooltip",
|
||||
"dropdown",
|
||||
"overlay",
|
||||
}
|
||||
|
||||
return any(keyword in id_class for keyword in layout_keywords)
|
||||
|
||||
# Tags to ignore in the final markdown output
|
||||
included_tags = {
|
||||
"div",
|
||||
"span",
|
||||
"a",
|
||||
"p",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"img",
|
||||
"button",
|
||||
"input",
|
||||
"textarea",
|
||||
"ul",
|
||||
"ol",
|
||||
"li",
|
||||
"table",
|
||||
"tr",
|
||||
"td",
|
||||
"th",
|
||||
"input",
|
||||
"textarea",
|
||||
"select",
|
||||
"option",
|
||||
"optgroup",
|
||||
"fieldset",
|
||||
"legend",
|
||||
}
|
||||
|
||||
special_elements = []
|
||||
normal_elements = []
|
||||
|
||||
for el in tree.iter():
|
||||
if el.tag is etree.Comment:
|
||||
continue
|
||||
|
||||
tag = el.tag.lower()
|
||||
|
||||
if tag not in included_tags:
|
||||
continue
|
||||
|
||||
if not is_visible(el):
|
||||
continue
|
||||
|
||||
if is_layout_or_decorative(el):
|
||||
continue
|
||||
|
||||
path = root.getpath(el)
|
||||
attrs = format_attributes(el)
|
||||
attrs_str = f" {attrs}" if attrs else ""
|
||||
text = el.text.strip() if el.text else ""
|
||||
|
||||
if not text and not attrs:
|
||||
continue
|
||||
|
||||
# input elements
|
||||
if tag == "button":
|
||||
prefix = "🔘 **<button>**"
|
||||
special_elements.append(f"<!-- {path} -->\n{prefix} {text}")
|
||||
elif tag == "a":
|
||||
href = el.attrib.get("href", "")
|
||||
prefix = f"🔗 **<a href='{href}'>**"
|
||||
special_elements.append(f"<!-- {path} -->\n{prefix} {text}")
|
||||
elif tag == "input":
|
||||
input_type = el.attrib.get("type", "text")
|
||||
prefix = f"📝 **<input type='{input_type}'>**"
|
||||
special_elements.append(f"<!-- {path} -->\n{prefix}")
|
||||
else:
|
||||
prefix = f"**<{tag}{attrs_str}>**"
|
||||
|
||||
if text:
|
||||
normal_elements.append(f"<!-- {path} -->\n{prefix} {text}")
|
||||
|
||||
return "\n\n".join(normal_elements + special_elements) # type: ignore
|
||||
|
||||
|
||||
def parse_response(text: str) -> list[dict[str, str]]:
|
||||
xpaths = re.findall(r"<xpaths>(.*?)</xpaths>", text, re.DOTALL)
|
||||
results = []
|
||||
|
||||
if xpaths:
|
||||
lines = xpaths[0].strip().splitlines()
|
||||
for line in lines:
|
||||
if line.strip().startswith("-"):
|
||||
name = re.findall(r"<name: (.*?)>", line)[0]
|
||||
xpath = re.findall(r"<xpath: (.*?)>", line)[0]
|
||||
results.append({"name": name, "xpath": xpath})
|
||||
else:
|
||||
results.append({"name": "", "xpath": line.strip()})
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def parse_next_page(text: str) -> str | None:
|
||||
next_page = re.findall(r"<next_page>(.*?)</next_page>", text, re.DOTALL)
|
||||
|
||||
if next_page:
|
||||
lines = next_page[0].strip().splitlines()
|
||||
next_page = [
|
||||
line.strip().lstrip("-").strip()
|
||||
for line in lines
|
||||
if line.strip().startswith("-")
|
||||
]
|
||||
|
||||
return next_page[0] if next_page else None
|
||||
|
||||
|
||||
async def capture_elements(
|
||||
page: Page, xpaths: list[dict[str, str]]
|
||||
) -> list[CapturedElement]:
|
||||
captured_elements = []
|
||||
seen_texts = set()
|
||||
|
||||
for xpath in xpaths:
|
||||
try:
|
||||
locator = page.locator(f"xpath={xpath['xpath']}")
|
||||
count = await locator.count()
|
||||
|
||||
for i in range(count):
|
||||
element_text = ""
|
||||
|
||||
element_handle = await locator.nth(i).element_handle()
|
||||
|
||||
if not element_handle:
|
||||
continue
|
||||
|
||||
link = await element_handle.get_attribute("href") or ""
|
||||
|
||||
text = await element_handle.text_content()
|
||||
|
||||
if text:
|
||||
element_text += text
|
||||
|
||||
if link:
|
||||
element_text += f" ({link})"
|
||||
|
||||
cleaned = clean_text(element_text)
|
||||
|
||||
if cleaned in seen_texts:
|
||||
continue
|
||||
|
||||
seen_texts.add(cleaned)
|
||||
|
||||
captured_elements.append(
|
||||
CapturedElement(
|
||||
name=xpath["name"],
|
||||
text=cleaned,
|
||||
xpath=xpath["xpath"],
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error processing xpath {xpath}: {e}")
|
||||
|
||||
return captured_elements
|
||||
@@ -1,32 +1,28 @@
|
||||
# STL
|
||||
import os
|
||||
import logging
|
||||
from collections.abc import Iterable, AsyncGenerator
|
||||
|
||||
# PDM
|
||||
from openai import OpenAI
|
||||
from ollama import Message
|
||||
from fastapi import APIRouter
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from openai.types.chat import ChatCompletionMessageParam
|
||||
|
||||
# LOCAL
|
||||
from ollama import Message, AsyncClient
|
||||
from api.backend.models import AI
|
||||
from api.backend.ai.clients import (
|
||||
llama_model,
|
||||
open_ai_key,
|
||||
llama_client,
|
||||
open_ai_model,
|
||||
openai_client,
|
||||
)
|
||||
from api.backend.ai.schemas import AI
|
||||
from api.backend.routers.handle_exceptions import handle_exceptions
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = logging.getLogger("AI")
|
||||
|
||||
ai_router = APIRouter()
|
||||
|
||||
# Load environment variables
|
||||
open_ai_key = os.getenv("OPENAI_KEY")
|
||||
open_ai_model = os.getenv("OPENAI_MODEL")
|
||||
llama_url = os.getenv("OLLAMA_URL")
|
||||
llama_model = os.getenv("OLLAMA_MODEL")
|
||||
|
||||
# Initialize clients
|
||||
openai_client = OpenAI(api_key=open_ai_key) if open_ai_key else None
|
||||
llama_client = AsyncClient(host=llama_url) if llama_url else None
|
||||
|
||||
|
||||
async def llama_chat(chat_messages: list[Message]) -> AsyncGenerator[str, None]:
|
||||
if llama_client and llama_model:
|
||||
@@ -43,6 +39,14 @@ async def llama_chat(chat_messages: list[Message]) -> AsyncGenerator[str, None]:
|
||||
async def openai_chat(
|
||||
chat_messages: Iterable[ChatCompletionMessageParam],
|
||||
) -> AsyncGenerator[str, None]:
|
||||
if openai_client and not open_ai_model:
|
||||
LOG.error("OpenAI model is not set")
|
||||
yield "An error occurred while processing your request."
|
||||
|
||||
if not openai_client:
|
||||
LOG.error("OpenAI client is not set")
|
||||
yield "An error occurred while processing your request."
|
||||
|
||||
if openai_client and open_ai_model:
|
||||
try:
|
||||
response = openai_client.chat.completions.create(
|
||||
@@ -59,6 +63,7 @@ chat_function = llama_chat if llama_client else openai_chat
|
||||
|
||||
|
||||
@ai_router.post("/ai")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def ai(c: AI):
|
||||
return StreamingResponse(
|
||||
chat_function(chat_messages=c.messages), media_type="text/plain"
|
||||
@@ -66,5 +71,6 @@ async def ai(c: AI):
|
||||
|
||||
|
||||
@ai_router.get("/ai/check")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def check():
|
||||
return JSONResponse(content={"ai_enabled": bool(open_ai_key or llama_model)})
|
||||
|
||||
39
api/backend/ai/clients.py
Normal file
39
api/backend/ai/clients.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# STL
|
||||
import os
|
||||
|
||||
# PDM
|
||||
from ollama import AsyncClient
|
||||
from openai import OpenAI
|
||||
|
||||
# Load environment variables
|
||||
open_ai_key = os.getenv("OPENAI_KEY")
|
||||
open_ai_model = os.getenv("OPENAI_MODEL")
|
||||
llama_url = os.getenv("OLLAMA_URL")
|
||||
llama_model = os.getenv("OLLAMA_MODEL")
|
||||
|
||||
# Initialize clients
|
||||
openai_client = OpenAI(api_key=open_ai_key) if open_ai_key else None
|
||||
llama_client = AsyncClient(host=llama_url) if llama_url else None
|
||||
|
||||
|
||||
async def ask_open_ai(prompt: str) -> str:
|
||||
if not openai_client:
|
||||
raise ValueError("OpenAI client not initialized")
|
||||
|
||||
response = openai_client.chat.completions.create(
|
||||
model=open_ai_model or "gpt-4.1-mini",
|
||||
messages=[{"role": "user", "content": prompt}],
|
||||
)
|
||||
|
||||
return response.choices[0].message.content or ""
|
||||
|
||||
|
||||
async def ask_ollama(prompt: str) -> str:
|
||||
if not llama_client:
|
||||
raise ValueError("Ollama client not initialized")
|
||||
|
||||
response = await llama_client.chat(
|
||||
model=llama_model or "", messages=[{"role": "user", "content": prompt}]
|
||||
)
|
||||
|
||||
return response.message.content or ""
|
||||
4
api/backend/ai/schemas/__init__.py
Normal file
4
api/backend/ai/schemas/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# LOCAL
|
||||
from .ai import AI
|
||||
|
||||
__all__ = ["AI"]
|
||||
9
api/backend/ai/schemas/ai.py
Normal file
9
api/backend/ai/schemas/ai.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# STL
|
||||
from typing import Any
|
||||
|
||||
# PDM
|
||||
import pydantic
|
||||
|
||||
|
||||
class AI(pydantic.BaseModel):
|
||||
messages: list[Any]
|
||||
@@ -1,40 +1,60 @@
|
||||
# STL
|
||||
import os
|
||||
import logging
|
||||
import apscheduler # type: ignore
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
# PDM
|
||||
import apscheduler.schedulers
|
||||
import apscheduler.schedulers.background
|
||||
from fastapi import FastAPI, Request, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
# LOCAL
|
||||
from api.backend.ai.ai_router import ai_router
|
||||
from api.backend.auth.auth_router import auth_router
|
||||
from api.backend.utils import get_log_level
|
||||
from api.backend.routers.job_router import job_router
|
||||
from api.backend.routers.log_router import log_router
|
||||
from api.backend.routers.stats_router import stats_router
|
||||
from api.backend.database.startup import init_database
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from api.backend.job.cron_scheduling.cron_scheduling import start_cron_scheduler
|
||||
from api.backend.scheduler import scheduler
|
||||
from api.backend.ai.ai_router import ai_router
|
||||
from api.backend.job.job_router import job_router
|
||||
from api.backend.auth.auth_router import auth_router
|
||||
from api.backend.database.startup import init_database
|
||||
from api.backend.stats.stats_router import stats_router
|
||||
from api.backend.job.cron_scheduling.cron_scheduling import start_cron_scheduler
|
||||
|
||||
log_level = os.getenv("LOG_LEVEL")
|
||||
LOG_LEVEL = get_log_level(log_level)
|
||||
|
||||
logging.basicConfig(
|
||||
level=LOG_LEVEL,
|
||||
format="%(levelname)s: %(asctime)s - %(name)s - %(message)s",
|
||||
format="%(levelname)s: %(asctime)s - [%(name)s] - %(message)s",
|
||||
handlers=[logging.StreamHandler()],
|
||||
)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
app = FastAPI(title="api", root_path="/api")
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI):
|
||||
# Startup
|
||||
LOG.info("Starting application...")
|
||||
|
||||
init_database()
|
||||
|
||||
LOG.info("Starting cron scheduler...")
|
||||
start_cron_scheduler(scheduler)
|
||||
scheduler.start()
|
||||
|
||||
LOG.info("Cron scheduler started successfully")
|
||||
|
||||
yield
|
||||
|
||||
# Shutdown
|
||||
LOG.info("Shutting down application...")
|
||||
LOG.info("Stopping cron scheduler...")
|
||||
scheduler.shutdown(wait=False) # Set wait=False to not block shutdown
|
||||
LOG.info("Cron scheduler stopped")
|
||||
LOG.info("Application shutdown complete")
|
||||
|
||||
|
||||
app = FastAPI(title="api", root_path="/api", lifespan=lifespan)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
@@ -44,29 +64,12 @@ app.add_middleware(
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
app.include_router(auth_router)
|
||||
app.include_router(ai_router)
|
||||
app.include_router(job_router)
|
||||
app.include_router(log_router)
|
||||
app.include_router(stats_router)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
start_cron_scheduler(scheduler)
|
||||
scheduler.start()
|
||||
|
||||
if os.getenv("ENV") != "test":
|
||||
init_database()
|
||||
LOG.info("Starting up...")
|
||||
|
||||
|
||||
@app.on_event("shutdown")
|
||||
def shutdown_scheduler():
|
||||
scheduler.shutdown(wait=False) # Set wait=False to not block shutdown
|
||||
|
||||
|
||||
@app.exception_handler(RequestValidationError)
|
||||
async def validation_exception_handler(request: Request, exc: RequestValidationError):
|
||||
exc_str = f"{exc}".replace("\n", " ").replace(" ", " ")
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
# STL
|
||||
from datetime import timedelta
|
||||
import os
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
# PDM
|
||||
from fastapi import Depends, APIRouter, HTTPException, status
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
|
||||
# LOCAL
|
||||
from api.backend.schemas import User, Token, UserCreate
|
||||
from api.backend.auth.schemas import User, Token, UserCreate
|
||||
from api.backend.auth.auth_utils import (
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES,
|
||||
get_current_user,
|
||||
@@ -15,18 +16,19 @@ from api.backend.auth.auth_utils import (
|
||||
get_password_hash,
|
||||
create_access_token,
|
||||
)
|
||||
import logging
|
||||
|
||||
from api.backend.database.common import update
|
||||
from api.backend.routers.handle_exceptions import handle_exceptions
|
||||
|
||||
auth_router = APIRouter()
|
||||
|
||||
LOG = logging.getLogger("auth_router")
|
||||
LOG = logging.getLogger("Auth")
|
||||
|
||||
|
||||
@auth_router.post("/auth/token", response_model=Token)
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
|
||||
user = await authenticate_user(form_data.username, form_data.password)
|
||||
|
||||
if not user:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
@@ -47,6 +49,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
|
||||
|
||||
|
||||
@auth_router.post("/auth/signup", response_model=User)
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def create_user(user: UserCreate):
|
||||
hashed_password = get_password_hash(user.password)
|
||||
user_dict = user.model_dump()
|
||||
@@ -60,10 +63,16 @@ async def create_user(user: UserCreate):
|
||||
|
||||
|
||||
@auth_router.get("/auth/users/me", response_model=User)
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def read_users_me(current_user: User = Depends(get_current_user)):
|
||||
return current_user
|
||||
|
||||
|
||||
@auth_router.get("/auth/check")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def check_auth():
|
||||
return {"registration": os.environ.get("REGISTRATION_ENABLED", "True") == "True"}
|
||||
return {
|
||||
"registration": os.environ.get("REGISTRATION_ENABLED", "True") == "True",
|
||||
"recordings_enabled": os.environ.get("RECORDINGS_ENABLED", "true").lower()
|
||||
== "true",
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# STL
|
||||
import os
|
||||
import logging
|
||||
from typing import Any, Optional
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
|
||||
# PDM
|
||||
from jose import JWTError, jwt
|
||||
@@ -12,17 +12,16 @@ from passlib.context import CryptContext
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
|
||||
# LOCAL
|
||||
from api.backend.schemas import User, UserInDB, TokenData
|
||||
|
||||
from api.backend.auth.schemas import User, UserInDB, TokenData
|
||||
from api.backend.database.common import query
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = logging.getLogger("Auth")
|
||||
|
||||
_ = load_dotenv()
|
||||
|
||||
SECRET_KEY = os.getenv("SECRET_KEY") or ""
|
||||
ALGORITHM = os.getenv("ALGORITHM") or ""
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES = os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES")
|
||||
SECRET_KEY = os.getenv("SECRET_KEY") or "secret"
|
||||
ALGORITHM = os.getenv("ALGORITHM") or "HS256"
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES = os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES") or 600
|
||||
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="auth/token")
|
||||
@@ -118,7 +117,8 @@ async def get_current_user(token: str = Depends(oauth2_scheme)):
|
||||
LOG.error(f"Exception occurred: {e}")
|
||||
return EMPTY_USER
|
||||
|
||||
user = await get_user(email=token_data.email)
|
||||
user = await get_user(email=token_data.email or "")
|
||||
|
||||
if user is None:
|
||||
return EMPTY_USER
|
||||
|
||||
@@ -136,6 +136,7 @@ async def require_user(token: str = Depends(oauth2_scheme)):
|
||||
payload: Optional[dict[str, Any]] = jwt.decode(
|
||||
token, SECRET_KEY, algorithms=[ALGORITHM]
|
||||
)
|
||||
|
||||
if not payload:
|
||||
raise credentials_exception
|
||||
|
||||
@@ -149,7 +150,7 @@ async def require_user(token: str = Depends(oauth2_scheme)):
|
||||
except JWTError:
|
||||
raise credentials_exception
|
||||
|
||||
user = await get_user(email=token_data.email)
|
||||
user = await get_user(email=token_data.email or "")
|
||||
|
||||
if user is None:
|
||||
raise credentials_exception
|
||||
|
||||
4
api/backend/auth/schemas/__init__.py
Normal file
4
api/backend/auth/schemas/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# LOCAL
|
||||
from .auth import User, Token, UserInDB, TokenData, UserCreate
|
||||
|
||||
__all__ = ["User", "Token", "UserInDB", "TokenData", "UserCreate"]
|
||||
@@ -1 +1,24 @@
|
||||
# STL
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
DATABASE_PATH = "data/database.db"
|
||||
RECORDINGS_DIR = Path("media/recordings")
|
||||
RECORDINGS_ENABLED = os.getenv("RECORDINGS_ENABLED", "true").lower() == "true"
|
||||
MEDIA_DIR = Path("media")
|
||||
MEDIA_TYPES = [
|
||||
"audio",
|
||||
"documents",
|
||||
"images",
|
||||
"pdfs",
|
||||
"presentations",
|
||||
"spreadsheets",
|
||||
"videos",
|
||||
]
|
||||
|
||||
REGISTRATION_ENABLED = os.getenv("REGISTRATION_ENABLED", "true").lower() == "true"
|
||||
DEFAULT_USER_EMAIL = os.getenv("DEFAULT_USER_EMAIL")
|
||||
DEFAULT_USER_PASSWORD = os.getenv("DEFAULT_USER_PASSWORD")
|
||||
DEFAULT_USER_FULL_NAME = os.getenv("DEFAULT_USER_FULL_NAME")
|
||||
|
||||
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from .common import insert, QUERIES, update
|
||||
# LOCAL
|
||||
from .common import insert, update, connect
|
||||
from .schema import INIT_QUERY
|
||||
|
||||
__all__ = ["insert", "QUERIES", "update"]
|
||||
__all__ = ["insert", "update", "INIT_QUERY", "connect"]
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
# STL
|
||||
import logging
|
||||
import sqlite3
|
||||
from typing import Any, Optional
|
||||
from api.backend.constants import DATABASE_PATH
|
||||
from api.backend.utils import format_json, format_sql_row_to_python
|
||||
from api.backend.database.schema import INIT_QUERY
|
||||
from api.backend.database.queries import JOB_INSERT_QUERY, DELETE_JOB_QUERY
|
||||
import logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
# LOCAL
|
||||
from api.backend.constants import DATABASE_PATH
|
||||
from api.backend.database.utils import format_json, format_sql_row_to_python
|
||||
|
||||
LOG = logging.getLogger("Database")
|
||||
|
||||
|
||||
def connect():
|
||||
@@ -25,8 +26,10 @@ def insert(query: str, values: tuple[Any, ...]):
|
||||
try:
|
||||
_ = cursor.execute(query, copy)
|
||||
connection.commit()
|
||||
|
||||
except sqlite3.Error as e:
|
||||
LOG.error(f"An error occurred: {e}")
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
connection.close()
|
||||
@@ -78,15 +81,9 @@ def update(query: str, values: Optional[tuple[Any, ...]] = None):
|
||||
return res.rowcount
|
||||
except sqlite3.Error as e:
|
||||
LOG.error(f"An error occurred: {e}")
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
QUERIES = {
|
||||
"init": INIT_QUERY,
|
||||
"insert_job": JOB_INSERT_QUERY,
|
||||
"delete_job": DELETE_JOB_QUERY,
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from .queries import JOB_INSERT_QUERY, DELETE_JOB_QUERY
|
||||
# LOCAL
|
||||
from .job.job_queries import DELETE_JOB_QUERY, JOB_INSERT_QUERY
|
||||
|
||||
__all__ = ["JOB_INSERT_QUERY", "DELETE_JOB_QUERY"]
|
||||
|
||||
68
api/backend/database/queries/job/job_queries.py
Normal file
68
api/backend/database/queries/job/job_queries.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# STL
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
# LOCAL
|
||||
from api.backend.database.utils import format_list_for_query
|
||||
from api.backend.database.common import query, insert, update
|
||||
|
||||
JOB_INSERT_QUERY = """
|
||||
INSERT INTO jobs
|
||||
(id, url, elements, user, time_created, result, status, chat, job_options, agent_mode, prompt)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
"""
|
||||
|
||||
DELETE_JOB_QUERY = """
|
||||
DELETE FROM jobs WHERE id IN ()
|
||||
"""
|
||||
|
||||
LOG = logging.getLogger("Database")
|
||||
|
||||
|
||||
def insert_job(item: dict[str, Any]) -> None:
|
||||
insert(
|
||||
JOB_INSERT_QUERY,
|
||||
(
|
||||
item["id"],
|
||||
item["url"],
|
||||
item["elements"],
|
||||
item["user"],
|
||||
item["time_created"],
|
||||
item["result"],
|
||||
item["status"],
|
||||
item["chat"],
|
||||
item["job_options"],
|
||||
item["agent_mode"],
|
||||
item["prompt"],
|
||||
),
|
||||
)
|
||||
LOG.info(f"Inserted item: {item}")
|
||||
|
||||
|
||||
async def get_queued_job():
|
||||
queued_job_query = (
|
||||
"SELECT * FROM jobs WHERE status = 'Queued' ORDER BY time_created DESC LIMIT 1"
|
||||
)
|
||||
|
||||
res = query(queued_job_query)
|
||||
LOG.info(f"Got queued job: {res}")
|
||||
return res[0] if res else None
|
||||
|
||||
|
||||
async def update_job(ids: list[str], field: str, value: Any):
|
||||
query = f"UPDATE jobs SET {field} = ? WHERE id IN {format_list_for_query(ids)}"
|
||||
res = update(query, tuple([value] + ids))
|
||||
LOG.info(f"Updated job: {res}")
|
||||
|
||||
|
||||
async def delete_jobs(jobs: list[str]):
|
||||
if not jobs:
|
||||
LOG.info("No jobs to delete.")
|
||||
return False
|
||||
|
||||
query = f"DELETE FROM jobs WHERE id IN {format_list_for_query(jobs)}"
|
||||
res = update(query, tuple(jobs))
|
||||
|
||||
LOG.info(f"Deleted jobs: {res}")
|
||||
|
||||
return res
|
||||
@@ -1,9 +0,0 @@
|
||||
JOB_INSERT_QUERY = """
|
||||
INSERT INTO jobs
|
||||
(id, url, elements, user, time_created, result, status, chat, job_options)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
"""
|
||||
|
||||
DELETE_JOB_QUERY = """
|
||||
DELETE FROM jobs WHERE id IN ()
|
||||
"""
|
||||
41
api/backend/database/queries/statistics/statistic_queries.py
Normal file
41
api/backend/database/queries/statistics/statistic_queries.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# LOCAL
|
||||
from api.backend.database.common import query
|
||||
|
||||
|
||||
async def average_elements_per_link(user: str):
|
||||
job_query = """
|
||||
SELECT
|
||||
DATE(time_created) AS date,
|
||||
AVG(json_array_length(elements)) AS average_elements,
|
||||
COUNT(*) AS count
|
||||
FROM
|
||||
jobs
|
||||
WHERE
|
||||
status = 'Completed' AND user = ?
|
||||
GROUP BY
|
||||
DATE(time_created)
|
||||
ORDER BY
|
||||
date ASC;
|
||||
"""
|
||||
results = query(job_query, (user,))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
async def get_jobs_per_day(user: str):
|
||||
job_query = """
|
||||
SELECT
|
||||
DATE(time_created) AS date,
|
||||
COUNT(*) AS job_count
|
||||
FROM
|
||||
jobs
|
||||
WHERE
|
||||
status = 'Completed' AND user = ?
|
||||
GROUP BY
|
||||
DATE(time_created)
|
||||
ORDER BY
|
||||
date ASC;
|
||||
"""
|
||||
results = query(job_query, (user,))
|
||||
|
||||
return results
|
||||
@@ -27,4 +27,8 @@ CREATE TABLE IF NOT EXISTS cron_jobs (
|
||||
time_updated DATETIME NOT NULL,
|
||||
FOREIGN KEY (job_id) REFERENCES jobs(id)
|
||||
);
|
||||
|
||||
ALTER TABLE jobs ADD COLUMN agent_mode BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
ALTER TABLE jobs ADD COLUMN prompt STRING;
|
||||
ALTER TABLE jobs ADD COLUMN favorite BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
"""
|
||||
|
||||
@@ -1,24 +1,52 @@
|
||||
import os
|
||||
from api.backend.database.common import connect, QUERIES
|
||||
# STL
|
||||
import logging
|
||||
import sqlite3
|
||||
|
||||
# LOCAL
|
||||
from api.backend.constants import (
|
||||
DEFAULT_USER_EMAIL,
|
||||
REGISTRATION_ENABLED,
|
||||
DEFAULT_USER_PASSWORD,
|
||||
DEFAULT_USER_FULL_NAME,
|
||||
)
|
||||
from api.backend.auth.auth_utils import get_password_hash
|
||||
from api.backend.database.common import insert, connect
|
||||
from api.backend.database.schema import INIT_QUERY
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = logging.getLogger("Database")
|
||||
|
||||
|
||||
def init_database():
|
||||
def execute_startup_query():
|
||||
cursor = connect()
|
||||
|
||||
for query in QUERIES["init"].strip().split(";"):
|
||||
if query.strip():
|
||||
for query in INIT_QUERY.strip().split(";"):
|
||||
query = query.strip()
|
||||
|
||||
if not query:
|
||||
continue
|
||||
|
||||
try:
|
||||
LOG.info(f"Executing query: {query}")
|
||||
_ = cursor.execute(query)
|
||||
|
||||
if os.environ.get("REGISTRATION_ENABLED", "True") == "False":
|
||||
default_user_email = os.environ.get("DEFAULT_USER_EMAIL")
|
||||
default_user_password = os.environ.get("DEFAULT_USER_PASSWORD")
|
||||
default_user_full_name = os.environ.get("DEFAULT_USER_FULL_NAME")
|
||||
except sqlite3.OperationalError as e:
|
||||
if "duplicate column name" in str(e).lower():
|
||||
LOG.warning(f"Skipping duplicate column error: {e}")
|
||||
continue
|
||||
else:
|
||||
LOG.error(f"Error executing query: {query}")
|
||||
raise
|
||||
|
||||
cursor.close()
|
||||
|
||||
|
||||
def init_database():
|
||||
execute_startup_query()
|
||||
|
||||
if not REGISTRATION_ENABLED:
|
||||
default_user_email = DEFAULT_USER_EMAIL
|
||||
default_user_password = DEFAULT_USER_PASSWORD
|
||||
default_user_full_name = DEFAULT_USER_FULL_NAME
|
||||
|
||||
if (
|
||||
not default_user_email
|
||||
@@ -31,7 +59,7 @@ def init_database():
|
||||
exit(1)
|
||||
|
||||
query = "INSERT INTO users (email, hashed_password, full_name) VALUES (?, ?, ?)"
|
||||
_ = cursor.execute(
|
||||
_ = insert(
|
||||
query,
|
||||
(
|
||||
default_user_email,
|
||||
@@ -39,5 +67,3 @@ def init_database():
|
||||
default_user_full_name,
|
||||
),
|
||||
)
|
||||
|
||||
cursor.close()
|
||||
|
||||
30
api/backend/database/utils.py
Normal file
30
api/backend/database/utils.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# STL
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
|
||||
def format_list_for_query(ids: list[str]):
|
||||
return (
|
||||
f"({','.join(['?' for _ in ids])})" # Returns placeholders, e.g., "(?, ?, ?)"
|
||||
)
|
||||
|
||||
|
||||
def format_sql_row_to_python(row: dict[str, Any]):
|
||||
new_row: dict[str, Any] = {}
|
||||
for key, value in row.items():
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
new_row[key] = json.loads(value)
|
||||
except json.JSONDecodeError:
|
||||
new_row[key] = value
|
||||
else:
|
||||
new_row[key] = value
|
||||
|
||||
return new_row
|
||||
|
||||
|
||||
def format_json(items: list[Any]):
|
||||
for idx, item in enumerate(items):
|
||||
if isinstance(item, (dict, list)):
|
||||
formatted_item = json.dumps(item)
|
||||
items[idx] = formatted_item
|
||||
@@ -1,17 +1,9 @@
|
||||
from .job import (
|
||||
insert,
|
||||
update_job,
|
||||
delete_jobs,
|
||||
get_jobs_per_day,
|
||||
get_queued_job,
|
||||
average_elements_per_link,
|
||||
)
|
||||
# LOCAL
|
||||
from .job import insert, update_job, delete_jobs, get_queued_job
|
||||
|
||||
__all__ = [
|
||||
"insert",
|
||||
"update_job",
|
||||
"delete_jobs",
|
||||
"get_jobs_per_day",
|
||||
"get_queued_job",
|
||||
"average_elements_per_link",
|
||||
]
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
# STL
|
||||
import uuid
|
||||
import logging
|
||||
import datetime
|
||||
from typing import Any
|
||||
import uuid
|
||||
from api.backend.database.common import insert, query
|
||||
from api.backend.models import CronJob
|
||||
from apscheduler.schedulers.background import BackgroundScheduler # type: ignore
|
||||
from apscheduler.triggers.cron import CronTrigger # type: ignore
|
||||
|
||||
# PDM
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job import insert as insert_job
|
||||
import logging
|
||||
from api.backend.schemas.cron import CronJob
|
||||
from api.backend.database.common import query, insert
|
||||
|
||||
LOG = logging.getLogger("Cron Scheduler")
|
||||
LOG = logging.getLogger("Cron")
|
||||
|
||||
|
||||
def insert_cron_job(cron_job: CronJob):
|
||||
@@ -17,6 +21,7 @@ def insert_cron_job(cron_job: CronJob):
|
||||
INSERT INTO cron_jobs (id, user_email, job_id, cron_expression, time_created, time_updated)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
"""
|
||||
|
||||
values = (
|
||||
cron_job.id,
|
||||
cron_job.user_email,
|
||||
@@ -36,6 +41,7 @@ def delete_cron_job(id: str, user_email: str):
|
||||
DELETE FROM cron_jobs
|
||||
WHERE id = ? AND user_email = ?
|
||||
"""
|
||||
|
||||
values = (id, user_email)
|
||||
insert(query, values)
|
||||
|
||||
|
||||
@@ -3,20 +3,18 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
# LOCAL
|
||||
from api.backend.utils import format_list_for_query
|
||||
from api.backend.database.common import (
|
||||
insert as common_insert,
|
||||
query as common_query,
|
||||
QUERIES,
|
||||
update as common_update,
|
||||
)
|
||||
from api.backend.database.utils import format_list_for_query
|
||||
from api.backend.database.common import query as common_query
|
||||
from api.backend.database.common import insert as common_insert
|
||||
from api.backend.database.common import update as common_update
|
||||
from api.backend.database.queries.job.job_queries import JOB_INSERT_QUERY
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = logging.getLogger("Job")
|
||||
|
||||
|
||||
def insert(item: dict[str, Any]) -> None:
|
||||
common_insert(
|
||||
QUERIES["insert_job"],
|
||||
JOB_INSERT_QUERY,
|
||||
(
|
||||
item["id"],
|
||||
item["url"],
|
||||
@@ -27,9 +25,12 @@ def insert(item: dict[str, Any]) -> None:
|
||||
item["status"],
|
||||
item["chat"],
|
||||
item["job_options"],
|
||||
item["agent_mode"],
|
||||
item["prompt"],
|
||||
),
|
||||
)
|
||||
LOG.info(f"Inserted item: {item}")
|
||||
|
||||
LOG.debug(f"Inserted item: {item}")
|
||||
|
||||
|
||||
async def get_queued_job():
|
||||
@@ -37,61 +38,22 @@ async def get_queued_job():
|
||||
"SELECT * FROM jobs WHERE status = 'Queued' ORDER BY time_created DESC LIMIT 1"
|
||||
)
|
||||
res = common_query(query)
|
||||
LOG.info(f"Got queued job: {res}")
|
||||
LOG.debug(f"Got queued job: {res}")
|
||||
return res[0] if res else None
|
||||
|
||||
|
||||
async def update_job(ids: list[str], field: str, value: Any):
|
||||
query = f"UPDATE jobs SET {field} = ? WHERE id IN {format_list_for_query(ids)}"
|
||||
res = common_update(query, tuple([value] + ids))
|
||||
LOG.info(f"Updated job: {res}")
|
||||
LOG.debug(f"Updated job: {res}")
|
||||
|
||||
|
||||
async def delete_jobs(jobs: list[str]):
|
||||
if not jobs:
|
||||
LOG.info("No jobs to delete.")
|
||||
LOG.debug("No jobs to delete.")
|
||||
return False
|
||||
|
||||
query = f"DELETE FROM jobs WHERE id IN {format_list_for_query(jobs)}"
|
||||
res = common_update(query, tuple(jobs))
|
||||
|
||||
return res > 0
|
||||
|
||||
|
||||
async def average_elements_per_link(user: str):
|
||||
job_query = """
|
||||
SELECT
|
||||
DATE(time_created) AS date,
|
||||
AVG(json_array_length(elements)) AS average_elements,
|
||||
COUNT(*) AS count
|
||||
FROM
|
||||
jobs
|
||||
WHERE
|
||||
status = 'Completed' AND user = ?
|
||||
GROUP BY
|
||||
DATE(time_created)
|
||||
ORDER BY
|
||||
date ASC;
|
||||
"""
|
||||
results = common_query(job_query, (user,))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
async def get_jobs_per_day(user: str):
|
||||
job_query = """
|
||||
SELECT
|
||||
DATE(time_created) AS date,
|
||||
COUNT(*) AS job_count
|
||||
FROM
|
||||
jobs
|
||||
WHERE
|
||||
status = 'Completed' AND user = ?
|
||||
GROUP BY
|
||||
DATE(time_created)
|
||||
ORDER BY
|
||||
date ASC;
|
||||
"""
|
||||
results = common_query(job_query, (user,))
|
||||
|
||||
return results
|
||||
|
||||
@@ -1,113 +1,111 @@
|
||||
# STL
|
||||
import datetime
|
||||
import uuid
|
||||
import traceback
|
||||
from io import StringIO
|
||||
import csv
|
||||
import logging
|
||||
import uuid
|
||||
import random
|
||||
import logging
|
||||
import datetime
|
||||
from io import StringIO
|
||||
|
||||
# PDM
|
||||
from fastapi import Depends, APIRouter
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from api.backend.scheduler import scheduler
|
||||
from fastapi.responses import FileResponse, JSONResponse, StreamingResponse
|
||||
from apscheduler.triggers.cron import CronTrigger # type: ignore
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job import insert, update_job, delete_jobs
|
||||
from api.backend.models import (
|
||||
DeleteCronJob,
|
||||
UpdateJobs,
|
||||
DownloadJob,
|
||||
DeleteScrapeJobs,
|
||||
Job,
|
||||
CronJob,
|
||||
)
|
||||
from api.backend.schemas import User
|
||||
from api.backend.constants import MEDIA_DIR, MEDIA_TYPES, RECORDINGS_DIR
|
||||
from api.backend.scheduler import scheduler
|
||||
from api.backend.schemas.job import Job, UpdateJobs, DownloadJob, DeleteScrapeJobs
|
||||
from api.backend.auth.schemas import User
|
||||
from api.backend.schemas.cron import CronJob, DeleteCronJob
|
||||
from api.backend.database.utils import format_list_for_query
|
||||
from api.backend.auth.auth_utils import get_current_user
|
||||
from api.backend.utils import clean_text, format_list_for_query
|
||||
from api.backend.job.models.job_options import FetchOptions
|
||||
|
||||
from api.backend.database.common import query
|
||||
|
||||
from api.backend.job.utils.text_utils import clean_text
|
||||
from api.backend.job.models.job_options import FetchOptions
|
||||
from api.backend.routers.handle_exceptions import handle_exceptions
|
||||
from api.backend.job.utils.clean_job_format import clean_job_format
|
||||
from api.backend.job.cron_scheduling.cron_scheduling import (
|
||||
delete_cron_job,
|
||||
get_cron_job_trigger,
|
||||
insert_cron_job,
|
||||
get_cron_jobs,
|
||||
delete_cron_job,
|
||||
insert_cron_job,
|
||||
get_cron_job_trigger,
|
||||
insert_job_from_cron_job,
|
||||
)
|
||||
from api.backend.job.utils.stream_md_from_job_results import stream_md_from_job_results
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = logging.getLogger("Job")
|
||||
|
||||
job_router = APIRouter()
|
||||
|
||||
|
||||
@job_router.post("/update")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def update(update_jobs: UpdateJobs, _: User = Depends(get_current_user)):
|
||||
"""Used to update jobs"""
|
||||
await update_job(update_jobs.ids, update_jobs.field, update_jobs.value)
|
||||
|
||||
return JSONResponse(content={"message": "Jobs updated successfully."})
|
||||
|
||||
|
||||
@job_router.post("/submit-scrape-job")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def submit_scrape_job(job: Job):
|
||||
LOG.info(f"Recieved job: {job}")
|
||||
try:
|
||||
job.id = uuid.uuid4().hex
|
||||
|
||||
job_dict = job.model_dump()
|
||||
insert(job_dict)
|
||||
job.id = uuid.uuid4().hex
|
||||
job_dict = job.model_dump()
|
||||
insert(job_dict)
|
||||
|
||||
return JSONResponse(content={"id": job.id})
|
||||
except Exception as e:
|
||||
LOG.error(f"Exception occurred: {traceback.format_exc()}")
|
||||
return JSONResponse(content={"error": str(e)}, status_code=500)
|
||||
return JSONResponse(
|
||||
content={"id": job.id, "message": "Job submitted successfully."}
|
||||
)
|
||||
|
||||
|
||||
@job_router.post("/retrieve-scrape-jobs")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def retrieve_scrape_jobs(
|
||||
fetch_options: FetchOptions, user: User = Depends(get_current_user)
|
||||
):
|
||||
LOG.info(f"Retrieving jobs for account: {user.email}")
|
||||
ATTRIBUTES = "chat" if fetch_options.chat else "*"
|
||||
|
||||
try:
|
||||
job_query = f"SELECT {ATTRIBUTES} FROM jobs WHERE user = ?"
|
||||
results = query(job_query, (user.email,))
|
||||
return JSONResponse(content=jsonable_encoder(results[::-1]))
|
||||
except Exception as e:
|
||||
LOG.error(f"Exception occurred: {e}")
|
||||
return JSONResponse(content=[], status_code=500)
|
||||
job_query = f"SELECT {ATTRIBUTES} FROM jobs WHERE user = ?"
|
||||
results = query(job_query, (user.email,))
|
||||
return JSONResponse(content=jsonable_encoder(results[::-1]))
|
||||
|
||||
|
||||
@job_router.get("/job/{id}")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def job(id: str, user: User = Depends(get_current_user)):
|
||||
LOG.info(f"Retrieving jobs for account: {user.email}")
|
||||
|
||||
try:
|
||||
job_query = "SELECT * FROM jobs WHERE user = ? AND id = ?"
|
||||
results = query(job_query, (user.email, id))
|
||||
return JSONResponse(content=jsonable_encoder(results))
|
||||
except Exception as e:
|
||||
LOG.error(f"Exception occurred: {e}")
|
||||
return JSONResponse(content={"error": str(e)}, status_code=500)
|
||||
job_query = "SELECT * FROM jobs WHERE user = ? AND id = ?"
|
||||
results = query(job_query, (user.email, id))
|
||||
return JSONResponse(content=jsonable_encoder(results))
|
||||
|
||||
|
||||
@job_router.post("/download")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def download(download_job: DownloadJob):
|
||||
LOG.info(f"Downloading job with ids: {download_job.ids}")
|
||||
job_query = (
|
||||
f"SELECT * FROM jobs WHERE id IN {format_list_for_query(download_job.ids)}"
|
||||
)
|
||||
results = query(job_query, tuple(download_job.ids))
|
||||
|
||||
try:
|
||||
job_query = (
|
||||
f"SELECT * FROM jobs WHERE id IN {format_list_for_query(download_job.ids)}"
|
||||
)
|
||||
results = query(job_query, tuple(download_job.ids))
|
||||
|
||||
if download_job.job_format == "csv":
|
||||
csv_buffer = StringIO()
|
||||
csv_writer = csv.writer(csv_buffer, quotechar='"', quoting=csv.QUOTE_ALL)
|
||||
|
||||
headers = ["id", "url", "element_name", "xpath", "text", "user", "time_created"]
|
||||
headers = [
|
||||
"id",
|
||||
"url",
|
||||
"element_name",
|
||||
"xpath",
|
||||
"text",
|
||||
"user",
|
||||
"time_created",
|
||||
]
|
||||
csv_writer.writerow(headers)
|
||||
|
||||
for result in results:
|
||||
@@ -139,23 +137,37 @@ async def download(download_job: DownloadJob):
|
||||
response.headers["Content-Disposition"] = "attachment; filename=export.csv"
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
LOG.error(f"Exception occurred: {e}")
|
||||
traceback.print_exc()
|
||||
return {"error": str(e)}
|
||||
elif download_job.job_format == "md":
|
||||
response = StreamingResponse(
|
||||
stream_md_from_job_results(results),
|
||||
media_type="text/markdown",
|
||||
)
|
||||
|
||||
response.headers["Content-Disposition"] = "attachment; filename=export.md"
|
||||
return response
|
||||
|
||||
|
||||
@job_router.get("/job/{id}/convert-to-csv")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def convert_to_csv(id: str):
|
||||
job_query = f"SELECT * FROM jobs WHERE id = ?"
|
||||
results = query(job_query, (id,))
|
||||
return JSONResponse(content=clean_job_format(results))
|
||||
|
||||
|
||||
@job_router.post("/delete-scrape-jobs")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def delete(delete_scrape_jobs: DeleteScrapeJobs):
|
||||
result = await delete_jobs(delete_scrape_jobs.ids)
|
||||
return (
|
||||
JSONResponse(content={"message": "Jobs successfully deleted."})
|
||||
if result
|
||||
else JSONResponse({"error": "Jobs not deleted."})
|
||||
else JSONResponse(content={"error": "Jobs not deleted."})
|
||||
)
|
||||
|
||||
|
||||
@job_router.post("/schedule-cron-job")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def schedule_cron_job(cron_job: CronJob):
|
||||
if not cron_job.id:
|
||||
cron_job.id = uuid.uuid4().hex
|
||||
@@ -181,6 +193,7 @@ async def schedule_cron_job(cron_job: CronJob):
|
||||
|
||||
|
||||
@job_router.post("/delete-cron-job")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def delete_cron_job_request(request: DeleteCronJob):
|
||||
if not request.id:
|
||||
return JSONResponse(
|
||||
@@ -194,6 +207,42 @@ async def delete_cron_job_request(request: DeleteCronJob):
|
||||
|
||||
|
||||
@job_router.get("/cron-jobs")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def get_cron_jobs_request(user: User = Depends(get_current_user)):
|
||||
cron_jobs = get_cron_jobs(user.email)
|
||||
return JSONResponse(content=jsonable_encoder(cron_jobs))
|
||||
|
||||
|
||||
@job_router.get("/recordings/{id}")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def get_recording(id: str):
|
||||
path = RECORDINGS_DIR / f"{id}.mp4"
|
||||
if not path.exists():
|
||||
return JSONResponse(content={"error": "Recording not found."}, status_code=404)
|
||||
|
||||
return FileResponse(
|
||||
path, headers={"Content-Type": "video/mp4", "Accept-Ranges": "bytes"}
|
||||
)
|
||||
|
||||
|
||||
@job_router.get("/get-media")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def get_media(id: str):
|
||||
files: dict[str, list[str]] = {}
|
||||
|
||||
for media_type in MEDIA_TYPES:
|
||||
path = MEDIA_DIR / media_type / f"{id}"
|
||||
files[media_type] = [file.name for file in path.glob("*")]
|
||||
|
||||
return JSONResponse(content={"files": files})
|
||||
|
||||
|
||||
@job_router.get("/media")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def get_media_file(id: str, type: str, file: str):
|
||||
path = MEDIA_DIR / type / f"{id}" / file
|
||||
|
||||
if not path.exists():
|
||||
return JSONResponse(content={"error": "Media file not found."}, status_code=404)
|
||||
|
||||
return FileResponse(path)
|
||||
@@ -1,3 +1,5 @@
|
||||
from .job_options import JobOptions
|
||||
# LOCAL
|
||||
from .job import Element, CapturedElement
|
||||
from .job_options import Proxy, JobOptions
|
||||
|
||||
__all__ = ["JobOptions"]
|
||||
__all__ = ["JobOptions", "CapturedElement", "Element", "Proxy"]
|
||||
|
||||
15
api/backend/job/models/job.py
Normal file
15
api/backend/job/models/job.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from typing import Optional
|
||||
|
||||
import pydantic
|
||||
|
||||
|
||||
class Element(pydantic.BaseModel):
|
||||
name: str
|
||||
xpath: str
|
||||
url: Optional[str] = None
|
||||
|
||||
|
||||
class CapturedElement(pydantic.BaseModel):
|
||||
xpath: str
|
||||
text: str
|
||||
name: str
|
||||
@@ -1,8 +1,19 @@
|
||||
from pydantic import BaseModel
|
||||
# STL
|
||||
from typing import Any, Optional
|
||||
|
||||
# PDM
|
||||
from pydantic import BaseModel
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job.models.site_map import SiteMap
|
||||
|
||||
|
||||
class Proxy(BaseModel):
|
||||
server: str
|
||||
username: Optional[str] = None
|
||||
password: Optional[str] = None
|
||||
|
||||
|
||||
class FetchOptions(BaseModel):
|
||||
chat: Optional[bool] = None
|
||||
|
||||
@@ -10,6 +21,7 @@ class FetchOptions(BaseModel):
|
||||
class JobOptions(BaseModel):
|
||||
multi_page_scrape: bool = False
|
||||
custom_headers: dict[str, Any] = {}
|
||||
proxies: list[str] = []
|
||||
proxies: list[Proxy] = []
|
||||
site_map: Optional[SiteMap] = None
|
||||
collect_media: bool = False
|
||||
custom_cookies: list[dict[str, Any]] = []
|
||||
|
||||
49
api/backend/job/scraping/add_custom.py
Normal file
49
api/backend/job/scraping/add_custom.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# STL
|
||||
import logging
|
||||
from typing import Any, Optional
|
||||
from urllib.parse import urlparse
|
||||
|
||||
# PDM
|
||||
from playwright.async_api import Page, BrowserContext
|
||||
|
||||
LOG = logging.getLogger("Job")
|
||||
|
||||
|
||||
async def add_custom_cookies(
|
||||
custom_cookies: list[dict[str, Any]],
|
||||
url: str,
|
||||
context: BrowserContext,
|
||||
) -> None:
|
||||
parsed_url = urlparse(url)
|
||||
domain = parsed_url.netloc
|
||||
|
||||
for cookie in custom_cookies:
|
||||
cookie_dict = {
|
||||
"name": cookie.get("name", ""),
|
||||
"value": cookie.get("value", ""),
|
||||
"domain": domain,
|
||||
"path": "/",
|
||||
}
|
||||
|
||||
LOG.info(f"Adding cookie: {cookie_dict}")
|
||||
await context.add_cookies([cookie_dict]) # type: ignore
|
||||
|
||||
|
||||
async def add_custom_headers(
|
||||
custom_headers: dict[str, Any],
|
||||
page: Page,
|
||||
) -> None:
|
||||
await page.set_extra_http_headers(custom_headers)
|
||||
|
||||
|
||||
async def add_custom_items(
|
||||
url: str,
|
||||
page: Page,
|
||||
cookies: Optional[list[dict[str, Any]]] = None,
|
||||
headers: Optional[dict[str, Any]] = None,
|
||||
) -> None:
|
||||
if cookies:
|
||||
await add_custom_cookies(cookies, url, page.context)
|
||||
|
||||
if headers:
|
||||
await add_custom_headers(headers, page)
|
||||
@@ -1,19 +1,24 @@
|
||||
# STL
|
||||
import os
|
||||
import requests
|
||||
import re
|
||||
import logging
|
||||
from typing import Dict, List
|
||||
from pathlib import Path
|
||||
from selenium.webdriver.common.by import By
|
||||
from seleniumwire import webdriver
|
||||
from urllib.parse import urlparse
|
||||
from urllib.parse import urljoin, urlparse
|
||||
|
||||
from api.backend.utils import LOG
|
||||
# PDM
|
||||
import aiohttp
|
||||
from playwright.async_api import Page
|
||||
|
||||
LOG = logging.getLogger("Job")
|
||||
|
||||
|
||||
def collect_media(driver: webdriver.Chrome):
|
||||
async def collect_media(id: str, page: Page) -> dict[str, list[dict[str, str]]]:
|
||||
media_types = {
|
||||
"images": "img",
|
||||
"videos": "video",
|
||||
"audio": "audio",
|
||||
"pdfs": 'a[href$=".pdf"]',
|
||||
"pdfs": 'a[href$=".pdf"], a[href*=".pdf#page="]',
|
||||
"documents": 'a[href$=".doc"], a[href$=".docx"], a[href$=".txt"], a[href$=".rtf"]',
|
||||
"presentations": 'a[href$=".ppt"], a[href$=".pptx"]',
|
||||
"spreadsheets": 'a[href$=".xls"], a[href$=".xlsx"], a[href$=".csv"]',
|
||||
@@ -24,62 +29,79 @@ def collect_media(driver: webdriver.Chrome):
|
||||
|
||||
media_urls = {}
|
||||
|
||||
for media_type, selector in media_types.items():
|
||||
elements = driver.find_elements(By.CSS_SELECTOR, selector)
|
||||
urls: list[dict[str, str]] = []
|
||||
async with aiohttp.ClientSession() as session:
|
||||
for media_type, selector in media_types.items():
|
||||
elements = await page.query_selector_all(selector)
|
||||
urls: List[Dict[str, str]] = []
|
||||
|
||||
media_dir = base_dir / media_type
|
||||
media_dir.mkdir(exist_ok=True)
|
||||
media_dir = base_dir / media_type
|
||||
media_dir.mkdir(exist_ok=True)
|
||||
|
||||
for element in elements:
|
||||
if media_type == "images":
|
||||
url = element.get_attribute("src")
|
||||
elif media_type == "videos":
|
||||
url = element.get_attribute("src") or element.get_attribute("data-src")
|
||||
else:
|
||||
url = element.get_attribute("href")
|
||||
for element in elements:
|
||||
if media_type == "images":
|
||||
url = await element.get_attribute("src")
|
||||
elif media_type == "videos":
|
||||
url = await element.get_attribute(
|
||||
"src"
|
||||
) or await element.get_attribute("data-src")
|
||||
else:
|
||||
url = await element.get_attribute("href")
|
||||
|
||||
if url and url.startswith(("http://", "https://")):
|
||||
try:
|
||||
filename = os.path.basename(urlparse(url).path)
|
||||
if url and url.startswith("/"):
|
||||
root_url = urlparse(page.url)
|
||||
root_domain = f"{root_url.scheme}://{root_url.netloc}"
|
||||
url = f"{root_domain}{url}"
|
||||
|
||||
if not filename:
|
||||
filename = f"{media_type}_{len(urls)}"
|
||||
if url and re.match(r"^[\w\-]+/", url):
|
||||
root_url = urlparse(page.url)
|
||||
root_domain = f"{root_url.scheme}://{root_url.netloc}"
|
||||
url = urljoin(root_domain + "/", url)
|
||||
|
||||
if media_type == "images":
|
||||
filename += ".jpg"
|
||||
elif media_type == "videos":
|
||||
filename += ".mp4"
|
||||
elif media_type == "audio":
|
||||
filename += ".mp3"
|
||||
elif media_type == "pdfs":
|
||||
filename += ".pdf"
|
||||
elif media_type == "documents":
|
||||
filename += ".doc"
|
||||
elif media_type == "presentations":
|
||||
filename += ".ppt"
|
||||
elif media_type == "spreadsheets":
|
||||
filename += ".xls"
|
||||
if url and url.startswith(("http://", "https://")):
|
||||
try:
|
||||
parsed = urlparse(url)
|
||||
filename = (
|
||||
os.path.basename(parsed.path) or f"{media_type}_{len(urls)}"
|
||||
)
|
||||
|
||||
response = requests.get(url, stream=True)
|
||||
response.raise_for_status()
|
||||
if "." not in filename:
|
||||
ext = {
|
||||
"images": ".jpg",
|
||||
"videos": ".mp4",
|
||||
"audio": ".mp3",
|
||||
"pdfs": ".pdf",
|
||||
"documents": ".doc",
|
||||
"presentations": ".ppt",
|
||||
"spreadsheets": ".xls",
|
||||
}.get(media_type, "")
|
||||
filename += ext
|
||||
|
||||
# Save the file
|
||||
file_path = media_dir / filename
|
||||
with open(file_path, "wb") as f:
|
||||
for chunk in response.iter_content(chunk_size=8192):
|
||||
if chunk:
|
||||
f.write(chunk)
|
||||
if not os.path.exists(media_dir / id):
|
||||
os.makedirs(media_dir / id, exist_ok=True)
|
||||
|
||||
urls.append({"url": url, "local_path": str(file_path)})
|
||||
LOG.info(f"Downloaded {filename} to {file_path}")
|
||||
file_path = media_dir / id / f"{filename}"
|
||||
|
||||
except Exception as e:
|
||||
LOG.error(f"Error downloading {url}: {str(e)}")
|
||||
continue
|
||||
async with session.get(url) as response:
|
||||
response.raise_for_status()
|
||||
|
||||
media_urls[media_type] = urls
|
||||
with open(file_path, "wb") as f:
|
||||
while True:
|
||||
chunk = await response.content.read(8192)
|
||||
if not chunk:
|
||||
break
|
||||
|
||||
f.write(chunk)
|
||||
|
||||
urls.append({"url": url, "local_path": str(file_path)})
|
||||
LOG.info(f"Downloaded {filename} to {file_path}")
|
||||
|
||||
except Exception as e:
|
||||
LOG.error(f"Error downloading {url}: {str(e)}")
|
||||
continue
|
||||
|
||||
media_urls[media_type] = urls
|
||||
|
||||
# Write summary
|
||||
with open(base_dir / "download_summary.txt", "w") as f:
|
||||
for media_type, downloads in media_urls.items():
|
||||
if downloads:
|
||||
|
||||
166
api/backend/job/scraping/scraping.py
Normal file
166
api/backend/job/scraping/scraping.py
Normal file
@@ -0,0 +1,166 @@
|
||||
# STL
|
||||
import random
|
||||
import logging
|
||||
from typing import Any, cast
|
||||
from urllib.parse import urljoin, urlparse
|
||||
|
||||
# PDM
|
||||
from bs4 import Tag, BeautifulSoup
|
||||
from lxml import etree
|
||||
from camoufox import AsyncCamoufox
|
||||
from playwright.async_api import Page
|
||||
|
||||
# LOCAL
|
||||
from api.backend.constants import RECORDINGS_ENABLED
|
||||
from api.backend.job.models import Element, CapturedElement
|
||||
from api.backend.job.utils.text_utils import clean_text
|
||||
from api.backend.job.scraping.add_custom import add_custom_items
|
||||
from api.backend.job.scraping.scraping_utils import (
|
||||
sxpath,
|
||||
is_same_domain,
|
||||
scrape_content,
|
||||
)
|
||||
from api.backend.job.site_mapping.site_mapping import handle_site_mapping
|
||||
|
||||
LOG = logging.getLogger("Job")
|
||||
|
||||
|
||||
async def make_site_request(
|
||||
id: str,
|
||||
url: str,
|
||||
job_options: dict[str, Any],
|
||||
visited_urls: set[str] = set(),
|
||||
pages: set[tuple[str, str]] = set(),
|
||||
original_url: str = "",
|
||||
):
|
||||
headers = job_options["custom_headers"]
|
||||
multi_page_scrape = job_options["multi_page_scrape"]
|
||||
proxies = job_options["proxies"]
|
||||
site_map = job_options["site_map"]
|
||||
collect_media = job_options["collect_media"]
|
||||
custom_cookies = job_options["custom_cookies"]
|
||||
|
||||
if url in visited_urls:
|
||||
return
|
||||
|
||||
proxy = None
|
||||
|
||||
if proxies:
|
||||
proxy = random.choice(proxies)
|
||||
LOG.info(f"Using proxy: {proxy}")
|
||||
|
||||
async with AsyncCamoufox(headless=not RECORDINGS_ENABLED, proxy=proxy) as browser:
|
||||
page: Page = await browser.new_page()
|
||||
await page.set_viewport_size({"width": 1920, "height": 1080})
|
||||
|
||||
# Add cookies and headers
|
||||
await add_custom_items(url, page, custom_cookies, headers)
|
||||
|
||||
LOG.info(f"Visiting URL: {url}")
|
||||
|
||||
try:
|
||||
await page.goto(url, timeout=60000)
|
||||
await page.wait_for_load_state("networkidle")
|
||||
|
||||
final_url = page.url
|
||||
|
||||
visited_urls.add(url)
|
||||
visited_urls.add(final_url)
|
||||
|
||||
html_content = await scrape_content(id, page, pages, collect_media)
|
||||
|
||||
html_content = await page.content()
|
||||
pages.add((html_content, final_url))
|
||||
|
||||
if site_map:
|
||||
await handle_site_mapping(
|
||||
id, site_map, page, pages, collect_media=collect_media
|
||||
)
|
||||
|
||||
finally:
|
||||
await page.close()
|
||||
await browser.close()
|
||||
|
||||
if not multi_page_scrape:
|
||||
return
|
||||
|
||||
soup = BeautifulSoup(html_content, "html.parser")
|
||||
|
||||
for a_tag in soup.find_all("a"):
|
||||
if not isinstance(a_tag, Tag):
|
||||
continue
|
||||
|
||||
link = cast(str, a_tag.get("href", ""))
|
||||
|
||||
if not link:
|
||||
continue
|
||||
|
||||
if not urlparse(link).netloc:
|
||||
base_url = "{0.scheme}://{0.netloc}".format(urlparse(final_url))
|
||||
link = urljoin(base_url, link)
|
||||
|
||||
if link not in visited_urls and is_same_domain(link, original_url):
|
||||
await make_site_request(
|
||||
id,
|
||||
link,
|
||||
job_options=job_options,
|
||||
visited_urls=visited_urls,
|
||||
pages=pages,
|
||||
original_url=original_url,
|
||||
)
|
||||
|
||||
|
||||
async def collect_scraped_elements(page: tuple[str, str], xpaths: list[Element]):
|
||||
soup = BeautifulSoup(page[0], "lxml")
|
||||
root = etree.HTML(str(soup))
|
||||
|
||||
elements: dict[str, list[CapturedElement]] = {}
|
||||
|
||||
for elem in xpaths:
|
||||
el = sxpath(root, elem.xpath)
|
||||
|
||||
for e in el: # type: ignore
|
||||
text = (
|
||||
" ".join(str(t) for t in e.itertext())
|
||||
if isinstance(e, etree._Element)
|
||||
else str(e) # type: ignore
|
||||
)
|
||||
|
||||
text = clean_text(text)
|
||||
|
||||
captured_element = CapturedElement(
|
||||
xpath=elem.xpath, text=text, name=elem.name
|
||||
)
|
||||
|
||||
if elem.name in elements:
|
||||
elements[elem.name].append(captured_element)
|
||||
else:
|
||||
elements[elem.name] = [captured_element]
|
||||
|
||||
return {page[1]: elements}
|
||||
|
||||
|
||||
async def scrape(
|
||||
id: str,
|
||||
url: str,
|
||||
xpaths: list[Element],
|
||||
job_options: dict[str, Any],
|
||||
):
|
||||
visited_urls: set[str] = set()
|
||||
pages: set[tuple[str, str]] = set()
|
||||
|
||||
await make_site_request(
|
||||
id,
|
||||
url,
|
||||
job_options=job_options,
|
||||
visited_urls=visited_urls,
|
||||
pages=pages,
|
||||
original_url=url,
|
||||
)
|
||||
|
||||
elements: list[dict[str, dict[str, list[CapturedElement]]]] = []
|
||||
|
||||
for page in pages:
|
||||
elements.append(await collect_scraped_elements(page, xpaths))
|
||||
|
||||
return elements
|
||||
@@ -1,41 +1,58 @@
|
||||
import time
|
||||
from typing import cast
|
||||
# STL
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import Set, Tuple
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from seleniumwire import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
|
||||
from api.backend.utils import LOG
|
||||
# PDM
|
||||
from lxml import etree
|
||||
from playwright.async_api import Page
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job.scraping.collect_media import collect_media as collect_media_utils
|
||||
|
||||
LOG = logging.getLogger("Job")
|
||||
|
||||
def scrape_content(
|
||||
driver: webdriver.Chrome, pages: set[tuple[str, str]], collect_media: bool
|
||||
):
|
||||
_ = WebDriverWait(driver, 10).until(
|
||||
EC.presence_of_element_located((By.TAG_NAME, "body"))
|
||||
)
|
||||
|
||||
last_height = cast(str, driver.execute_script("return document.body.scrollHeight"))
|
||||
async def scrape_content(
|
||||
id: str, page: Page, pages: Set[Tuple[str, str]], collect_media: bool
|
||||
) -> str:
|
||||
last_height = await page.evaluate("document.body.scrollHeight")
|
||||
|
||||
while True:
|
||||
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
||||
|
||||
time.sleep(3) # Wait for the page to load
|
||||
new_height = cast(
|
||||
str, driver.execute_script("return document.body.scrollHeight")
|
||||
)
|
||||
await page.evaluate("window.scrollTo(0, document.body.scrollHeight);")
|
||||
await asyncio.sleep(3)
|
||||
new_height = await page.evaluate("document.body.scrollHeight")
|
||||
|
||||
if new_height == last_height:
|
||||
break
|
||||
|
||||
last_height = new_height
|
||||
|
||||
pages.add((driver.page_source, driver.current_url))
|
||||
html = await page.content()
|
||||
pages.add((html, page.url))
|
||||
|
||||
if collect_media:
|
||||
LOG.info("Collecting media")
|
||||
collect_media_utils(driver)
|
||||
await collect_media_utils(id, page)
|
||||
|
||||
return driver.page_source
|
||||
return html
|
||||
|
||||
|
||||
def is_same_domain(url: str, original_url: str) -> bool:
|
||||
parsed_url = urlparse(url)
|
||||
parsed_original_url = urlparse(original_url)
|
||||
return parsed_url.netloc == parsed_original_url.netloc or parsed_url.netloc == ""
|
||||
|
||||
|
||||
def clean_xpath(xpath: str) -> str:
|
||||
parts = xpath.split("/")
|
||||
clean_parts = ["/" if part == "" else part for part in parts]
|
||||
clean_xpath = "//".join(clean_parts).replace("////", "//").replace("'", "\\'")
|
||||
LOG.info(f"Cleaned xpath: {clean_xpath}")
|
||||
|
||||
return clean_xpath
|
||||
|
||||
|
||||
def sxpath(context: etree._Element, xpath: str):
|
||||
return context.xpath(xpath)
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
from api.backend.job.models.site_map import Action, SiteMap
|
||||
from selenium import webdriver
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
from selenium.webdriver.common.by import By
|
||||
from typing import Any
|
||||
# STL
|
||||
import asyncio
|
||||
import logging
|
||||
import time
|
||||
from copy import deepcopy
|
||||
from typing import Any
|
||||
|
||||
# PDM
|
||||
from playwright.async_api import Page
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job.models.site_map import Action, SiteMap
|
||||
from api.backend.job.scraping.scraping_utils import scrape_content
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from seleniumwire.inspect import TimeoutException
|
||||
from seleniumwire.webdriver import Chrome
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = logging.getLogger("Job")
|
||||
|
||||
|
||||
def clear_done_actions(site_map: dict[str, Any]):
|
||||
def clear_done_actions(site_map: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Clear all actions that have been clicked."""
|
||||
cleared_site_map = deepcopy(site_map)
|
||||
|
||||
cleared_site_map["actions"] = [
|
||||
action for action in cleared_site_map["actions"] if not action["do_once"]
|
||||
]
|
||||
@@ -27,43 +24,27 @@ def clear_done_actions(site_map: dict[str, Any]):
|
||||
return cleared_site_map
|
||||
|
||||
|
||||
def handle_input(action: Action, driver: webdriver.Chrome):
|
||||
async def handle_input(action: Action, page: Page) -> bool:
|
||||
try:
|
||||
element = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.XPATH, action.xpath))
|
||||
)
|
||||
LOG.info(f"Sending keys: {action.input} to element: {element}")
|
||||
|
||||
element.send_keys(action.input)
|
||||
|
||||
except NoSuchElementException:
|
||||
LOG.info(f"Element not found: {action.xpath}")
|
||||
return False
|
||||
|
||||
except TimeoutException:
|
||||
LOG.info(f"Timeout waiting for element: {action.xpath}")
|
||||
return False
|
||||
|
||||
element = page.locator(f"xpath={action.xpath}")
|
||||
LOG.info(f"Sending keys: {action.input} to element: {action.xpath}")
|
||||
await element.fill(action.input)
|
||||
return True
|
||||
except Exception as e:
|
||||
LOG.info(f"Error handling input: {e}")
|
||||
LOG.warning(f"Error handling input for xpath '{action.xpath}': {e}")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def handle_click(action: Action, driver: webdriver.Chrome):
|
||||
async def handle_click(action: Action, page: Page) -> bool:
|
||||
try:
|
||||
element = driver.find_element(By.XPATH, action.xpath)
|
||||
LOG.info(f"Clicking element: {element}")
|
||||
|
||||
element.click()
|
||||
|
||||
except NoSuchElementException:
|
||||
LOG.info(f"Element not found: {action.xpath}")
|
||||
element = page.locator(f"xpath={action.xpath}")
|
||||
LOG.info(f"Clicking element: {action.xpath}")
|
||||
await element.click()
|
||||
return True
|
||||
except Exception as e:
|
||||
LOG.warning(f"Error clicking element at xpath '{action.xpath}': {e}")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
ACTION_MAP = {
|
||||
"click": handle_click,
|
||||
@@ -72,22 +53,28 @@ ACTION_MAP = {
|
||||
|
||||
|
||||
async def handle_site_mapping(
|
||||
id: str,
|
||||
site_map_dict: dict[str, Any],
|
||||
driver: Chrome,
|
||||
page: Page,
|
||||
pages: set[tuple[str, str]],
|
||||
collect_media: bool = False,
|
||||
):
|
||||
site_map = SiteMap(**site_map_dict)
|
||||
|
||||
for action in site_map.actions:
|
||||
action_handler = ACTION_MAP[action.type]
|
||||
if not action_handler(action, driver):
|
||||
success = await action_handler(action, page)
|
||||
|
||||
if not success:
|
||||
return
|
||||
|
||||
time.sleep(2)
|
||||
await asyncio.sleep(2)
|
||||
|
||||
_ = scrape_content(driver, pages)
|
||||
await scrape_content(id, page, pages, collect_media=collect_media)
|
||||
|
||||
cleared_site_map_dict = clear_done_actions(site_map_dict)
|
||||
|
||||
if cleared_site_map_dict["actions"]:
|
||||
await handle_site_mapping(cleared_site_map_dict, driver, pages)
|
||||
await handle_site_mapping(
|
||||
id, cleared_site_map_dict, page, pages, collect_media=collect_media
|
||||
)
|
||||
|
||||
38
api/backend/job/utils/clean_job_format.py
Normal file
38
api/backend/job/utils/clean_job_format.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# STL
|
||||
from typing import Any
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job.utils.text_utils import clean_text
|
||||
|
||||
|
||||
def clean_job_format(jobs: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
"""
|
||||
Convert a single job to a dictionary format.
|
||||
"""
|
||||
headers = ["id", "url", "element_name", "xpath", "text", "user", "time_created"]
|
||||
|
||||
cleaned_rows = []
|
||||
|
||||
for job in jobs:
|
||||
for res in job["result"]:
|
||||
for url, elements in res.items():
|
||||
for element_name, values in elements.items():
|
||||
for value in values:
|
||||
text = clean_text(value.get("text", "")).strip()
|
||||
if text:
|
||||
cleaned_rows.append(
|
||||
{
|
||||
"id": job.get("id", ""),
|
||||
"url": url,
|
||||
"element_name": element_name,
|
||||
"xpath": value.get("xpath", ""),
|
||||
"text": text,
|
||||
"user": job.get("user", ""),
|
||||
"time_created": job.get("time_created", ""),
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
"headers": headers,
|
||||
"rows": cleaned_rows,
|
||||
}
|
||||
26
api/backend/job/utils/stream_md_from_job_results.py
Normal file
26
api/backend/job/utils/stream_md_from_job_results.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# STL
|
||||
from typing import Any
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job.utils.text_utils import clean_text
|
||||
|
||||
|
||||
def stream_md_from_job_results(jobs: list[dict[str, Any]]):
|
||||
md = "# Job Results Summary\n\n"
|
||||
for i, job in enumerate(jobs, start=1):
|
||||
md += f"## Job #{i}\n"
|
||||
yield f"- **Job URL:** {job.get('url', 'N/A')}\n"
|
||||
yield f"- **Timestamp:** {job.get('time_created', 'N/A')}\n"
|
||||
yield f"- **ID:** {job.get('id', 'N/A')}\n"
|
||||
yield "### Extracted Results:\n"
|
||||
|
||||
for res in job.get("result", []):
|
||||
for url, elements in res.items():
|
||||
yield f"\n#### URL: {url}\n"
|
||||
for element_name, values in elements.items():
|
||||
for value in values:
|
||||
text = clean_text(value.get("text", "")).strip()
|
||||
if text:
|
||||
yield f"- **Element:** `{element_name}`\n"
|
||||
yield f" - **Text:** {text}\n"
|
||||
yield "\n---\n"
|
||||
10
api/backend/job/utils/text_utils.py
Normal file
10
api/backend/job/utils/text_utils.py
Normal file
@@ -0,0 +1,10 @@
|
||||
def clean_text(text: str):
|
||||
text = text.strip()
|
||||
text = text.replace("\n", " ")
|
||||
text = text.replace("\t", " ")
|
||||
text = text.replace("\r", " ")
|
||||
text = text.replace("\f", " ")
|
||||
text = text.replace("\v", " ")
|
||||
text = text.replace("\b", " ")
|
||||
text = text.replace("\a", " ")
|
||||
return text
|
||||
31
api/backend/routers/handle_exceptions.py
Normal file
31
api/backend/routers/handle_exceptions.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# STL
|
||||
import logging
|
||||
import traceback
|
||||
from typing import Any, Union, Callable, Awaitable
|
||||
from functools import wraps
|
||||
|
||||
# PDM
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
|
||||
def handle_exceptions(
|
||||
logger: logging.Logger,
|
||||
) -> Callable[
|
||||
[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Union[Any, JSONResponse]]]
|
||||
]:
|
||||
def decorator(
|
||||
func: Callable[..., Awaitable[Any]],
|
||||
) -> Callable[..., Awaitable[Union[Any, JSONResponse]]]:
|
||||
@wraps(func)
|
||||
async def wrapper(*args: Any, **kwargs: Any) -> Union[Any, JSONResponse]:
|
||||
try:
|
||||
return await func(*args, **kwargs)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Exception occurred: {e}")
|
||||
traceback.print_exc()
|
||||
return JSONResponse(content={"error": str(e)}, status_code=500)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
@@ -1,46 +0,0 @@
|
||||
# STL
|
||||
import logging
|
||||
import docker
|
||||
|
||||
# PDM
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
log_router = APIRouter()
|
||||
|
||||
client = docker.from_env()
|
||||
|
||||
|
||||
@log_router.get("/initial_logs")
|
||||
async def get_initial_logs():
|
||||
container_id = "scraperr_api"
|
||||
|
||||
try:
|
||||
container = client.containers.get(container_id)
|
||||
log_stream = container.logs(stream=False).decode("utf-8")
|
||||
return JSONResponse(content={"logs": log_stream})
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Unexpected error: {e}")
|
||||
|
||||
|
||||
@log_router.get("/logs")
|
||||
async def get_own_logs():
|
||||
container_id = "scraperr_api"
|
||||
|
||||
try:
|
||||
container = client.containers.get(container_id)
|
||||
log_stream = container.logs(stream=True, follow=True)
|
||||
|
||||
def log_generator():
|
||||
try:
|
||||
for log in log_stream:
|
||||
yield f"data: {log.decode('utf-8')}\n\n"
|
||||
except Exception as e:
|
||||
yield f"data: {str(e)}\n\n"
|
||||
|
||||
return StreamingResponse(log_generator(), media_type="text/event-stream")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -1,3 +1,4 @@
|
||||
from apscheduler.schedulers.background import BackgroundScheduler # type: ignore
|
||||
# PDM
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
|
||||
scheduler = BackgroundScheduler()
|
||||
|
||||
17
api/backend/schemas/cron.py
Normal file
17
api/backend/schemas/cron.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from typing import Optional, Union
|
||||
from datetime import datetime
|
||||
import pydantic
|
||||
|
||||
|
||||
class CronJob(pydantic.BaseModel):
|
||||
id: Optional[str] = None
|
||||
user_email: str
|
||||
job_id: str
|
||||
cron_expression: str
|
||||
time_created: Optional[Union[datetime, str]] = None
|
||||
time_updated: Optional[Union[datetime, str]] = None
|
||||
|
||||
|
||||
class DeleteCronJob(pydantic.BaseModel):
|
||||
id: str
|
||||
user_email: str
|
||||
@@ -1,50 +1,9 @@
|
||||
# STL
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Any, Literal, Optional, Union
|
||||
from datetime import datetime
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job.models.job_options import JobOptions
|
||||
|
||||
# PDM
|
||||
import pydantic
|
||||
|
||||
|
||||
class Element(pydantic.BaseModel):
|
||||
name: str
|
||||
xpath: str
|
||||
url: Optional[str] = None
|
||||
|
||||
|
||||
class CapturedElement(pydantic.BaseModel):
|
||||
xpath: str
|
||||
text: str
|
||||
name: str
|
||||
|
||||
|
||||
class RetrieveScrapeJobs(pydantic.BaseModel):
|
||||
user: str
|
||||
|
||||
|
||||
class DownloadJob(pydantic.BaseModel):
|
||||
ids: list[str]
|
||||
|
||||
|
||||
class DeleteScrapeJobs(pydantic.BaseModel):
|
||||
ids: list[str]
|
||||
|
||||
|
||||
class GetStatistics(pydantic.BaseModel):
|
||||
user: str
|
||||
|
||||
|
||||
class UpdateJobs(pydantic.BaseModel):
|
||||
ids: list[str]
|
||||
field: str
|
||||
value: Any
|
||||
|
||||
|
||||
class AI(pydantic.BaseModel):
|
||||
messages: list[Any]
|
||||
from api.backend.job.models import Element, CapturedElement
|
||||
|
||||
|
||||
class Job(pydantic.BaseModel):
|
||||
@@ -57,17 +16,25 @@ class Job(pydantic.BaseModel):
|
||||
job_options: JobOptions
|
||||
status: str = "Queued"
|
||||
chat: Optional[str] = None
|
||||
agent_mode: bool = False
|
||||
prompt: Optional[str] = None
|
||||
favorite: bool = False
|
||||
|
||||
|
||||
class CronJob(pydantic.BaseModel):
|
||||
id: Optional[str] = None
|
||||
user_email: str
|
||||
job_id: str
|
||||
cron_expression: str
|
||||
time_created: Optional[Union[datetime, str]] = None
|
||||
time_updated: Optional[Union[datetime, str]] = None
|
||||
class RetrieveScrapeJobs(pydantic.BaseModel):
|
||||
user: str
|
||||
|
||||
|
||||
class DeleteCronJob(pydantic.BaseModel):
|
||||
id: str
|
||||
user_email: str
|
||||
class DownloadJob(pydantic.BaseModel):
|
||||
ids: list[str]
|
||||
job_format: Literal["csv", "md"]
|
||||
|
||||
|
||||
class DeleteScrapeJobs(pydantic.BaseModel):
|
||||
ids: list[str]
|
||||
|
||||
|
||||
class UpdateJobs(pydantic.BaseModel):
|
||||
ids: list[str]
|
||||
field: str
|
||||
value: Any
|
||||
@@ -1,223 +0,0 @@
|
||||
import logging
|
||||
from typing import Any, Optional
|
||||
import random
|
||||
|
||||
from bs4 import BeautifulSoup, Tag
|
||||
from lxml import etree
|
||||
from seleniumwire import webdriver
|
||||
from lxml.etree import _Element
|
||||
from fake_useragent import UserAgent
|
||||
from selenium.webdriver.chrome.options import Options as ChromeOptions
|
||||
from urllib.parse import urlparse, urljoin
|
||||
from api.backend.models import Element, CapturedElement
|
||||
from api.backend.job.site_mapping.site_mapping import (
|
||||
handle_site_mapping,
|
||||
)
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
from webdriver_manager.chrome import ChromeDriverManager
|
||||
from api.backend.job.scraping.scraping_utils import scrape_content
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HtmlElement(_Element): ...
|
||||
|
||||
|
||||
def is_same_domain(url: str, original_url: str) -> bool:
|
||||
parsed_url = urlparse(url)
|
||||
parsed_original_url = urlparse(original_url)
|
||||
return parsed_url.netloc == parsed_original_url.netloc or parsed_url.netloc == ""
|
||||
|
||||
|
||||
def clean_xpath(xpath: str) -> str:
|
||||
parts = xpath.split("/")
|
||||
clean_parts: list[str] = []
|
||||
for part in parts:
|
||||
if part == "":
|
||||
clean_parts.append("/")
|
||||
else:
|
||||
clean_parts.append(part)
|
||||
clean_xpath = "//".join(clean_parts).replace("////", "//")
|
||||
clean_xpath = clean_xpath.replace("'", "\\'")
|
||||
LOG.info(f"Cleaned xpath: {clean_xpath}")
|
||||
return clean_xpath
|
||||
|
||||
|
||||
def sxpath(context: _Element, xpath: str) -> list[HtmlElement]:
|
||||
return context.xpath(xpath) # pyright: ignore [reportReturnType]
|
||||
|
||||
|
||||
def interceptor(headers: dict[str, Any]):
|
||||
def _interceptor(request: Any):
|
||||
for key, val in headers.items():
|
||||
if request.headers.get(key):
|
||||
del request.headers[key]
|
||||
request.headers[key] = val
|
||||
if "sec-ch-ua" in request.headers:
|
||||
original_value = request.headers["sec-ch-ua"]
|
||||
del request.headers["sec-ch-ua"]
|
||||
modified_value = original_value.replace("HeadlessChrome", "Chrome")
|
||||
request.headers["sec-ch-ua"] = modified_value
|
||||
|
||||
return _interceptor
|
||||
|
||||
|
||||
def create_driver(proxies: Optional[list[str]] = []):
|
||||
ua = UserAgent()
|
||||
chrome_options = ChromeOptions()
|
||||
chrome_options.add_argument("--headless")
|
||||
chrome_options.add_argument("--no-sandbox")
|
||||
chrome_options.add_argument("--disable-dev-shm-usage")
|
||||
chrome_options.add_argument(f"user-agent={ua.random}")
|
||||
|
||||
sw_options = {}
|
||||
|
||||
if proxies:
|
||||
selected_proxy = random.choice(proxies)
|
||||
LOG.info(f"Using proxy: {selected_proxy}")
|
||||
|
||||
sw_options = {
|
||||
"proxy": {
|
||||
"https": f"https://{selected_proxy}",
|
||||
"http": f"http://{selected_proxy}",
|
||||
"no_proxy": "localhost,127.0.0.1",
|
||||
}
|
||||
}
|
||||
|
||||
service = Service(ChromeDriverManager().install())
|
||||
|
||||
driver = webdriver.Chrome(
|
||||
service=service,
|
||||
options=chrome_options,
|
||||
seleniumwire_options=sw_options,
|
||||
)
|
||||
|
||||
return driver
|
||||
|
||||
|
||||
async def make_site_request(
|
||||
url: str,
|
||||
headers: Optional[dict[str, Any]],
|
||||
multi_page_scrape: bool = False,
|
||||
visited_urls: set[str] = set(),
|
||||
pages: set[tuple[str, str]] = set(),
|
||||
original_url: str = "",
|
||||
proxies: Optional[list[str]] = [],
|
||||
site_map: Optional[dict[str, Any]] = None,
|
||||
collect_media: bool = False,
|
||||
) -> None:
|
||||
"""Make basic `GET` request to site using Selenium."""
|
||||
# Check if URL has already been visited
|
||||
if url in visited_urls:
|
||||
return
|
||||
|
||||
driver = create_driver(proxies)
|
||||
driver.implicitly_wait(10)
|
||||
|
||||
if headers:
|
||||
driver.request_interceptor = interceptor(headers)
|
||||
|
||||
try:
|
||||
LOG.info(f"Visiting URL: {url}")
|
||||
driver.get(url)
|
||||
|
||||
final_url = driver.current_url
|
||||
visited_urls.add(url)
|
||||
visited_urls.add(final_url)
|
||||
|
||||
page_source = scrape_content(driver, pages, collect_media)
|
||||
|
||||
if site_map:
|
||||
LOG.info("Site map: %s", site_map)
|
||||
_ = await handle_site_mapping(
|
||||
site_map,
|
||||
driver,
|
||||
pages,
|
||||
)
|
||||
finally:
|
||||
driver.quit()
|
||||
|
||||
if not multi_page_scrape:
|
||||
return
|
||||
|
||||
soup = BeautifulSoup(page_source, "html.parser")
|
||||
|
||||
for a_tag in soup.find_all("a"):
|
||||
if not isinstance(a_tag, Tag):
|
||||
continue
|
||||
|
||||
link = str(a_tag.get("href", ""))
|
||||
|
||||
if link:
|
||||
if not urlparse(link).netloc:
|
||||
base_url = "{0.scheme}://{0.netloc}".format(urlparse(final_url))
|
||||
link = urljoin(base_url, link)
|
||||
|
||||
if link not in visited_urls and is_same_domain(link, original_url):
|
||||
await make_site_request(
|
||||
link,
|
||||
headers=headers,
|
||||
multi_page_scrape=multi_page_scrape,
|
||||
visited_urls=visited_urls,
|
||||
pages=pages,
|
||||
original_url=original_url,
|
||||
)
|
||||
|
||||
|
||||
async def collect_scraped_elements(page: tuple[str, str], xpaths: list[Element]):
|
||||
soup = BeautifulSoup(page[0], "lxml")
|
||||
root = etree.HTML(str(soup))
|
||||
|
||||
elements: dict[str, list[CapturedElement]] = dict()
|
||||
|
||||
for elem in xpaths:
|
||||
el = sxpath(root, elem.xpath)
|
||||
|
||||
for e in el:
|
||||
if isinstance(e, etree._Element): # type: ignore
|
||||
text = "\t".join(str(t) for t in e.itertext())
|
||||
else:
|
||||
text = str(e)
|
||||
captured_element = CapturedElement(
|
||||
xpath=elem.xpath, text=text, name=elem.name
|
||||
)
|
||||
|
||||
if elem.name in elements:
|
||||
elements[elem.name].append(captured_element)
|
||||
continue
|
||||
|
||||
elements[elem.name] = [captured_element]
|
||||
|
||||
return {page[1]: elements}
|
||||
|
||||
|
||||
async def scrape(
|
||||
url: str,
|
||||
xpaths: list[Element],
|
||||
headers: Optional[dict[str, Any]],
|
||||
multi_page_scrape: bool = False,
|
||||
proxies: Optional[list[str]] = [],
|
||||
site_map: Optional[dict[str, Any]] = None,
|
||||
collect_media: bool = False,
|
||||
):
|
||||
visited_urls: set[str] = set()
|
||||
pages: set[tuple[str, str]] = set()
|
||||
|
||||
_ = await make_site_request(
|
||||
url,
|
||||
headers,
|
||||
multi_page_scrape=multi_page_scrape,
|
||||
visited_urls=visited_urls,
|
||||
pages=pages,
|
||||
original_url=url,
|
||||
proxies=proxies,
|
||||
site_map=site_map,
|
||||
collect_media=collect_media,
|
||||
)
|
||||
|
||||
elements: list[dict[str, dict[str, list[CapturedElement]]]] = list()
|
||||
|
||||
for page in pages:
|
||||
elements.append(await collect_scraped_elements(page, xpaths))
|
||||
|
||||
return elements
|
||||
@@ -2,28 +2,30 @@
|
||||
import logging
|
||||
|
||||
# PDM
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import Depends, APIRouter
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job import (
|
||||
from api.backend.auth.schemas import User
|
||||
from api.backend.auth.auth_utils import get_current_user
|
||||
from api.backend.routers.handle_exceptions import handle_exceptions
|
||||
from api.backend.database.queries.statistics.statistic_queries import (
|
||||
get_jobs_per_day,
|
||||
average_elements_per_link,
|
||||
)
|
||||
from api.backend.auth.auth_utils import get_current_user
|
||||
from api.backend.schemas import User
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = logging.getLogger("Statistics")
|
||||
|
||||
stats_router = APIRouter()
|
||||
|
||||
|
||||
@stats_router.get("/statistics/get-average-element-per-link")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def get_average_element_per_link(user: User = Depends(get_current_user)):
|
||||
return await average_elements_per_link(user.email)
|
||||
|
||||
|
||||
@stats_router.get("/statistics/get-average-jobs-per-day")
|
||||
@handle_exceptions(logger=LOG)
|
||||
async def average_jobs_per_day(user: User = Depends(get_current_user)):
|
||||
data = await get_jobs_per_day(user.email)
|
||||
return data
|
||||
63
api/backend/tests/conftest.py
Normal file
63
api/backend/tests/conftest.py
Normal file
@@ -0,0 +1,63 @@
|
||||
# STL
|
||||
import os
|
||||
import sqlite3
|
||||
from typing import Generator
|
||||
from unittest.mock import patch
|
||||
|
||||
# PDM
|
||||
import pytest
|
||||
from proxy import Proxy
|
||||
|
||||
# LOCAL
|
||||
from api.backend.database.schema import INIT_QUERY
|
||||
from api.backend.tests.constants import TEST_DB_PATH
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def running_proxy():
|
||||
proxy = Proxy(["--hostname", "127.0.0.1", "--port", "8080"])
|
||||
proxy.setup()
|
||||
yield proxy
|
||||
proxy.shutdown()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def patch_database_path():
|
||||
with patch("api.backend.database.common.DATABASE_PATH", TEST_DB_PATH):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def patch_recordings_enabled():
|
||||
with patch("api.backend.job.scraping.scraping.RECORDINGS_ENABLED", False):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def test_db_path() -> str:
|
||||
return TEST_DB_PATH
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def test_db(test_db_path: str) -> Generator[str, None, None]:
|
||||
"""Create a fresh test database for each test function."""
|
||||
os.makedirs(os.path.dirname(test_db_path), exist_ok=True)
|
||||
|
||||
if os.path.exists(test_db_path):
|
||||
os.remove(test_db_path)
|
||||
|
||||
conn = sqlite3.connect(test_db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
for query in INIT_QUERY.strip().split(";"):
|
||||
query = query.strip()
|
||||
if query:
|
||||
cursor.execute(query)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
yield test_db_path
|
||||
|
||||
if os.path.exists(test_db_path):
|
||||
os.remove(test_db_path)
|
||||
1
api/backend/tests/constants.py
Normal file
1
api/backend/tests/constants.py
Normal file
@@ -0,0 +1 @@
|
||||
TEST_DB_PATH = "tests/test_db.sqlite"
|
||||
@@ -1,7 +1,13 @@
|
||||
from api.backend.models import Element, Job, JobOptions, CapturedElement
|
||||
# STL
|
||||
import uuid
|
||||
|
||||
# PDM
|
||||
from faker import Faker
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job.models import Element, JobOptions, CapturedElement
|
||||
from api.backend.schemas.job import Job
|
||||
|
||||
fake = Faker()
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
# STL
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
# PDM
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
# LOCAL
|
||||
from api.backend.app import app
|
||||
from api.backend.models import DownloadJob
|
||||
from api.backend.schemas.job import DownloadJob
|
||||
from api.backend.tests.factories.job_factory import create_completed_job
|
||||
|
||||
client = TestClient(app)
|
||||
@@ -13,15 +18,15 @@ mocked_random_int = 123456
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("api.backend.routers.job_router.query")
|
||||
@patch("api.backend.routers.job_router.random.randint")
|
||||
@patch("api.backend.job.job_router.query")
|
||||
@patch("api.backend.job.job_router.random.randint")
|
||||
async def test_download(mock_randint: AsyncMock, mock_query: AsyncMock):
|
||||
# Ensure the mock returns immediately
|
||||
mock_query.return_value = mock_results
|
||||
mock_randint.return_value = mocked_random_int
|
||||
|
||||
# Create a DownloadJob instance
|
||||
download_job = DownloadJob(ids=[mocked_job["id"]])
|
||||
download_job = DownloadJob(ids=[mocked_job["id"]], job_format="csv")
|
||||
|
||||
# Make a POST request to the /download endpoint
|
||||
response = client.post("/download", json=download_job.model_dump())
|
||||
|
||||
@@ -1,27 +1,110 @@
|
||||
import pytest
|
||||
# STL
|
||||
import logging
|
||||
from unittest.mock import AsyncMock, patch, MagicMock
|
||||
from api.backend.scraping import create_driver
|
||||
from typing import Dict
|
||||
from datetime import datetime
|
||||
|
||||
# PDM
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from playwright.async_api import Route, Cookie, async_playwright
|
||||
|
||||
# LOCAL
|
||||
from api.backend.app import app
|
||||
from api.backend.job.models import Proxy, Element, JobOptions
|
||||
from api.backend.schemas.job import Job
|
||||
from api.backend.database.common import query
|
||||
from api.backend.job.scraping.scraping import scrape
|
||||
from api.backend.job.scraping.add_custom import add_custom_items
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("seleniumwire.webdriver.Chrome.get")
|
||||
async def test_proxy(mock_get: AsyncMock):
|
||||
# Mock the response of the requests.get call
|
||||
mock_response = MagicMock()
|
||||
mock_get.return_value = mock_response
|
||||
async def test_add_custom_items():
|
||||
test_cookies = [{"name": "big", "value": "cookie"}]
|
||||
test_headers = {"User-Agent": "test-agent", "Accept": "application/json"}
|
||||
|
||||
driver = create_driver(proxies=["127.0.0.1:8080"])
|
||||
assert driver is not None
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=True)
|
||||
context = await browser.new_context()
|
||||
page = await context.new_page()
|
||||
|
||||
# Simulate a request
|
||||
driver.get("http://example.com")
|
||||
response = driver.last_request
|
||||
# Set up request interception
|
||||
captured_headers: Dict[str, str] = {}
|
||||
|
||||
if response:
|
||||
assert response.headers["Proxy-Connection"] == "keep-alive"
|
||||
async def handle_route(route: Route) -> None:
|
||||
nonlocal captured_headers
|
||||
captured_headers = route.request.headers
|
||||
await route.continue_()
|
||||
|
||||
driver.quit()
|
||||
await page.route("**/*", handle_route)
|
||||
|
||||
await add_custom_items(
|
||||
url="http://example.com",
|
||||
page=page,
|
||||
cookies=test_cookies,
|
||||
headers=test_headers,
|
||||
)
|
||||
|
||||
# Navigate to example.com
|
||||
await page.goto("http://example.com")
|
||||
|
||||
# Verify cookies were added
|
||||
cookies: list[Cookie] = await page.context.cookies()
|
||||
test_cookie = next((c for c in cookies if c.get("name") == "big"), None)
|
||||
|
||||
assert test_cookie is not None
|
||||
assert test_cookie.get("value") == "cookie"
|
||||
assert test_cookie.get("path") == "/" # Default path should be set
|
||||
assert test_cookie.get("sameSite") == "Lax" # Default sameSite should be set
|
||||
|
||||
# Verify headers were added
|
||||
assert captured_headers.get("user-agent") == "test-agent"
|
||||
|
||||
await browser.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_proxies():
|
||||
job = Job(
|
||||
url="https://example.com",
|
||||
elements=[Element(xpath="//div", name="test")],
|
||||
job_options=JobOptions(
|
||||
proxies=[
|
||||
Proxy(
|
||||
server="127.0.0.1:8080",
|
||||
username="user",
|
||||
password="pass",
|
||||
)
|
||||
],
|
||||
),
|
||||
time_created=datetime.now().isoformat(),
|
||||
)
|
||||
|
||||
response = client.post("/submit-scrape-job", json=job.model_dump())
|
||||
assert response.status_code == 200
|
||||
|
||||
jobs = query("SELECT * FROM jobs")
|
||||
job = jobs[0]
|
||||
|
||||
assert job is not None
|
||||
assert job["job_options"]["proxies"] == [
|
||||
{
|
||||
"server": "127.0.0.1:8080",
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
}
|
||||
]
|
||||
|
||||
response = await scrape(
|
||||
id=job["id"],
|
||||
url=job["url"],
|
||||
xpaths=[Element(**e) for e in job["elements"]],
|
||||
job_options=job["job_options"],
|
||||
)
|
||||
|
||||
example_response = response[0]["https://example.com/"]
|
||||
assert example_response is not {}
|
||||
|
||||
17
api/backend/tests/utilities/database.py
Normal file
17
api/backend/tests/utilities/database.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# STL
|
||||
import sqlite3
|
||||
|
||||
# LOCAL
|
||||
from api.backend.database.schema import INIT_QUERY
|
||||
from api.backend.tests.constants import TEST_DB_PATH
|
||||
|
||||
|
||||
def connect_to_db():
|
||||
conn = sqlite3.connect(TEST_DB_PATH)
|
||||
cur = conn.cursor()
|
||||
|
||||
for query in INIT_QUERY.split(";"):
|
||||
cur.execute(query)
|
||||
|
||||
conn.commit()
|
||||
return conn, cur
|
||||
@@ -1,17 +1,10 @@
|
||||
from typing import Any, Optional
|
||||
# STL
|
||||
import logging
|
||||
import json
|
||||
from typing import Optional
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def clean_text(text: str):
|
||||
text = text.replace("\r\n", "\n") # Normalize newlines
|
||||
text = text.replace("\n", "\\n") # Escape newlines
|
||||
text = text.replace('"', '\\"') # Escape double quotes
|
||||
return text
|
||||
|
||||
|
||||
def get_log_level(level_name: Optional[str]) -> int:
|
||||
level = logging.INFO
|
||||
|
||||
@@ -20,30 +13,3 @@ def get_log_level(level_name: Optional[str]) -> int:
|
||||
level = getattr(logging, level_name, logging.INFO)
|
||||
|
||||
return level
|
||||
|
||||
|
||||
def format_list_for_query(ids: list[str]):
|
||||
return (
|
||||
f"({','.join(['?' for _ in ids])})" # Returns placeholders, e.g., "(?, ?, ?)"
|
||||
)
|
||||
|
||||
|
||||
def format_sql_row_to_python(row: dict[str, Any]):
|
||||
new_row: dict[str, Any] = {}
|
||||
for key, value in row.items():
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
new_row[key] = json.loads(value)
|
||||
except json.JSONDecodeError:
|
||||
new_row[key] = value
|
||||
else:
|
||||
new_row[key] = value
|
||||
|
||||
return new_row
|
||||
|
||||
|
||||
def format_json(items: list[Any]):
|
||||
for idx, item in enumerate(items):
|
||||
if isinstance(item, (dict, list)):
|
||||
formatted_item = json.dumps(item)
|
||||
items[idx] = formatted_item
|
||||
|
||||
17
api/backend/worker/constants.py
Normal file
17
api/backend/worker/constants.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# STL
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
NOTIFICATION_CHANNEL = os.getenv("NOTIFICATION_CHANNEL", "")
|
||||
NOTIFICATION_WEBHOOK_URL = os.getenv("NOTIFICATION_WEBHOOK_URL", "")
|
||||
SCRAPERR_FRONTEND_URL = os.getenv("SCRAPERR_FRONTEND_URL", "")
|
||||
EMAIL = os.getenv("EMAIL", "")
|
||||
TO = os.getenv("TO", "")
|
||||
SMTP_HOST = os.getenv("SMTP_HOST", "")
|
||||
SMTP_PORT = int(os.getenv("SMTP_PORT", 587))
|
||||
SMTP_USER = os.getenv("SMTP_USER", "")
|
||||
SMTP_PASSWORD = os.getenv("SMTP_PASSWORD", "")
|
||||
USE_TLS = os.getenv("USE_TLS", "false").lower() == "true"
|
||||
|
||||
RECORDINGS_ENABLED = os.getenv("RECORDINGS_ENABLED", "true").lower() == "true"
|
||||
RECORDINGS_DIR = Path("/project/app/media/recordings")
|
||||
@@ -1,34 +1,89 @@
|
||||
from api.backend.job import get_queued_job, update_job
|
||||
from api.backend.scraping import scrape
|
||||
from api.backend.models import Element
|
||||
# STL
|
||||
import json
|
||||
import asyncio
|
||||
import traceback
|
||||
import subprocess
|
||||
|
||||
# PDM
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
# LOCAL
|
||||
from api.backend.job import update_job, get_queued_job
|
||||
from api.backend.job.models import Element
|
||||
from api.backend.worker.logger import LOG
|
||||
from api.backend.ai.agent.agent import scrape_with_agent
|
||||
from api.backend.database.startup import init_database
|
||||
|
||||
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
||||
LOG = logging.getLogger(__name__)
|
||||
from api.backend.worker.constants import (
|
||||
TO,
|
||||
EMAIL,
|
||||
USE_TLS,
|
||||
SMTP_HOST,
|
||||
SMTP_PORT,
|
||||
SMTP_USER,
|
||||
SMTP_PASSWORD,
|
||||
RECORDINGS_DIR,
|
||||
RECORDINGS_ENABLED,
|
||||
NOTIFICATION_CHANNEL,
|
||||
SCRAPERR_FRONTEND_URL,
|
||||
NOTIFICATION_WEBHOOK_URL,
|
||||
)
|
||||
from api.backend.job.scraping.scraping import scrape
|
||||
from api.backend.worker.post_job_complete.post_job_complete import post_job_complete
|
||||
|
||||
|
||||
async def process_job():
|
||||
job = await get_queued_job()
|
||||
ffmpeg_proc = None
|
||||
status = "Queued"
|
||||
|
||||
if job:
|
||||
LOG.info(f"Beginning processing job: {job}.")
|
||||
|
||||
try:
|
||||
output_path = RECORDINGS_DIR / f"{job['id']}.mp4"
|
||||
|
||||
if RECORDINGS_ENABLED:
|
||||
ffmpeg_proc = subprocess.Popen(
|
||||
[
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-video_size",
|
||||
"1280x1024",
|
||||
"-framerate",
|
||||
"15",
|
||||
"-f",
|
||||
"x11grab",
|
||||
"-i",
|
||||
":99",
|
||||
"-codec:v",
|
||||
"libx264",
|
||||
"-preset",
|
||||
"ultrafast",
|
||||
output_path,
|
||||
]
|
||||
)
|
||||
|
||||
_ = await update_job([job["id"]], field="status", value="Scraping")
|
||||
scraped = await scrape(
|
||||
job["url"],
|
||||
[Element(**j) for j in job["elements"]],
|
||||
job["job_options"]["custom_headers"],
|
||||
job["job_options"]["multi_page_scrape"],
|
||||
job["job_options"]["proxies"],
|
||||
job["job_options"]["site_map"],
|
||||
job["job_options"]["collect_media"],
|
||||
)
|
||||
|
||||
proxies = job["job_options"]["proxies"]
|
||||
|
||||
if proxies and isinstance(proxies[0], str) and proxies[0].startswith("{"):
|
||||
try:
|
||||
proxies = [json.loads(p) for p in proxies]
|
||||
except json.JSONDecodeError:
|
||||
LOG.error(f"Failed to parse proxy JSON: {proxies}")
|
||||
proxies = []
|
||||
|
||||
if job["agent_mode"]:
|
||||
scraped = await scrape_with_agent(job)
|
||||
else:
|
||||
scraped = await scrape(
|
||||
job["id"],
|
||||
job["url"],
|
||||
[Element(**j) for j in job["elements"]],
|
||||
{**job["job_options"], "proxies": proxies},
|
||||
)
|
||||
|
||||
LOG.info(
|
||||
f"Scraped result for url: {job['url']}, with elements: {job['elements']}\n{scraped}"
|
||||
)
|
||||
@@ -36,10 +91,34 @@ async def process_job():
|
||||
[job["id"]], field="result", value=jsonable_encoder(scraped)
|
||||
)
|
||||
_ = await update_job([job["id"]], field="status", value="Completed")
|
||||
status = "Completed"
|
||||
|
||||
except Exception as e:
|
||||
_ = await update_job([job["id"]], field="status", value="Failed")
|
||||
_ = await update_job([job["id"]], field="result", value=e)
|
||||
LOG.error(f"Exception as occured: {e}\n{traceback.print_exc()}")
|
||||
status = "Failed"
|
||||
finally:
|
||||
job["status"] = status
|
||||
await post_job_complete(
|
||||
job,
|
||||
{
|
||||
"channel": NOTIFICATION_CHANNEL,
|
||||
"webhook_url": NOTIFICATION_WEBHOOK_URL,
|
||||
"scraperr_frontend_url": SCRAPERR_FRONTEND_URL,
|
||||
"email": EMAIL,
|
||||
"to": TO,
|
||||
"smtp_host": SMTP_HOST,
|
||||
"smtp_port": SMTP_PORT,
|
||||
"smtp_user": SMTP_USER,
|
||||
"smtp_password": SMTP_PASSWORD,
|
||||
"use_tls": USE_TLS,
|
||||
},
|
||||
)
|
||||
|
||||
if ffmpeg_proc:
|
||||
ffmpeg_proc.terminate()
|
||||
ffmpeg_proc.wait()
|
||||
|
||||
|
||||
async def main():
|
||||
@@ -47,6 +126,8 @@ async def main():
|
||||
|
||||
init_database()
|
||||
|
||||
RECORDINGS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
while True:
|
||||
await process_job()
|
||||
await asyncio.sleep(5)
|
||||
|
||||
13
api/backend/worker/logger.py
Normal file
13
api/backend/worker/logger.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# STL
|
||||
import logging
|
||||
|
||||
# LOCAL
|
||||
from api.backend.app import LOG_LEVEL
|
||||
|
||||
logging.basicConfig(
|
||||
level=LOG_LEVEL,
|
||||
format="%(levelname)s: %(asctime)s - [%(name)s] - %(message)s",
|
||||
handlers=[logging.StreamHandler()],
|
||||
)
|
||||
|
||||
LOG = logging.getLogger("Job Worker")
|
||||
56
api/backend/worker/post_job_complete/discord_notification.py
Normal file
56
api/backend/worker/post_job_complete/discord_notification.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
|
||||
from api.backend.worker.logger import LOG
|
||||
from api.backend.worker.post_job_complete.models import (
|
||||
PostJobCompleteOptions,
|
||||
JOB_COLOR_MAP,
|
||||
)
|
||||
|
||||
|
||||
def discord_notification(job: dict[str, Any], options: PostJobCompleteOptions):
|
||||
webhook_url = options["webhook_url"]
|
||||
scraperr_frontend_url = options["scraperr_frontend_url"]
|
||||
|
||||
LOG.info(f"Sending discord notification to {webhook_url}")
|
||||
|
||||
embed = {
|
||||
"title": "Job Completed",
|
||||
"description": "Scraping job has been completed.",
|
||||
"color": JOB_COLOR_MAP[job["status"]],
|
||||
"url": f"{scraperr_frontend_url}/jobs?search={job['id']}&type=id",
|
||||
"image": {
|
||||
"url": "https://github.com/jaypyles/Scraperr/raw/master/docs/logo_picture.png",
|
||||
},
|
||||
"author": {
|
||||
"name": "Scraperr",
|
||||
"url": "https://github.com/jaypyles/Scraperr",
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "Status",
|
||||
"value": "Completed",
|
||||
"inline": True,
|
||||
},
|
||||
{
|
||||
"name": "URL",
|
||||
"value": job["url"],
|
||||
"inline": True,
|
||||
},
|
||||
{
|
||||
"name": "ID",
|
||||
"value": job["id"],
|
||||
"inline": False,
|
||||
},
|
||||
{
|
||||
"name": "Options",
|
||||
"value": f"```json\n{json.dumps(job['job_options'], indent=4)}\n```",
|
||||
"inline": False,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
payload = {"embeds": [embed]}
|
||||
requests.post(webhook_url, json=payload)
|
||||
97
api/backend/worker/post_job_complete/email_notifcation.py
Normal file
97
api/backend/worker/post_job_complete/email_notifcation.py
Normal file
@@ -0,0 +1,97 @@
|
||||
import smtplib
|
||||
import ssl
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from api.backend.worker.logger import LOG
|
||||
|
||||
from api.backend.worker.post_job_complete.models import (
|
||||
JOB_COLOR_MAP,
|
||||
PostJobCompleteOptions,
|
||||
)
|
||||
|
||||
|
||||
def send_job_complete_email(
|
||||
job: dict[str, Any],
|
||||
options: PostJobCompleteOptions,
|
||||
):
|
||||
status = job["status"]
|
||||
status_color = JOB_COLOR_MAP.get(status, 0x808080)
|
||||
job_url = job["url"]
|
||||
job_id = job["id"]
|
||||
job_options_json = json.dumps(job["job_options"], indent=4)
|
||||
frontend_url = options["scraperr_frontend_url"]
|
||||
|
||||
subject = "📦 Job Completed - Scraperr Notification"
|
||||
|
||||
html = f"""
|
||||
<html>
|
||||
<body style="font-family: Arial, sans-serif;">
|
||||
<h2 style="color: #{status_color:06x};">✅ Job Completed</h2>
|
||||
<p>Scraping job has been completed successfully.</p>
|
||||
|
||||
<a href="{frontend_url}/jobs?search={job_id}&type=id" target="_blank">
|
||||
<img src="https://github.com/jaypyles/Scraperr/raw/master/docs/logo_picture.png" alt="Scraperr Logo" width="200">
|
||||
</a>
|
||||
|
||||
<h3>Job Info:</h3>
|
||||
<ul>
|
||||
<li><strong>Status:</strong> {status}</li>
|
||||
<li><strong>Job URL:</strong> <a href="{job_url}">{job_url}</a></li>
|
||||
<li><strong>Job ID:</strong> {job_id}</li>
|
||||
</ul>
|
||||
|
||||
<h3>Options:</h3>
|
||||
<pre style="background-color:#f4f4f4; padding:10px; border-radius:5px;">
|
||||
{job_options_json}
|
||||
</pre>
|
||||
|
||||
<h3>View your job here:</h3>
|
||||
<a href="{options['scraperr_frontend_url']}/jobs?search={job_id}&type=id">Scraperr Job</a>
|
||||
|
||||
<p style="font-size: 12px; color: gray;">
|
||||
Sent by <a href="https://github.com/jaypyles/Scraperr" target="_blank">Scraperr</a>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
# Create email
|
||||
message = MIMEMultipart("alternative")
|
||||
message["From"] = options["email"]
|
||||
message["To"] = options["to"]
|
||||
message["Subject"] = subject
|
||||
message.attach(
|
||||
MIMEText(
|
||||
"Job completed. View this email in HTML format for full details.", "plain"
|
||||
)
|
||||
)
|
||||
message.attach(MIMEText(html, "html"))
|
||||
|
||||
context = ssl.create_default_context()
|
||||
|
||||
try:
|
||||
if options["use_tls"]:
|
||||
with smtplib.SMTP(options["smtp_host"], options["smtp_port"]) as server:
|
||||
server.starttls(context=context)
|
||||
server.login(options["smtp_user"], options["smtp_password"])
|
||||
server.sendmail(
|
||||
from_addr=options["email"],
|
||||
to_addrs=options["to"],
|
||||
msg=message.as_string(),
|
||||
)
|
||||
else:
|
||||
with smtplib.SMTP_SSL(
|
||||
options["smtp_host"], options["smtp_port"], context=context
|
||||
) as server:
|
||||
server.login(options["smtp_user"], options["smtp_password"])
|
||||
server.sendmail(
|
||||
from_addr=options["email"],
|
||||
to_addrs=options["to"],
|
||||
msg=message.as_string(),
|
||||
)
|
||||
LOG.info("✅ Email sent successfully!")
|
||||
except Exception as e:
|
||||
LOG.error(f"❌ Failed to send email: {e}")
|
||||
22
api/backend/worker/post_job_complete/models.py
Normal file
22
api/backend/worker/post_job_complete/models.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
class PostJobCompleteOptions(TypedDict):
|
||||
channel: str
|
||||
webhook_url: str
|
||||
scraperr_frontend_url: str
|
||||
email: str
|
||||
to: str
|
||||
smtp_host: str
|
||||
smtp_port: int
|
||||
smtp_user: str
|
||||
smtp_password: str
|
||||
use_tls: bool
|
||||
|
||||
|
||||
JOB_COLOR_MAP = {
|
||||
"Queued": 0x0000FF,
|
||||
"Scraping": 0x0000FF,
|
||||
"Completed": 0x00FF00,
|
||||
"Failed": 0xFF0000,
|
||||
}
|
||||
27
api/backend/worker/post_job_complete/post_job_complete.py
Normal file
27
api/backend/worker/post_job_complete/post_job_complete.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# STL
|
||||
from typing import Any
|
||||
|
||||
# LOCAL
|
||||
from api.backend.worker.post_job_complete.models import PostJobCompleteOptions
|
||||
from api.backend.worker.post_job_complete.email_notifcation import (
|
||||
send_job_complete_email,
|
||||
)
|
||||
from api.backend.worker.post_job_complete.discord_notification import (
|
||||
discord_notification,
|
||||
)
|
||||
|
||||
|
||||
async def post_job_complete(job: dict[str, Any], options: PostJobCompleteOptions):
|
||||
if options["channel"] == "":
|
||||
return
|
||||
|
||||
if not options.values():
|
||||
return
|
||||
|
||||
match options["channel"]:
|
||||
case "discord":
|
||||
discord_notification(job, options)
|
||||
case "email":
|
||||
send_job_complete_email(job, options)
|
||||
case _:
|
||||
raise ValueError(f"Invalid channel: {options['channel']}")
|
||||
23
cypress/e2e/00-setup.cy.ts
Normal file
23
cypress/e2e/00-setup.cy.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
describe("Global setup", () => {
|
||||
it("signs up user once", () => {
|
||||
cy.request({
|
||||
method: "POST",
|
||||
url: "/api/signup",
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
email: "test@test.com",
|
||||
password: "password",
|
||||
full_name: "John Doe",
|
||||
},
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
failOnStatusCode: false,
|
||||
}).then((response) => {
|
||||
if (response.status !== 200 && response.status !== 201) {
|
||||
console.warn("Signup failed:", response.status, response.body);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
101
cypress/e2e/advanced-job-options.cy.ts
Normal file
101
cypress/e2e/advanced-job-options.cy.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import { login } from "../utilities/authentication.utils";
|
||||
import {
|
||||
addCustomHeaders,
|
||||
addElement,
|
||||
addMedia,
|
||||
addSiteMapAction,
|
||||
checkForMedia,
|
||||
cleanUpJobs,
|
||||
enterJobUrl,
|
||||
openAdvancedJobOptions,
|
||||
submitBasicJob,
|
||||
submitJob,
|
||||
waitForJobCompletion,
|
||||
} from "../utilities/job.utilities";
|
||||
import { mockSubmitJob } from "../utilities/mocks";
|
||||
|
||||
describe.only("Advanced Job Options", () => {
|
||||
beforeEach(() => {
|
||||
mockSubmitJob();
|
||||
login();
|
||||
cy.visit("/");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanUpJobs();
|
||||
});
|
||||
|
||||
it.only("should handle custom headers", () => {
|
||||
const customHeaders = {
|
||||
"User-Agent": "Test Agent",
|
||||
"Accept-Language": "en-US",
|
||||
};
|
||||
|
||||
addCustomHeaders(customHeaders);
|
||||
submitBasicJob("https://httpbin.org/headers", "headers", "//pre");
|
||||
|
||||
cy.wait("@submitScrapeJob").then((interception) => {
|
||||
expect(interception.response?.statusCode).to.eq(200);
|
||||
expect(
|
||||
interception.request?.body.data.job_options.custom_headers
|
||||
).to.deep.equal(customHeaders);
|
||||
});
|
||||
|
||||
waitForJobCompletion("https://httpbin.org/headers");
|
||||
});
|
||||
|
||||
it("should handle site map actions", () => {
|
||||
addSiteMapAction("click", "//button[contains(text(), 'Load More')]");
|
||||
addSiteMapAction("input", "//input[@type='search']", "test search");
|
||||
|
||||
submitBasicJob("https://example.com", "content", "//div[@class='content']");
|
||||
|
||||
cy.wait("@submitScrapeJob").then((interception) => {
|
||||
expect(interception.response?.statusCode).to.eq(200);
|
||||
const siteMap = interception.request?.body.data.job_options.site_map;
|
||||
expect(siteMap.actions).to.have.length(2);
|
||||
expect(siteMap.actions[0].type).to.equal("click");
|
||||
expect(siteMap.actions[1].type).to.equal("input");
|
||||
});
|
||||
|
||||
waitForJobCompletion("https://example.com");
|
||||
});
|
||||
|
||||
it("should handle multiple elements", () => {
|
||||
enterJobUrl("https://books.toscrape.com");
|
||||
|
||||
addElement("titles", "//h3");
|
||||
addElement("prices", "//p[@class='price_color']");
|
||||
|
||||
submitJob();
|
||||
|
||||
cy.wait("@submitScrapeJob").then((interception) => {
|
||||
expect(interception.response?.statusCode).to.eq(200);
|
||||
expect(interception.request?.body.data.elements).to.have.length(2);
|
||||
});
|
||||
|
||||
waitForJobCompletion("https://books.toscrape.com");
|
||||
});
|
||||
|
||||
it.only("should handle collecting media", () => {
|
||||
enterJobUrl("https://books.toscrape.com");
|
||||
|
||||
openAdvancedJobOptions();
|
||||
addMedia();
|
||||
|
||||
cy.get("body").type("{esc}");
|
||||
|
||||
addElement("images", "//img");
|
||||
|
||||
submitJob();
|
||||
|
||||
cy.wait("@submitScrapeJob").then((interception) => {
|
||||
expect(interception.response?.statusCode).to.eq(200);
|
||||
expect(interception.request?.body.data.job_options.collect_media).to.be
|
||||
.true;
|
||||
});
|
||||
|
||||
waitForJobCompletion("https://books.toscrape.com");
|
||||
checkForMedia();
|
||||
});
|
||||
});
|
||||
35
cypress/e2e/agent.cy.ts
Normal file
35
cypress/e2e/agent.cy.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { login } from "../utilities/authentication.utils";
|
||||
import {
|
||||
buildAgentJob,
|
||||
cleanUpJobs,
|
||||
submitJob,
|
||||
waitForJobCompletion,
|
||||
} from "../utilities/job.utilities";
|
||||
import { mockSubmitJob } from "../utilities/mocks";
|
||||
|
||||
describe.only("Agent", () => {
|
||||
beforeEach(() => {
|
||||
mockSubmitJob();
|
||||
login();
|
||||
cy.visit("/agent");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanUpJobs();
|
||||
});
|
||||
|
||||
it("should be able to scrape some data", () => {
|
||||
const url = "https://books.toscrape.com";
|
||||
const prompt = "Collect all the links on the page";
|
||||
buildAgentJob(url, prompt);
|
||||
|
||||
submitJob();
|
||||
cy.wait("@submitScrapeJob").then((interception) => {
|
||||
expect(interception.response?.statusCode).to.eq(200);
|
||||
expect(interception.request?.body.data.url).to.eq(url);
|
||||
expect(interception.request?.body.data.prompt).to.eq(prompt);
|
||||
});
|
||||
|
||||
waitForJobCompletion("https://books.toscrape.com");
|
||||
});
|
||||
});
|
||||
@@ -1,60 +1,61 @@
|
||||
describe("Authentication", () => {
|
||||
it("should register", () => {
|
||||
cy.intercept("POST", "/api/signup").as("signup");
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { mockLogin, mockSignup } from "../utilities/mocks";
|
||||
|
||||
cy.visit("/").then(() => {
|
||||
cy.get("button").contains("Login").click();
|
||||
cy.url().should("include", "/login");
|
||||
const mockEmail = faker.internet.email();
|
||||
const mockPassword = faker.internet.password();
|
||||
|
||||
cy.get("form").should("be.visible");
|
||||
cy.get("button")
|
||||
.contains("No Account? Sign up")
|
||||
.should("be.visible")
|
||||
.click();
|
||||
|
||||
cy.get("input[name='email']").type("test@test.com");
|
||||
cy.get("input[name='password']").type("password");
|
||||
cy.get("input[name='fullName']").type("John Doe");
|
||||
cy.get("button[type='submit']").contains("Signup").click();
|
||||
|
||||
cy.wait("@signup").then((interception) => {
|
||||
if (!interception.response) {
|
||||
cy.log("No response received!");
|
||||
throw new Error("signup request did not return a response");
|
||||
}
|
||||
|
||||
cy.log("Response status: " + interception.response.statusCode);
|
||||
cy.log("Response body: " + JSON.stringify(interception.response.body));
|
||||
|
||||
expect(interception.response.statusCode).to.eq(200);
|
||||
});
|
||||
});
|
||||
describe.only("Authentication", () => {
|
||||
beforeEach(() => {
|
||||
cy.visit("/");
|
||||
mockSignup();
|
||||
mockLogin();
|
||||
});
|
||||
|
||||
it("should login", () => {
|
||||
cy.intercept("POST", "/api/token").as("token");
|
||||
it("should register", () => {
|
||||
cy.get("button").contains("Login").click();
|
||||
cy.url().should("include", "/login");
|
||||
|
||||
cy.visit("/").then(() => {
|
||||
cy.get("button")
|
||||
.contains("Login")
|
||||
.click()
|
||||
.then(() => {
|
||||
cy.get("input[name='email']").type("test@test.com");
|
||||
cy.get("input[name='password']").type("password");
|
||||
cy.get("button[type='submit']").contains("Login").click();
|
||||
cy.get("form").should("be.visible");
|
||||
|
||||
cy.wait("@token").then((interception) => {
|
||||
if (!interception.response) {
|
||||
cy.log("No response received!");
|
||||
throw new Error("token request did not return a response");
|
||||
}
|
||||
cy.get("button")
|
||||
.contains("No Account? Sign up")
|
||||
.should("be.visible")
|
||||
.click();
|
||||
|
||||
cy.log("Response status: " + interception.response.statusCode);
|
||||
cy.log("Response body: " + JSON.stringify(interception.response.body));
|
||||
cy.get("input[name='email']").type(mockEmail);
|
||||
cy.get("input[name='password']").type(mockPassword);
|
||||
cy.get("input[name='fullName']").type(faker.person.fullName());
|
||||
cy.get("button[type='submit']").contains("Signup").click();
|
||||
|
||||
expect(interception.response.statusCode).to.eq(200);
|
||||
});
|
||||
});
|
||||
cy.wait("@signup").then((interception) => {
|
||||
if (!interception.response) {
|
||||
throw new Error("signup request did not return a response");
|
||||
}
|
||||
|
||||
expect(interception.response.statusCode).to.eq(200);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should login", () => {
|
||||
cy.intercept("POST", "/api/token").as("token");
|
||||
|
||||
cy.visit("/").then(() => {
|
||||
cy.get("button")
|
||||
.contains("Login")
|
||||
.click()
|
||||
.then(() => {
|
||||
cy.get("input[name='email']").type(mockEmail);
|
||||
cy.get("input[name='password']").type(mockPassword);
|
||||
cy.get("button[type='submit']").contains("Login").click();
|
||||
|
||||
cy.wait("@token").then((interception) => {
|
||||
if (!interception.response) {
|
||||
throw new Error("token request did not return a response");
|
||||
}
|
||||
|
||||
expect(interception.response.statusCode).to.eq(200);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
34
cypress/e2e/chat.cy.ts
Normal file
34
cypress/e2e/chat.cy.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { login } from "../utilities/authentication.utils";
|
||||
import {
|
||||
cleanUpJobs,
|
||||
selectJobFromSelector,
|
||||
submitBasicJob,
|
||||
waitForJobCompletion,
|
||||
} from "../utilities/job.utilities";
|
||||
import { mockLogin } from "../utilities/mocks";
|
||||
|
||||
describe.only("Chat", () => {
|
||||
beforeEach(() => {
|
||||
mockLogin();
|
||||
login();
|
||||
cy.visit("/");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanUpJobs();
|
||||
});
|
||||
|
||||
it.only("should be able to chat", () => {
|
||||
const url = "https://books.toscrape.com";
|
||||
submitBasicJob(url, "test", "//body");
|
||||
waitForJobCompletion(url);
|
||||
|
||||
cy.visit("/chat");
|
||||
selectJobFromSelector();
|
||||
|
||||
cy.get("[data-cy='message-input']").type("Hello");
|
||||
cy.get("[data-cy='send-message']").click();
|
||||
|
||||
cy.get("[data-cy='ai-message']").should("exist");
|
||||
});
|
||||
});
|
||||
@@ -1,34 +1,37 @@
|
||||
import { login } from "../utilities/authentication.utils";
|
||||
import {
|
||||
addElement,
|
||||
cleanUpJobs,
|
||||
enterJobUrl,
|
||||
submitJob,
|
||||
waitForJobCompletion,
|
||||
} from "../utilities/job.utilities";
|
||||
import { mockSubmitJob } from "../utilities/mocks";
|
||||
|
||||
describe.only("Job", () => {
|
||||
it("should create a job", () => {
|
||||
cy.intercept("POST", "/api/submit-scrape-job").as("submitScrapeJob");
|
||||
|
||||
beforeEach(() => {
|
||||
mockSubmitJob();
|
||||
login();
|
||||
cy.visit("/");
|
||||
});
|
||||
|
||||
cy.get('[data-cy="url-input"]').type("https://example.com");
|
||||
cy.get('[data-cy="name-field"]').type("example");
|
||||
cy.get('[data-cy="xpath-field"]').type("//body");
|
||||
cy.get('[data-cy="add-button"]').click();
|
||||
afterEach(() => {
|
||||
cleanUpJobs();
|
||||
});
|
||||
|
||||
cy.contains("Submit").click();
|
||||
it("should create a job", () => {
|
||||
enterJobUrl("https://books.toscrape.com");
|
||||
addElement("body", "//body");
|
||||
submitJob();
|
||||
|
||||
cy.wait("@submitScrapeJob").then((interception) => {
|
||||
if (!interception.response) {
|
||||
cy.log("No response received!");
|
||||
cy.log("Request body: " + JSON.stringify(interception.request?.body));
|
||||
throw new Error("submitScrapeJob request did not return a response");
|
||||
}
|
||||
|
||||
cy.log("Response status: " + interception.response.statusCode);
|
||||
cy.log("Response body: " + JSON.stringify(interception.response.body));
|
||||
|
||||
expect(interception.response.statusCode).to.eq(200);
|
||||
});
|
||||
|
||||
cy.get("li").contains("Previous Jobs").click();
|
||||
|
||||
cy.contains("div", "https://example.com", { timeout: 10000 }).should(
|
||||
"exist"
|
||||
);
|
||||
cy.contains("div", "Completed", { timeout: 20000 }).should("exist");
|
||||
waitForJobCompletion("https://books.toscrape.com");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// ***********************************************************
|
||||
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import './commands'
|
||||
import "./commands";
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
// require('./commands')
|
||||
|
||||
68
cypress/utilities/authentication.utils.ts
Normal file
68
cypress/utilities/authentication.utils.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
export const signup = () => {
|
||||
cy.intercept("POST", "/api/token").as("token");
|
||||
|
||||
cy.visit("/").then(() => {
|
||||
cy.get("button").contains("Login").click();
|
||||
cy.url().should("include", "/login");
|
||||
|
||||
cy.get("form").should("be.visible");
|
||||
cy.get("button")
|
||||
.contains("No Account? Sign up")
|
||||
.should("be.visible")
|
||||
.click();
|
||||
|
||||
cy.get("input[name='email']").type("test@test.com");
|
||||
cy.get("input[name='password']").type("password");
|
||||
cy.get("input[name='fullName']").type("John Doe");
|
||||
cy.get("button[type='submit']").contains("Signup").click();
|
||||
|
||||
cy.wait("@token").then((interception) => {
|
||||
if (!interception.response) {
|
||||
cy.log("No response received!");
|
||||
throw new Error("token request did not return a response");
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const login = () => {
|
||||
cy.intercept("POST", "/api/token").as("token");
|
||||
cy.intercept("GET", "/api/me").as("me");
|
||||
cy.intercept("GET", "/api/check").as("check");
|
||||
|
||||
cy.visit("/").then(() => {
|
||||
cy.get("body").then(() => {
|
||||
cy.get("button")
|
||||
.contains("Login")
|
||||
.click()
|
||||
.then(() => {
|
||||
cy.get("input[name='email']").type("test@test.com");
|
||||
cy.get("input[name='password']").type("password");
|
||||
cy.get("button[type='submit']").contains("Login").click();
|
||||
|
||||
cy.wait("@token").then((interception) => {
|
||||
if (!interception.response) {
|
||||
cy.log("No response received!");
|
||||
throw new Error("token request did not return a response");
|
||||
}
|
||||
});
|
||||
|
||||
cy.wait("@me").then((interception) => {
|
||||
if (!interception.response) {
|
||||
cy.log("No response received!");
|
||||
throw new Error("me request did not return a response");
|
||||
}
|
||||
});
|
||||
|
||||
cy.wait("@check").then((interception) => {
|
||||
if (!interception.response) {
|
||||
cy.log("No response received!");
|
||||
throw new Error("check request did not return a response");
|
||||
}
|
||||
});
|
||||
|
||||
cy.url().should("not.include", "/login");
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
151
cypress/utilities/job.utilities.ts
Normal file
151
cypress/utilities/job.utilities.ts
Normal file
@@ -0,0 +1,151 @@
|
||||
export const cleanUpJobs = () => {
|
||||
cy.intercept("POST", "/api/retrieve").as("retrieve");
|
||||
cy.visit("/jobs");
|
||||
|
||||
cy.wait("@retrieve", { timeout: 15000 });
|
||||
|
||||
cy.get("tbody tr", { timeout: 10000 }).should("have.length.at.least", 1);
|
||||
|
||||
const tryClickSelectAll = (attempt = 1, maxAttempts = 5) => {
|
||||
cy.log(`Attempt ${attempt} to click Select All`);
|
||||
|
||||
cy.get('[data-testid="select-all"]')
|
||||
.closest("button")
|
||||
.then(($btn) => {
|
||||
// Retry if button is disabled
|
||||
if ($btn.is(":disabled") || $btn.css("pointer-events") === "none") {
|
||||
if (attempt < maxAttempts) {
|
||||
cy.wait(1000).then(() =>
|
||||
tryClickSelectAll(attempt + 1, maxAttempts)
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
"Select All button is still disabled after max retries"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Click and then verify if checkbox is checked
|
||||
cy.wrap($btn)
|
||||
.click({ force: true })
|
||||
.then(() => {
|
||||
cy.get("tbody tr")
|
||||
.first()
|
||||
.find("td")
|
||||
.first()
|
||||
.find("input[type='checkbox']")
|
||||
.should("be.checked")
|
||||
.then(() => {
|
||||
cy.log("Select All successful");
|
||||
});
|
||||
});
|
||||
|
||||
// Handle failure case
|
||||
cy.on("fail", () => {
|
||||
cy.log("Error clicking Select All");
|
||||
if (attempt < maxAttempts) {
|
||||
cy.wait(1000).then(() =>
|
||||
tryClickSelectAll(attempt + 1, maxAttempts)
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
"Checkbox was never checked after clicking Select All"
|
||||
);
|
||||
}
|
||||
return false; // Prevent Cypress from failing the test
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
tryClickSelectAll();
|
||||
|
||||
cy.get('[data-testid="DeleteIcon"]', { timeout: 10000 })
|
||||
.closest("button")
|
||||
.should("not.be.disabled")
|
||||
.click();
|
||||
};
|
||||
export const submitBasicJob = (url: string, name: string, xpath: string) => {
|
||||
cy.get('[data-cy="url-input"]').type(url);
|
||||
cy.get('[data-cy="name-field"]').type(name);
|
||||
cy.get('[data-cy="xpath-field"]').type(xpath);
|
||||
cy.get('[data-cy="add-button"]').click();
|
||||
cy.contains("Submit").click();
|
||||
};
|
||||
|
||||
export const waitForJobCompletion = (url: string) => {
|
||||
cy.visit("/jobs");
|
||||
cy.contains("div", url, { timeout: 10000 }).should("exist");
|
||||
cy.contains("div", "Completed", { timeout: 20000 }).should("exist");
|
||||
};
|
||||
|
||||
export const enableMultiPageScraping = () => {
|
||||
cy.get("button").contains("Advanced Job Options").click();
|
||||
cy.get('[data-cy="multi-page-toggle"]').click();
|
||||
cy.get("body").type("{esc}");
|
||||
};
|
||||
|
||||
export const addCustomHeaders = (headers: Record<string, string>) => {
|
||||
cy.get("button").contains("Advanced Job Options").click();
|
||||
cy.get('[name="custom_headers"]').type(JSON.stringify(headers), {
|
||||
parseSpecialCharSequences: false,
|
||||
});
|
||||
cy.get("body").type("{esc}");
|
||||
};
|
||||
|
||||
export const addCustomCookies = (cookies: Record<string, string>) => {
|
||||
cy.get("button").contains("Advanced Job Options").click();
|
||||
cy.get('[name="custom_cookies"]').type(JSON.stringify(cookies));
|
||||
cy.get("body").type("{esc}");
|
||||
};
|
||||
|
||||
export const openAdvancedJobOptions = () => {
|
||||
cy.get("button").contains("Advanced Job Options").click();
|
||||
};
|
||||
|
||||
export const selectJobFromSelector = () => {
|
||||
cy.get("div[id='select-job']").click();
|
||||
cy.get("li[role='option']").click().first();
|
||||
};
|
||||
|
||||
export const addMedia = () => {
|
||||
cy.get('[data-cy="collect-media-checkbox"]').click();
|
||||
};
|
||||
|
||||
export const checkForMedia = () => {
|
||||
cy.visit("/media");
|
||||
selectJobFromSelector();
|
||||
cy.get("[data-testid='media-grid']", { timeout: 10000 }).should("exist");
|
||||
};
|
||||
|
||||
export const addSiteMapAction = (
|
||||
type: "click" | "input",
|
||||
xpath: string,
|
||||
input?: string
|
||||
) => {
|
||||
cy.get("button").contains("Create Site Map").click();
|
||||
cy.get('[data-cy="site-map-select"]').select(type);
|
||||
cy.get('[data-cy="site-map-xpath"]').type(xpath);
|
||||
if (type === "input" && input) {
|
||||
cy.get('[data-cy="site-map-input"]').type(input);
|
||||
}
|
||||
cy.get('[data-cy="add-site-map-action"]').click();
|
||||
};
|
||||
|
||||
export const addElement = (name: string, xpath: string) => {
|
||||
cy.get('[data-cy="name-field"]').type(name);
|
||||
cy.get('[data-cy="xpath-field"]').type(xpath);
|
||||
cy.get('[data-cy="add-button"]').click();
|
||||
};
|
||||
|
||||
export const buildAgentJob = (url: string, prompt: string) => {
|
||||
enterJobUrl(url);
|
||||
cy.get("[data-cy='prompt-input']").type(prompt);
|
||||
};
|
||||
|
||||
export const submitJob = () => {
|
||||
cy.get("button").contains("Submit").click();
|
||||
};
|
||||
|
||||
export const enterJobUrl = (url: string) => {
|
||||
cy.get('[data-cy="url-input"]').type(url);
|
||||
};
|
||||
15
cypress/utilities/mocks.ts
Normal file
15
cypress/utilities/mocks.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export const mockSubmitJob = () => {
|
||||
cy.intercept("POST", "/api/submit-scrape-job").as("submitScrapeJob");
|
||||
};
|
||||
|
||||
export const mockToken = () => {
|
||||
cy.intercept("POST", "/api/token").as("token");
|
||||
};
|
||||
|
||||
export const mockSignup = () => {
|
||||
cy.intercept("POST", "/api/signup").as("signup");
|
||||
};
|
||||
|
||||
export const mockLogin = () => {
|
||||
cy.intercept("POST", "/api/token").as("token");
|
||||
};
|
||||
1
cypress/utilities/utilities.ts
Normal file
1
cypress/utilities/utilities.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./authentication.utils";
|
||||
@@ -1,6 +1,9 @@
|
||||
version: "3"
|
||||
services:
|
||||
scraperr:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/frontend/Dockerfile
|
||||
command: ["npm", "run", "dev"]
|
||||
volumes:
|
||||
- "$PWD/src:/app/src"
|
||||
@@ -10,8 +13,12 @@ services:
|
||||
- "$PWD/package-lock.json:/app/package-lock.json"
|
||||
- "$PWD/tsconfig.json:/app/tsconfig.json"
|
||||
scraperr_api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/api/Dockerfile
|
||||
environment:
|
||||
- LOG_LEVEL=INFO
|
||||
volumes:
|
||||
- "$PWD/api:/project/api"
|
||||
- "$PWD/scraping:/project/scraping"
|
||||
- "$PWD/api:/project/app/api"
|
||||
ports:
|
||||
- "5900:5900"
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
services:
|
||||
scraperr:
|
||||
depends_on:
|
||||
- scraperr_api
|
||||
image: jpyles0524/scraperr:latest
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/frontend/Dockerfile
|
||||
container_name: scraperr
|
||||
command: ["npm", "run", "start"]
|
||||
environment:
|
||||
@@ -18,22 +13,17 @@ services:
|
||||
scraperr_api:
|
||||
init: True
|
||||
image: jpyles0524/scraperr_api:latest
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/api/Dockerfile
|
||||
environment:
|
||||
- LOG_LEVEL=INFO
|
||||
- SECRET_KEY=MRo9PfasPibnqFeK4Oswb6Z+PhFmjzdvxZzwdAkbf/Y= # used to encode authentication tokens (can be a random string)
|
||||
- ALGORITHM=HS256 # authentication encoding algorithm
|
||||
- ACCESS_TOKEN_EXPIRE_MINUTES=600 # access token expire minutes
|
||||
- OPENAI_KEY=${OPENAI_KEY}
|
||||
container_name: scraperr_api
|
||||
ports:
|
||||
- 8000:8000
|
||||
volumes:
|
||||
- "$PWD/data:/project/data"
|
||||
- "$PWD/media:/project/media"
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- "$PWD/data:/project/app/data"
|
||||
- "$PWD/media:/project/app/media"
|
||||
networks:
|
||||
- web
|
||||
|
||||
networks:
|
||||
web:
|
||||
|
||||
@@ -1,36 +1,42 @@
|
||||
# Build python dependencies
|
||||
FROM python:3.10.12-slim as pybuilder
|
||||
|
||||
RUN apt update && apt install -y uvicorn
|
||||
RUN apt-get update && \
|
||||
apt-get install -y curl && \
|
||||
apt-get install -y x11vnc xvfb uvicorn wget gnupg supervisor libgl1 libglx-mesa0 libglx0 vainfo libva-dev libva-glx2 libva-drm2 ffmpeg && \
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh && \
|
||||
apt-get remove -y curl && \
|
||||
apt-get autoremove -y && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN python -m pip --no-cache-dir install pdm
|
||||
RUN pdm config python.use_venv false
|
||||
|
||||
|
||||
WORKDIR /project/app
|
||||
COPY pyproject.toml pdm.lock /project/app/
|
||||
RUN pdm install
|
||||
|
||||
RUN pdm install -v --frozen-lockfile
|
||||
|
||||
RUN pdm run playwright install --with-deps
|
||||
|
||||
RUN pdm run camoufox fetch
|
||||
|
||||
COPY ./api/ /project/app/api
|
||||
|
||||
# Create final image
|
||||
FROM python:3.10.12-slim
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y wget gnupg supervisor
|
||||
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
|
||||
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y google-chrome-stable
|
||||
|
||||
ENV PYTHONPATH=/project/pkgs
|
||||
COPY --from=pybuilder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
|
||||
COPY --from=pybuilder /usr/local/bin /usr/local/bin
|
||||
COPY --from=pybuilder /project/app /project/
|
||||
|
||||
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
WORKDIR /project/
|
||||
WORKDIR /project/app
|
||||
|
||||
RUN mkdir -p /project/app/media
|
||||
RUN mkdir -p /project/app/data
|
||||
RUN touch /project/app/data/database.db
|
||||
|
||||
EXPOSE 5900
|
||||
|
||||
COPY start.sh /project/app/start.sh
|
||||
|
||||
CMD [ "supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf" ]
|
||||
@@ -1,10 +1,14 @@
|
||||
# Build next dependencies
|
||||
FROM node:23.1
|
||||
FROM node:23.1-slim
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
# Copy package files first to leverage Docker cache
|
||||
COPY package.json yarn.lock ./
|
||||
|
||||
# Install dependencies in a separate layer
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
# Copy the rest of the application
|
||||
COPY tsconfig.json /app/tsconfig.json
|
||||
COPY tailwind.config.js /app/tailwind.config.js
|
||||
COPY next.config.mjs /app/next.config.mjs
|
||||
@@ -13,6 +17,7 @@ COPY postcss.config.js /app/postcss.config.js
|
||||
COPY public /app/public
|
||||
COPY src /app/src
|
||||
|
||||
RUN npm run build
|
||||
# Build the application
|
||||
RUN yarn build
|
||||
|
||||
EXPOSE 3000
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 48 KiB |
23
helm/.helmignore
Normal file
23
helm/.helmignore
Normal file
@@ -0,0 +1,23 @@
|
||||
# Patterns to ignore when building packages.
|
||||
# This supports shell glob matching, relative path matching, and
|
||||
# negation (prefixed with !). Only one pattern per line.
|
||||
.DS_Store
|
||||
# Common VCS dirs
|
||||
.git/
|
||||
.gitignore
|
||||
.bzr/
|
||||
.bzrignore
|
||||
.hg/
|
||||
.hgignore
|
||||
.svn/
|
||||
# Common backup files
|
||||
*.swp
|
||||
*.bak
|
||||
*.tmp
|
||||
*.orig
|
||||
*~
|
||||
# Various IDEs
|
||||
.project
|
||||
.idea/
|
||||
*.tmproj
|
||||
.vscode/
|
||||
24
helm/Chart.yaml
Normal file
24
helm/Chart.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
apiVersion: v2
|
||||
name: scraperr
|
||||
description: A Helm chart for Kubernetes
|
||||
|
||||
# A chart can be either an 'application' or a 'library' chart.
|
||||
#
|
||||
# Application charts are a collection of templates that can be packaged into versioned archives
|
||||
# to be deployed.
|
||||
#
|
||||
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
||||
# a dependency of application charts to inject those utilities and functions into the rendering
|
||||
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
||||
type: application
|
||||
|
||||
# This is the chart version. This version number should be incremented each time you make changes
|
||||
# to the chart and its templates, including the app version.
|
||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||
version: 1.1.0
|
||||
|
||||
# This is the version number of the application being deployed. This version number should be
|
||||
# incremented each time you make changes to the application. Versions are not expected to
|
||||
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||
# It is recommended to use it with quotes.
|
||||
appVersion: "1.16.0"
|
||||
56
helm/templates/deployment.yaml
Normal file
56
helm/templates/deployment.yaml
Normal file
@@ -0,0 +1,56 @@
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: scraperr
|
||||
spec:
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: scraperr
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: scraperr
|
||||
spec:
|
||||
containers:
|
||||
- name: scraperr
|
||||
{{ if .Values.scraperr.image.repository }}
|
||||
image: "{{ .Values.scraperr.image.repository }}:{{ .Values.scraperr.image.tag }}"
|
||||
{{ else }}
|
||||
image: "{{ .Chart.Name }}:{{ .Chart.Version }}"
|
||||
{{ end }}
|
||||
imagePullPolicy: {{ .Values.scraperr.image.pullPolicy }}
|
||||
command: {{ .Values.scraperr.containerCommand | toJson }}
|
||||
ports:
|
||||
- containerPort: {{ .Values.scraperr.containerPort }}
|
||||
env: {{ toYaml .Values.scraperr.env | nindent 12 }}
|
||||
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: scraperr-api
|
||||
spec:
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: scraperr-api
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: scraperr-api
|
||||
spec:
|
||||
containers:
|
||||
- name: scraperr-api
|
||||
{{ if .Values.scraperrApi.image.repository }}
|
||||
image: "{{ .Values.scraperrApi.image.repository }}:{{ .Values.scraperrApi.image.tag }}"
|
||||
{{ else }}
|
||||
image: "{{ .Chart.Name }}:{{ .Chart.Version }}"
|
||||
{{ end }}
|
||||
imagePullPolicy: {{ .Values.scraperrApi.image.pullPolicy }}
|
||||
ports:
|
||||
- containerPort: {{ .Values.scraperrApi.containerPort }}
|
||||
env: {{ toYaml .Values.scraperrApi.env | nindent 12 }}
|
||||
volumeMounts: {{ toYaml .Values.scraperrApi.volumeMounts | nindent 12 }}
|
||||
volumes: {{ toYaml .Values.scraperrApi.volumes | nindent 12 }}
|
||||
37
helm/templates/service.yaml
Normal file
37
helm/templates/service.yaml
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: scraperr
|
||||
spec:
|
||||
type: {{ .Values.scraperr.serviceType }}
|
||||
selector:
|
||||
app: scraperr
|
||||
ports:
|
||||
{{- range .Values.scraperr.ports }}
|
||||
- port: {{ .port }}
|
||||
targetPort: {{ .targetPort }}
|
||||
{{- if .nodePort }}
|
||||
nodePort: {{ .nodePort }}
|
||||
{{- end }}
|
||||
protocol: {{ .protocol | default "TCP" }}
|
||||
{{- end }}
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: scraperr-api
|
||||
spec:
|
||||
type: {{ .Values.scraperrApi.serviceType }}
|
||||
selector:
|
||||
app: scraperr-api
|
||||
ports:
|
||||
{{- range .Values.scraperrApi.ports }}
|
||||
- port: {{ .port }}
|
||||
targetPort: {{ .targetPort }}
|
||||
{{- if .nodePort }}
|
||||
nodePort: {{ .nodePort }}
|
||||
{{- end }}
|
||||
protocol: {{ .protocol | default "TCP" }}
|
||||
{{- end }}
|
||||
47
helm/values.yaml
Normal file
47
helm/values.yaml
Normal file
@@ -0,0 +1,47 @@
|
||||
scraperr:
|
||||
image:
|
||||
repository: jpyles0524/scraperr
|
||||
tag: latest
|
||||
pullPolicy: IfNotPresent
|
||||
containerCommand: ["npm", "run","start"]
|
||||
containerPort: 3000
|
||||
serviceType: NodePort
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 3000
|
||||
nodePort: 32300
|
||||
protocol: TCP
|
||||
env:
|
||||
- name: NEXT_PUBLIC_API_URL
|
||||
value: "http://scraperr-api:8000"
|
||||
- name: SERVER_URL
|
||||
value: "http://scraperr-api:8000"
|
||||
|
||||
scraperrApi:
|
||||
image:
|
||||
repository: jpyles0524/scraperr_api
|
||||
tag: latest
|
||||
pullPolicy: IfNotPresent
|
||||
containerPort: 8000
|
||||
serviceType: ClusterIP
|
||||
ports:
|
||||
- port: 8000
|
||||
targetPort: 8000
|
||||
protocol: TCP
|
||||
env:
|
||||
- name: LOG_LEVEL
|
||||
value: "INFO"
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /project/app/data
|
||||
- name: media
|
||||
mountPath: /project/app/media
|
||||
volumes:
|
||||
- name: data
|
||||
hostPath:
|
||||
path: /data/scraperr/data
|
||||
type: DirectoryOrCreate
|
||||
- name: media
|
||||
hostPath:
|
||||
path: /data/scraperr/media
|
||||
replicaCount: 1
|
||||
11371
package-lock.json
generated
11371
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -12,9 +12,11 @@
|
||||
"@minchat/react-chat-ui": "^0.16.2",
|
||||
"@mui/icons-material": "^5.15.3",
|
||||
"@mui/material": "^5.16.0",
|
||||
"@reduxjs/toolkit": "^2.8.2",
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"@types/react": "^18.3.21",
|
||||
"axios": "^1.7.2",
|
||||
"bootstrap": "^5.3.0",
|
||||
"chart.js": "^4.4.3",
|
||||
@@ -30,16 +32,19 @@
|
||||
"react-dom": "^18.3.1",
|
||||
"react-markdown": "^9.0.0",
|
||||
"react-modal-image": "^2.6.0",
|
||||
"react-redux": "^9.2.0",
|
||||
"react-router": "^6.14.1",
|
||||
"react-router-dom": "^6.14.1",
|
||||
"react-spinners": "^0.14.1",
|
||||
"react-toastify": "^11.0.5",
|
||||
"redux-persist": "^6.0.0",
|
||||
"typescript": "^4.9.5",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"dev": "yarn next dev",
|
||||
"build": "yarn next build",
|
||||
"start": "yarn next start",
|
||||
"serve": "serve -s ./dist",
|
||||
"cy:open": "cypress open",
|
||||
"cy:run": "cypress run"
|
||||
@@ -63,6 +68,7 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@faker-js/faker": "^9.8.0",
|
||||
"@types/cypress": "^1.1.6",
|
||||
"@types/js-cookie": "^3.0.6",
|
||||
"autoprefixer": "^10.4.21",
|
||||
|
||||
411
pdm.lock
generated
411
pdm.lock
generated
@@ -5,7 +5,7 @@
|
||||
groups = ["default", "dev"]
|
||||
strategy = ["inherit_metadata"]
|
||||
lock_version = "4.5.0"
|
||||
content_hash = "sha256:1d142e8b44e3a6a04135c54e1967b7c19c5c7ccd6b2ff8ec8bca8792bf961bb9"
|
||||
content_hash = "sha256:1a65c1e288d2c6827fc6866d3bfe6a9b8707b2ca895d488f4a9b11cd579c4359"
|
||||
|
||||
[[metadata.targets]]
|
||||
requires_python = ">=3.10"
|
||||
@@ -457,6 +457,21 @@ files = [
|
||||
{file = "Brotli-1.1.0.tar.gz", hash = "sha256:81de08ac11bcb85841e440c13611c00b67d3bf82698314928d0b676362546724"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "browserforge"
|
||||
version = "1.2.3"
|
||||
requires_python = "<4.0,>=3.8"
|
||||
summary = "Intelligent browser header & fingerprint generator"
|
||||
groups = ["default"]
|
||||
dependencies = [
|
||||
"click",
|
||||
"typing-extensions; python_version < \"3.10\"",
|
||||
]
|
||||
files = [
|
||||
{file = "browserforge-1.2.3-py3-none-any.whl", hash = "sha256:a6c71ed4688b2f1b0bee757ca82ddad0007cbba68a71eca66ca607dde382f132"},
|
||||
{file = "browserforge-1.2.3.tar.gz", hash = "sha256:d5bec6dffd4748b30fbac9f9c1ef33b26c01a23185240bf90011843e174b7ecc"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bs4"
|
||||
version = "0.0.2"
|
||||
@@ -470,6 +485,34 @@ files = [
|
||||
{file = "bs4-0.0.2.tar.gz", hash = "sha256:a48685c58f50fe127722417bae83fe6badf500d54b55f7e39ffe43b798653925"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "camoufox"
|
||||
version = "0.4.11"
|
||||
requires_python = "<4.0,>=3.8"
|
||||
summary = "Wrapper around Playwright to help launch Camoufox"
|
||||
groups = ["default"]
|
||||
dependencies = [
|
||||
"browserforge<2.0.0,>=1.2.1",
|
||||
"click",
|
||||
"language-tags",
|
||||
"lxml",
|
||||
"numpy",
|
||||
"orjson",
|
||||
"platformdirs",
|
||||
"playwright",
|
||||
"pysocks",
|
||||
"pyyaml",
|
||||
"requests",
|
||||
"screeninfo",
|
||||
"tqdm",
|
||||
"typing-extensions",
|
||||
"ua-parser",
|
||||
]
|
||||
files = [
|
||||
{file = "camoufox-0.4.11-py3-none-any.whl", hash = "sha256:83864d434d159a7566990aa6524429a8d1a859cbf84d2f64ef4a9f29e7d2e5ff"},
|
||||
{file = "camoufox-0.4.11.tar.gz", hash = "sha256:0a2c9d24ac5070c104e7c2b125c0a3937f70efa416084ef88afe94c32a72eebe"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2025.1.31"
|
||||
@@ -688,6 +731,58 @@ files = [
|
||||
{file = "cssselect-1.3.0.tar.gz", hash = "sha256:57f8a99424cfab289a1b6a816a43075a4b00948c86b4dcf3ef4ee7e15f7ab0c7"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cython"
|
||||
version = "3.1.0"
|
||||
requires_python = ">=3.8"
|
||||
summary = "The Cython compiler for writing C extensions in the Python language."
|
||||
groups = ["default"]
|
||||
marker = "sys_platform == \"darwin\""
|
||||
files = [
|
||||
{file = "cython-3.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:335982ac0b71a75720b99b980570b9a8416fafd1989ccf4292c0f2e0e1902eac"},
|
||||
{file = "cython-3.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c9389b7941e333a1cc11074556adbf6a9f97ed3de141c1b45cc9f957cd7f7fa2"},
|
||||
{file = "cython-3.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:136c938f3c0fe91bea3eab32751b860ab7587285c5225436b76a98fe933c599a"},
|
||||
{file = "cython-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d722d311fee9f0dc80b17b8f9d1f46311be63b631b7aeed8530bf5f5e8849507"},
|
||||
{file = "cython-3.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:95eb189635a4542f1f8471bcf9756bffdac5294c41d4a4de935c77852d54e992"},
|
||||
{file = "cython-3.1.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:c063146c711751701ad662eefbdf5b396098d646f1239a2f5a6caea2d6707c5d"},
|
||||
{file = "cython-3.1.0-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:d78774a25c221fbda3855acbccb249989a04d334fb4ac8112ab5ffe4f1bcc65e"},
|
||||
{file = "cython-3.1.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:678e204230ece3205c17285383727b9e99097e7a80330fabb75cdd80d1f4c2ee"},
|
||||
{file = "cython-3.1.0-cp310-cp310-win32.whl", hash = "sha256:8029dffafa9ec5e83b6cc28f8b061f158132f2b1e800673716f7b9d9f85f2335"},
|
||||
{file = "cython-3.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:8dbefee67f3c9219cc9d2311e4ebf9f7b930e1db4b6eec2863df0c436e3c78d0"},
|
||||
{file = "cython-3.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c736405078dc376502617eb41c39e223ae176ebd1a4ddc18179d2517bc8c8658"},
|
||||
{file = "cython-3.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1215d3adb4e8691d03e712aed31206d21f387a8003d8de6a574ee75fe6d2e07c"},
|
||||
{file = "cython-3.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:522d4dae1fea71eee5c944fb7a8530de8bdd6df0ccb2bd001d0f75be228eac6c"},
|
||||
{file = "cython-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:462ad6142057e81715ada74e2d24b9a07bf36ae3da72bf973478b5c3e809c26d"},
|
||||
{file = "cython-3.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a8f00cdeb14f004ebeacf946e06bad2e3ed5776af96f5af95f92d822c4ba275f"},
|
||||
{file = "cython-3.1.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:37d62b8b8919126c75769e5470b288d76c83a1645e73c7aca4b7d7aecb3c1234"},
|
||||
{file = "cython-3.1.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:bea0b6bfde7493acb0529fc603abd4b3b13c3bb2fff7a889ae5a8d3ea7dc5a84"},
|
||||
{file = "cython-3.1.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:fe8c1db9ec03d9ef83e33c842c108e892577ade4c5f530c9435beced048e4698"},
|
||||
{file = "cython-3.1.0-cp311-cp311-win32.whl", hash = "sha256:5f6417d378bd11ca55f16e3c1c7c3bf6d7f0a0cc326c46e309fcba46c54ba4f1"},
|
||||
{file = "cython-3.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:dde3726aa5acbe879f849a09606b886491f950cfa993b435e50e9561fdf731c6"},
|
||||
{file = "cython-3.1.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:8f8c4753f6b926046c0cdf6037ba8560f6677730bf0ab9c1db4e0163b4bb30f9"},
|
||||
{file = "cython-3.1.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:db8e15c8eeee529468eab08528c9bf714a94354b34375be6c0c110f6012a4768"},
|
||||
{file = "cython-3.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a46b34defa672268474fbb5541f6297f45df9e4ecc4def6edd6fe1c44bfdb795"},
|
||||
{file = "cython-3.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8818446612461aca3978ebe8e3def817a120d91f85022540843ebe4f24818cd6"},
|
||||
{file = "cython-3.1.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fe401e825b0fbeec75f8cc758c8cf32345c673bdb0edaf9585cd43b9d2798824"},
|
||||
{file = "cython-3.1.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:c96908b302e87e99915b3b66481a976e32b864e95bf054dcd2cb859dffd8cb10"},
|
||||
{file = "cython-3.1.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:cdde5f25fdb8a5d50dbe5d418fe5bfb2260b1acdbd45b788e77b247e9adf2f56"},
|
||||
{file = "cython-3.1.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:fe3320d13cde70fa8b1936e633b9e0fa68720cc61f97aa371d56d0f84fba3e02"},
|
||||
{file = "cython-3.1.0-cp312-cp312-win32.whl", hash = "sha256:d41d17d7cfcfbddf3b7dc0ceddb6361b8e749b0b3c5f8efa40c31c249127fa15"},
|
||||
{file = "cython-3.1.0-cp312-cp312-win_amd64.whl", hash = "sha256:61eb67401bd6c977084fc789812bd40f96be500049adb2bab99921d696ae0c87"},
|
||||
{file = "cython-3.1.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:539828d14fbd95eff135e8dc9e93012f5b018657868f15a69cb475b8784efb9a"},
|
||||
{file = "cython-3.1.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:fd0003171ad84d4812fdb1eb9a4f678ed027e75fbc2b7bef5db482621b72137a"},
|
||||
{file = "cython-3.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4551f9ab91019b6b63cf8b16bf1abb519db67627c31162f604e370e596b8c60c"},
|
||||
{file = "cython-3.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c088ac33f4fa04b3589c4e5cfb8a81e9d9a990405409f9c8bfab0f5a9e8b724f"},
|
||||
{file = "cython-3.1.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8926651830ada313a04284e711c2cf11e4e800ca080e83012418208edd4334a2"},
|
||||
{file = "cython-3.1.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:e03b3280c7ff99fae7b47327a4e2de7e117b069ce9183dc53774069c3e73d1c8"},
|
||||
{file = "cython-3.1.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:0605d364a2cc632c9269990777c2b266611724d1fccaa614fde335c2209b82da"},
|
||||
{file = "cython-3.1.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:856950b7c4282a713bcf4794aaae8f18d4a1ae177d3b63739604c91019ac4117"},
|
||||
{file = "cython-3.1.0-cp313-cp313-win32.whl", hash = "sha256:d6854c89d6c1ff472861376822a9df7a0c62b2be362147d313cf7f10bf230c69"},
|
||||
{file = "cython-3.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:9d6c88e8c86f2c582a2f9b460174ef86d9e01c8bfb12b8f7c44d697242285551"},
|
||||
{file = "cython-3.1.0-py3-none-any.whl", hash = "sha256:4e460bdf1d8742ddf4914959842f2f23ca4934df97f864be799ddf1912acd0ab"},
|
||||
{file = "cython-3.1.0.tar.gz", hash = "sha256:1097dd60d43ad0fff614a57524bfd531b35c13a907d13bee2cc2ec152e6bf4a1"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decorator"
|
||||
version = "5.2.1"
|
||||
@@ -986,6 +1081,60 @@ files = [
|
||||
{file = "frozenlist-1.6.0.tar.gz", hash = "sha256:b99655c32c1c8e06d111e7f41c06c29a5318cb1835df23a45518e02a47c63b68"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "greenlet"
|
||||
version = "3.2.2"
|
||||
requires_python = ">=3.9"
|
||||
summary = "Lightweight in-process concurrent programming"
|
||||
groups = ["default"]
|
||||
files = [
|
||||
{file = "greenlet-3.2.2-cp310-cp310-macosx_11_0_universal2.whl", hash = "sha256:c49e9f7c6f625507ed83a7485366b46cbe325717c60837f7244fc99ba16ba9d6"},
|
||||
{file = "greenlet-3.2.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c3cc1a3ed00ecfea8932477f729a9f616ad7347a5e55d50929efa50a86cb7be7"},
|
||||
{file = "greenlet-3.2.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7c9896249fbef2c615853b890ee854f22c671560226c9221cfd27c995db97e5c"},
|
||||
{file = "greenlet-3.2.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7409796591d879425997a518138889d8d17e63ada7c99edc0d7a1c22007d4907"},
|
||||
{file = "greenlet-3.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7791dcb496ec53d60c7f1c78eaa156c21f402dda38542a00afc3e20cae0f480f"},
|
||||
{file = "greenlet-3.2.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d8009ae46259e31bc73dc183e402f548e980c96f33a6ef58cc2e7865db012e13"},
|
||||
{file = "greenlet-3.2.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:fd9fb7c941280e2c837b603850efc93c999ae58aae2b40765ed682a6907ebbc5"},
|
||||
{file = "greenlet-3.2.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:00cd814b8959b95a546e47e8d589610534cfb71f19802ea8a2ad99d95d702057"},
|
||||
{file = "greenlet-3.2.2-cp310-cp310-win_amd64.whl", hash = "sha256:d0cb7d47199001de7658c213419358aa8937df767936506db0db7ce1a71f4a2f"},
|
||||
{file = "greenlet-3.2.2-cp311-cp311-macosx_11_0_universal2.whl", hash = "sha256:dcb9cebbf3f62cb1e5afacae90761ccce0effb3adaa32339a0670fe7805d8068"},
|
||||
{file = "greenlet-3.2.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bf3fc9145141250907730886b031681dfcc0de1c158f3cc51c092223c0f381ce"},
|
||||
{file = "greenlet-3.2.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:efcdfb9df109e8a3b475c016f60438fcd4be68cd13a365d42b35914cdab4bb2b"},
|
||||
{file = "greenlet-3.2.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:4bd139e4943547ce3a56ef4b8b1b9479f9e40bb47e72cc906f0f66b9d0d5cab3"},
|
||||
{file = "greenlet-3.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:71566302219b17ca354eb274dfd29b8da3c268e41b646f330e324e3967546a74"},
|
||||
{file = "greenlet-3.2.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3091bc45e6b0c73f225374fefa1536cd91b1e987377b12ef5b19129b07d93ebe"},
|
||||
{file = "greenlet-3.2.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:44671c29da26539a5f142257eaba5110f71887c24d40df3ac87f1117df589e0e"},
|
||||
{file = "greenlet-3.2.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:c23ea227847c9dbe0b3910f5c0dd95658b607137614eb821e6cbaecd60d81cc6"},
|
||||
{file = "greenlet-3.2.2-cp311-cp311-win_amd64.whl", hash = "sha256:0a16fb934fcabfdfacf21d79e6fed81809d8cd97bc1be9d9c89f0e4567143d7b"},
|
||||
{file = "greenlet-3.2.2-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:df4d1509efd4977e6a844ac96d8be0b9e5aa5d5c77aa27ca9f4d3f92d3fcf330"},
|
||||
{file = "greenlet-3.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:da956d534a6d1b9841f95ad0f18ace637668f680b1339ca4dcfb2c1837880a0b"},
|
||||
{file = "greenlet-3.2.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9c7b15fb9b88d9ee07e076f5a683027bc3befd5bb5d25954bb633c385d8b737e"},
|
||||
{file = "greenlet-3.2.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:752f0e79785e11180ebd2e726c8a88109ded3e2301d40abced2543aa5d164275"},
|
||||
{file = "greenlet-3.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9ae572c996ae4b5e122331e12bbb971ea49c08cc7c232d1bd43150800a2d6c65"},
|
||||
{file = "greenlet-3.2.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:02f5972ff02c9cf615357c17ab713737cccfd0eaf69b951084a9fd43f39833d3"},
|
||||
{file = "greenlet-3.2.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:4fefc7aa68b34b9224490dfda2e70ccf2131368493add64b4ef2d372955c207e"},
|
||||
{file = "greenlet-3.2.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a31ead8411a027c2c4759113cf2bd473690517494f3d6e4bf67064589afcd3c5"},
|
||||
{file = "greenlet-3.2.2-cp312-cp312-win_amd64.whl", hash = "sha256:b24c7844c0a0afc3ccbeb0b807adeefb7eff2b5599229ecedddcfeb0ef333bec"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313-macosx_11_0_universal2.whl", hash = "sha256:3ab7194ee290302ca15449f601036007873028712e92ca15fc76597a0aeb4c59"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2dc5c43bb65ec3669452af0ab10729e8fdc17f87a1f2ad7ec65d4aaaefabf6bf"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:decb0658ec19e5c1f519faa9a160c0fc85a41a7e6654b3ce1b44b939f8bf1325"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6fadd183186db360b61cb34e81117a096bff91c072929cd1b529eb20dd46e6c5"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1919cbdc1c53ef739c94cf2985056bcc0838c1f217b57647cbf4578576c63825"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3885f85b61798f4192d544aac7b25a04ece5fe2704670b4ab73c2d2c14ab740d"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:85f3e248507125bf4af607a26fd6cb8578776197bd4b66e35229cdf5acf1dfbf"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:1e76106b6fc55fa3d6fe1c527f95ee65e324a13b62e243f77b48317346559708"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313-win_amd64.whl", hash = "sha256:fe46d4f8e94e637634d54477b0cfabcf93c53f29eedcbdeecaf2af32029b4421"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ba30e88607fb6990544d84caf3c706c4b48f629e18853fc6a646f82db9629418"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:055916fafad3e3388d27dd68517478933a97edc2fc54ae79d3bec827de2c64c4"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2593283bf81ca37d27d110956b79e8723f9aa50c4bcdc29d3c0543d4743d2763"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:89c69e9a10670eb7a66b8cef6354c24671ba241f46152dd3eed447f79c29fb5b"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:02a98600899ca1ca5d3a2590974c9e3ec259503b2d6ba6527605fcd74e08e207"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313t-musllinux_1_1_aarch64.whl", hash = "sha256:b50a8c5c162469c3209e5ec92ee4f95c8231b11db6a04db09bbe338176723bb8"},
|
||||
{file = "greenlet-3.2.2-cp313-cp313t-musllinux_1_1_x86_64.whl", hash = "sha256:45f9f4853fb4cc46783085261c9ec4706628f3b57de3e68bae03e8f8b3c0de51"},
|
||||
{file = "greenlet-3.2.2-cp314-cp314-macosx_11_0_universal2.whl", hash = "sha256:9ea5231428af34226c05f927e16fc7f6fa5e39e3ad3cd24ffa48ba53a47f4240"},
|
||||
{file = "greenlet-3.2.2.tar.gz", hash = "sha256:ad053d34421a2debba45aa3cc39acf454acbcd025b3fc1a9f8a0dee237abd485"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h11"
|
||||
version = "0.16.0"
|
||||
@@ -1025,6 +1174,17 @@ files = [
|
||||
{file = "hpack-4.1.0.tar.gz", hash = "sha256:ec5eca154f7056aa06f196a557655c5b009b382873ac8d1e66e79e87535f1dca"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "html2text"
|
||||
version = "2025.4.15"
|
||||
requires_python = ">=3.9"
|
||||
summary = "Turn HTML into equivalent Markdown-structured text."
|
||||
groups = ["default"]
|
||||
files = [
|
||||
{file = "html2text-2025.4.15-py3-none-any.whl", hash = "sha256:00569167ffdab3d7767a4cdf589b7f57e777a5ed28d12907d8c58769ec734acc"},
|
||||
{file = "html2text-2025.4.15.tar.gz", hash = "sha256:948a645f8f0bc3abe7fd587019a2197a12436cd73d0d4908af95bfc8da337588"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "httpcore"
|
||||
version = "1.0.9"
|
||||
@@ -1241,6 +1401,16 @@ files = [
|
||||
{file = "kaitaistruct-0.10.tar.gz", hash = "sha256:a044dee29173d6afbacf27bcac39daf89b654dd418cfa009ab82d9178a9ae52a"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "language-tags"
|
||||
version = "1.2.0"
|
||||
summary = "This project is a Python version of the language-tags Javascript project."
|
||||
groups = ["default"]
|
||||
files = [
|
||||
{file = "language_tags-1.2.0-py3-none-any.whl", hash = "sha256:d815604622242fdfbbfd747b40c31213617fd03734a267f2e39ee4bd73c88722"},
|
||||
{file = "language_tags-1.2.0.tar.gz", hash = "sha256:e934acba3e3dc85f867703eca421847a9ab7b7679b11b5d5cfd096febbf8bde6"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lxml"
|
||||
version = "5.4.0"
|
||||
@@ -1683,7 +1853,6 @@ version = "2.2.5"
|
||||
requires_python = ">=3.10"
|
||||
summary = "Fundamental package for array computing in Python"
|
||||
groups = ["default"]
|
||||
marker = "python_version <= \"3.11\" or python_version >= \"3.12\""
|
||||
files = [
|
||||
{file = "numpy-2.2.5-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:1f4a922da1729f4c40932b2af4fe84909c7a6e167e6e99f71838ce3a29f3fe26"},
|
||||
{file = "numpy-2.2.5-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:b6f91524d31b34f4a5fee24f5bc16dcd1491b668798b6d85585d836c1e633a6a"},
|
||||
@@ -1792,6 +1961,74 @@ files = [
|
||||
{file = "openpyxl-3.1.5.tar.gz", hash = "sha256:cf0e3cf56142039133628b5acffe8ef0c12bc902d2aadd3e0fe5878dc08d1050"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "orjson"
|
||||
version = "3.10.18"
|
||||
requires_python = ">=3.9"
|
||||
summary = "Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy"
|
||||
groups = ["default"]
|
||||
files = [
|
||||
{file = "orjson-3.10.18-cp310-cp310-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl", hash = "sha256:a45e5d68066b408e4bc383b6e4ef05e717c65219a9e1390abc6155a520cac402"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:be3b9b143e8b9db05368b13b04c84d37544ec85bb97237b3a923f076265ec89c"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:9b0aa09745e2c9b3bf779b096fa71d1cc2d801a604ef6dd79c8b1bfef52b2f92"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:53a245c104d2792e65c8d225158f2b8262749ffe64bc7755b00024757d957a13"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f9495ab2611b7f8a0a8a505bcb0f0cbdb5469caafe17b0e404c3c746f9900469"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:73be1cbcebadeabdbc468f82b087df435843c809cd079a565fb16f0f3b23238f"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fe8936ee2679e38903df158037a2f1c108129dee218975122e37847fb1d4ac68"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:7115fcbc8525c74e4c2b608129bef740198e9a120ae46184dac7683191042056"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-musllinux_1_2_armv7l.whl", hash = "sha256:771474ad34c66bc4d1c01f645f150048030694ea5b2709b87d3bda273ffe505d"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:7c14047dbbea52886dd87169f21939af5d55143dad22d10db6a7514f058156a8"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:641481b73baec8db14fdf58f8967e52dc8bda1f2aba3aa5f5c1b07ed6df50b7f"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-win32.whl", hash = "sha256:607eb3ae0909d47280c1fc657c4284c34b785bae371d007595633f4b1a2bbe06"},
|
||||
{file = "orjson-3.10.18-cp310-cp310-win_amd64.whl", hash = "sha256:8770432524ce0eca50b7efc2a9a5f486ee0113a5fbb4231526d414e6254eba92"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl", hash = "sha256:e0a183ac3b8e40471e8d843105da6fbe7c070faab023be3b08188ee3f85719b8"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-macosx_15_0_arm64.whl", hash = "sha256:5ef7c164d9174362f85238d0cd4afdeeb89d9e523e4651add6a5d458d6f7d42d"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:afd14c5d99cdc7bf93f22b12ec3b294931518aa019e2a147e8aa2f31fd3240f7"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:7b672502323b6cd133c4af6b79e3bea36bad2d16bca6c1f645903fce83909a7a"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:51f8c63be6e070ec894c629186b1c0fe798662b8687f3d9fdfa5e401c6bd7679"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3f9478ade5313d724e0495d167083c6f3be0dd2f1c9c8a38db9a9e912cdaf947"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:187aefa562300a9d382b4b4eb9694806e5848b0cedf52037bb5c228c61bb66d4"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9da552683bc9da222379c7a01779bddd0ad39dd699dd6300abaf43eadee38334"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:e450885f7b47a0231979d9c49b567ed1c4e9f69240804621be87c40bc9d3cf17"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:5e3c9cc2ba324187cd06287ca24f65528f16dfc80add48dc99fa6c836bb3137e"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:50ce016233ac4bfd843ac5471e232b865271d7d9d44cf9d33773bcd883ce442b"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:b3ceff74a8f7ffde0b2785ca749fc4e80e4315c0fd887561144059fb1c138aa7"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-win32.whl", hash = "sha256:fdba703c722bd868c04702cac4cb8c6b8ff137af2623bc0ddb3b3e6a2c8996c1"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-win_amd64.whl", hash = "sha256:c28082933c71ff4bc6ccc82a454a2bffcef6e1d7379756ca567c772e4fb3278a"},
|
||||
{file = "orjson-3.10.18-cp311-cp311-win_arm64.whl", hash = "sha256:a6c7c391beaedd3fa63206e5c2b7b554196f14debf1ec9deb54b5d279b1b46f5"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl", hash = "sha256:50c15557afb7f6d63bc6d6348e0337a880a04eaa9cd7c9d569bcb4e760a24753"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-macosx_15_0_arm64.whl", hash = "sha256:356b076f1662c9813d5fa56db7d63ccceef4c271b1fb3dd522aca291375fcf17"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:559eb40a70a7494cd5beab2d73657262a74a2c59aff2068fdba8f0424ec5b39d"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f3c29eb9a81e2fbc6fd7ddcfba3e101ba92eaff455b8d602bf7511088bbc0eae"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6612787e5b0756a171c7d81ba245ef63a3533a637c335aa7fcb8e665f4a0966f"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7ac6bd7be0dcab5b702c9d43d25e70eb456dfd2e119d512447468f6405b4a69c"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9f72f100cee8dde70100406d5c1abba515a7df926d4ed81e20a9730c062fe9ad"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9dca85398d6d093dd41dc0983cbf54ab8e6afd1c547b6b8a311643917fbf4e0c"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:22748de2a07fcc8781a70edb887abf801bb6142e6236123ff93d12d92db3d406"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:3a83c9954a4107b9acd10291b7f12a6b29e35e8d43a414799906ea10e75438e6"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:303565c67a6c7b1f194c94632a4a39918e067bd6176a48bec697393865ce4f06"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:86314fdb5053a2f5a5d881f03fca0219bfdf832912aa88d18676a5175c6916b5"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-win32.whl", hash = "sha256:187ec33bbec58c76dbd4066340067d9ece6e10067bb0cc074a21ae3300caa84e"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-win_amd64.whl", hash = "sha256:f9f94cf6d3f9cd720d641f8399e390e7411487e493962213390d1ae45c7814fc"},
|
||||
{file = "orjson-3.10.18-cp312-cp312-win_arm64.whl", hash = "sha256:3d600be83fe4514944500fa8c2a0a77099025ec6482e8087d7659e891f23058a"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl", hash = "sha256:69c34b9441b863175cc6a01f2935de994025e773f814412030f269da4f7be147"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-macosx_15_0_arm64.whl", hash = "sha256:1ebeda919725f9dbdb269f59bc94f861afbe2a27dce5608cdba2d92772364d1c"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5adf5f4eed520a4959d29ea80192fa626ab9a20b2ea13f8f6dc58644f6927103"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:7592bb48a214e18cd670974f289520f12b7aed1fa0b2e2616b8ed9e069e08595"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f872bef9f042734110642b7a11937440797ace8c87527de25e0c53558b579ccc"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0315317601149c244cb3ecef246ef5861a64824ccbcb8018d32c66a60a84ffbc"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e0da26957e77e9e55a6c2ce2e7182a36a6f6b180ab7189315cb0995ec362e049"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bb70d489bc79b7519e5803e2cc4c72343c9dc1154258adf2f8925d0b60da7c58"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:e9e86a6af31b92299b00736c89caf63816f70a4001e750bda179e15564d7a034"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:c382a5c0b5931a5fc5405053d36c1ce3fd561694738626c77ae0b1dfc0242ca1"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:8e4b2ae732431127171b875cb2668f883e1234711d3c147ffd69fe5be51a8012"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:2d808e34ddb24fc29a4d4041dcfafbae13e129c93509b847b14432717d94b44f"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-win32.whl", hash = "sha256:ad8eacbb5d904d5591f27dee4031e2c1db43d559edb8f91778efd642d70e6bea"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-win_amd64.whl", hash = "sha256:aed411bcb68bf62e85588f2a7e03a6082cc42e5a2796e06e72a962d7c6310b52"},
|
||||
{file = "orjson-3.10.18-cp313-cp313-win_arm64.whl", hash = "sha256:f54c1385a0e6aba2f15a40d703b858bedad36ded0491e55d35d905b2c34a4cc3"},
|
||||
{file = "orjson-3.10.18.tar.gz", hash = "sha256:e8da3947d92123eda795b68228cafe2724815621fe35e8e320a9e9593a4bcd53"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "outcome"
|
||||
version = "1.3.0.post0"
|
||||
@@ -1929,6 +2166,38 @@ files = [
|
||||
{file = "pexpect-4.9.0.tar.gz", hash = "sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "platformdirs"
|
||||
version = "4.3.8"
|
||||
requires_python = ">=3.9"
|
||||
summary = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`."
|
||||
groups = ["default"]
|
||||
files = [
|
||||
{file = "platformdirs-4.3.8-py3-none-any.whl", hash = "sha256:ff7059bb7eb1179e2685604f4aaf157cfd9535242bd23742eadc3c13542139b4"},
|
||||
{file = "platformdirs-4.3.8.tar.gz", hash = "sha256:3d512d96e16bcb959a814c9f348431070822a6496326a4be0911c40b5a74c2bc"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "playwright"
|
||||
version = "1.52.0"
|
||||
requires_python = ">=3.9"
|
||||
summary = "A high-level API to automate web browsers"
|
||||
groups = ["default"]
|
||||
dependencies = [
|
||||
"greenlet<4.0.0,>=3.1.1",
|
||||
"pyee<14,>=13",
|
||||
]
|
||||
files = [
|
||||
{file = "playwright-1.52.0-py3-none-macosx_10_13_x86_64.whl", hash = "sha256:19b2cb9d4794062008a635a99bd135b03ebb782d460f96534a91cb583f549512"},
|
||||
{file = "playwright-1.52.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:0797c0479cbdc99607412a3c486a3a2ec9ddc77ac461259fd2878c975bcbb94a"},
|
||||
{file = "playwright-1.52.0-py3-none-macosx_11_0_universal2.whl", hash = "sha256:7223960b7dd7ddeec1ba378c302d1d09733b8dac438f492e9854c85d3ca7144f"},
|
||||
{file = "playwright-1.52.0-py3-none-manylinux1_x86_64.whl", hash = "sha256:d010124d24a321e0489a8c0d38a3971a7ca7656becea7656c9376bfea7f916d4"},
|
||||
{file = "playwright-1.52.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4173e453c43180acc60fd77ffe1ebee8d0efbfd9986c03267007b9c3845415af"},
|
||||
{file = "playwright-1.52.0-py3-none-win32.whl", hash = "sha256:cd0bdf92df99db6237a99f828e80a6a50db6180ef8d5352fc9495df2c92f9971"},
|
||||
{file = "playwright-1.52.0-py3-none-win_amd64.whl", hash = "sha256:dcbf75101eba3066b7521c6519de58721ea44379eb17a0dafa94f9f1b17f59e4"},
|
||||
{file = "playwright-1.52.0-py3-none-win_arm64.whl", hash = "sha256:9d0085b8de513de5fb50669f8e6677f0252ef95a9a1d2d23ccee9638e71e65cb"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pluggy"
|
||||
version = "1.5.0"
|
||||
@@ -2045,6 +2314,17 @@ files = [
|
||||
{file = "propcache-0.3.1.tar.gz", hash = "sha256:40d980c33765359098837527e18eddefc9a24cea5b45e078a7f3bb5b032c6ecf"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proxy-py"
|
||||
version = "2.4.10"
|
||||
requires_python = ">=3.6"
|
||||
summary = "\\u26a1 Fast \\u2022 \\U0001fab6 Lightweight \\u2022 \\U0001f51f Dependency \\u2022 \\U0001f50c Pluggable \\u2022 \\U0001f608 TLS interception \\u2022 \\U0001f512 DNS-over-HTTPS \\u2022 \\U0001f525 Poor Mans VPN \\u2022 \\u23ea Reverse & \\u23e9 Forward \\u2022 \\U0001f46e\\U0001f3ff Proxy Server framework \\u2022 \\U0001f310 Web Server framework \\u2022 \\u27b5 \\u27b6 \\u27b7 \\u27a0 PubSub framework \\u2022 \\U0001f477 Work acceptor & executor framework."
|
||||
groups = ["default"]
|
||||
files = [
|
||||
{file = "proxy.py-2.4.10-py3-none-any.whl", hash = "sha256:ef3a31f6ef3be6ff78559c0e68198523bfe2fb1e820bb16686750c1bb5baf9e8"},
|
||||
{file = "proxy_py-2.4.10.tar.gz", hash = "sha256:41b9e9d3aae6f80e2304d3726e8e9c583a510d8de224eada53d115f48a63a9ce"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ptyprocess"
|
||||
version = "0.7.0"
|
||||
@@ -2307,6 +2587,41 @@ files = [
|
||||
{file = "pymongo-4.12.0.tar.gz", hash = "sha256:d9f74a5cf3fccdb72211e33e07a6c05ac09cd0d7c99d21db5c2473fcfdd03152"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyobjc-core"
|
||||
version = "11.0"
|
||||
requires_python = ">=3.8"
|
||||
summary = "Python<->ObjC Interoperability Module"
|
||||
groups = ["default"]
|
||||
marker = "sys_platform == \"darwin\""
|
||||
files = [
|
||||
{file = "pyobjc_core-11.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:10866b3a734d47caf48e456eea0d4815c2c9b21856157db5917b61dee06893a1"},
|
||||
{file = "pyobjc_core-11.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:50675c0bb8696fe960a28466f9baf6943df2928a1fd85625d678fa2f428bd0bd"},
|
||||
{file = "pyobjc_core-11.0-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:a03061d4955c62ddd7754224a80cdadfdf17b6b5f60df1d9169a3b1b02923f0b"},
|
||||
{file = "pyobjc_core-11.0-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:c338c1deb7ab2e9436d4175d1127da2eeed4a1b564b3d83b9f3ae4844ba97e86"},
|
||||
{file = "pyobjc_core-11.0-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:b4e9dc4296110f251a4033ff3f40320b35873ea7f876bd29a1c9705bb5e08c59"},
|
||||
{file = "pyobjc_core-11.0.tar.gz", hash = "sha256:63bced211cb8a8fb5c8ff46473603da30e51112861bd02c438fbbbc8578d9a70"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyobjc-framework-cocoa"
|
||||
version = "11.0"
|
||||
requires_python = ">=3.9"
|
||||
summary = "Wrappers for the Cocoa frameworks on macOS"
|
||||
groups = ["default"]
|
||||
marker = "sys_platform == \"darwin\""
|
||||
dependencies = [
|
||||
"pyobjc-core>=11.0",
|
||||
]
|
||||
files = [
|
||||
{file = "pyobjc_framework_Cocoa-11.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:fbc65f260d617d5463c7fb9dbaaffc23c9a4fabfe3b1a50b039b61870b8daefd"},
|
||||
{file = "pyobjc_framework_Cocoa-11.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:3ea7be6e6dd801b297440de02d312ba3fa7fd3c322db747ae1cb237e975f5d33"},
|
||||
{file = "pyobjc_framework_Cocoa-11.0-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:280a577b83c68175a28b2b7138d1d2d3111f2b2b66c30e86f81a19c2b02eae71"},
|
||||
{file = "pyobjc_framework_Cocoa-11.0-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:15b2bd977ed340074f930f1330f03d42912d5882b697d78bd06f8ebe263ef92e"},
|
||||
{file = "pyobjc_framework_Cocoa-11.0-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:5750001db544e67f2b66f02067d8f0da96bb2ef71732bde104f01b8628f9d7ea"},
|
||||
{file = "pyobjc_framework_cocoa-11.0.tar.gz", hash = "sha256:00346a8cb81ad7b017b32ff7bf596000f9faa905807b1bd234644ebd47f692c5"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyopenssl"
|
||||
version = "25.0.0"
|
||||
@@ -2526,6 +2841,52 @@ files = [
|
||||
{file = "pywin32-310-cp313-cp313-win_arm64.whl", hash = "sha256:e308f831de771482b7cf692a1f308f8fca701b2d8f9dde6cc440c7da17e47b33"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyyaml"
|
||||
version = "6.0.2"
|
||||
requires_python = ">=3.8"
|
||||
summary = "YAML parser and emitter for Python"
|
||||
groups = ["default"]
|
||||
files = [
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:0a9a2848a5b7feac301353437eb7d5957887edbf81d56e903999a75a3d743086"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:29717114e51c84ddfba879543fb232a6ed60086602313ca38cce623c1d62cfbf"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8824b5a04a04a047e72eea5cec3bc266db09e35de6bdfe34c9436ac5ee27d237"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7c36280e6fb8385e520936c3cb3b8042851904eba0e58d277dca80a5cfed590b"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ec031d5d2feb36d1d1a24380e4db6d43695f3748343d99434e6f5f9156aaa2ed"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:936d68689298c36b53b29f23c6dbb74de12b4ac12ca6cfe0e047bedceea56180"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:23502f431948090f597378482b4812b0caae32c22213aecf3b55325e049a6c68"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-win32.whl", hash = "sha256:2e99c6826ffa974fe6e27cdb5ed0021786b03fc98e5ee3c5bfe1fd5015f42b99"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:a4d3091415f010369ae4ed1fc6b79def9416358877534caf6a0fdd2146c87a3e"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:cc1c1159b3d456576af7a3e4d1ba7e6924cb39de8f67111c735f6fc832082774"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1e2120ef853f59c7419231f3bf4e7021f1b936f6ebd222406c3b60212205d2ee"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d225db5a45f21e78dd9358e58a98702a0302f2659a3c6cd320564b75b86f47c"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5ac9328ec4831237bec75defaf839f7d4564be1e6b25ac710bd1a96321cc8317"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3ad2a3decf9aaba3d29c8f537ac4b243e36bef957511b4766cb0057d32b0be85"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:ff3824dc5261f50c9b0dfb3be22b4567a6f938ccce4587b38952d85fd9e9afe4"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:797b4f722ffa07cc8d62053e4cff1486fa6dc094105d13fea7b1de7d8bf71c9e"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-win32.whl", hash = "sha256:11d8f3dd2b9c1207dcaf2ee0bbbfd5991f571186ec9cc78427ba5bd32afae4b5"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-win_amd64.whl", hash = "sha256:e10ce637b18caea04431ce14fabcf5c64a1c61ec9c56b071a4b7ca131ca52d44"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:c70c95198c015b85feafc136515252a261a84561b7b1d51e3384e0655ddf25ab"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:ce826d6ef20b1bc864f0a68340c8b3287705cae2f8b4b1d932177dcc76721725"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1f71ea527786de97d1a0cc0eacd1defc0985dcf6b3f17bb77dcfc8c34bec4dc5"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9b22676e8097e9e22e36d6b7bda33190d0d400f345f23d4065d48f4ca7ae0425"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80bab7bfc629882493af4aa31a4cfa43a4c57c83813253626916b8c7ada83476"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:0833f8694549e586547b576dcfaba4a6b55b9e96098b36cdc7ebefe667dfed48"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8b9c7197f7cb2738065c481a0461e50ad02f18c78cd75775628afb4d7137fb3b"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-win32.whl", hash = "sha256:ef6107725bd54b262d6dedcc2af448a266975032bc85ef0172c5f059da6325b4"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:7e7401d0de89a9a855c839bc697c079a4af81cf878373abd7dc625847d25cbd8"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:50187695423ffe49e2deacb8cd10510bc361faac997de9efef88badc3bb9e2d1"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ffe8360bab4910ef1b9e87fb812d8bc0a308b0d0eef8c8f44e0254ab3b07133"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:17e311b6c678207928d649faa7cb0d7b4c26a0ba73d41e99c4fff6b6c3276484"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70b189594dbe54f75ab3a1acec5f1e3faa7e8cf2f1e08d9b561cb41b845f69d5"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:41e4e3953a79407c794916fa277a82531dd93aad34e29c2a514c2c0c5fe971cc"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:68ccc6023a3400877818152ad9a1033e3db8625d899c72eacb5a668902e4d652"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-win32.whl", hash = "sha256:bc2fa7c6b47d6bc618dd7fb02ef6fdedb1090ec036abab80d4681424b84c1183"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563"},
|
||||
{file = "pyyaml-6.0.2.tar.gz", hash = "sha256:d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "requests"
|
||||
version = "2.32.3"
|
||||
@@ -2605,9 +2966,25 @@ files = [
|
||||
{file = "s3transfer-0.12.0.tar.gz", hash = "sha256:8ac58bc1989a3fdb7c7f3ee0918a66b160d038a147c7b5db1500930a607e9a1c"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "screeninfo"
|
||||
version = "0.8.1"
|
||||
requires_python = ">=3.6.2,<4.0.0"
|
||||
summary = "Fetch location and size of physical screens."
|
||||
groups = ["default"]
|
||||
dependencies = [
|
||||
"Cython; sys_platform == \"darwin\"",
|
||||
"dataclasses; python_version < \"3.7\"",
|
||||
"pyobjc-framework-Cocoa; sys_platform == \"darwin\"",
|
||||
]
|
||||
files = [
|
||||
{file = "screeninfo-0.8.1-py3-none-any.whl", hash = "sha256:e97d6b173856edcfa3bd282f81deb528188aff14b11ec3e195584e7641be733c"},
|
||||
{file = "screeninfo-0.8.1.tar.gz", hash = "sha256:9983076bcc7e34402a1a9e4d7dabf3729411fd2abb3f3b4be7eba73519cd2ed1"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "selenium"
|
||||
version = "4.31.0"
|
||||
version = "4.32.0"
|
||||
requires_python = ">=3.9"
|
||||
summary = "Official Python bindings for Selenium WebDriver"
|
||||
groups = ["default"]
|
||||
@@ -2620,8 +2997,8 @@ dependencies = [
|
||||
"websocket-client~=1.8",
|
||||
]
|
||||
files = [
|
||||
{file = "selenium-4.31.0-py3-none-any.whl", hash = "sha256:7b8b8d5e424d7133cb7aa656263b19ac505ec26d65c0f921a696e7e2c5ccd95b"},
|
||||
{file = "selenium-4.31.0.tar.gz", hash = "sha256:441cffc436a2e6659fe3cfb012692435652efd38b0d368d16f661a5db47825f5"},
|
||||
{file = "selenium-4.32.0-py3-none-any.whl", hash = "sha256:c4d9613f8a45693d61530c9660560fadb52db7d730237bc788ddedf442391f97"},
|
||||
{file = "selenium-4.32.0.tar.gz", hash = "sha256:b9509bef4056f4083772abb1ae19ff57247d617a29255384b26be6956615b206"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2912,6 +3289,30 @@ files = [
|
||||
{file = "tzlocal-5.3.1.tar.gz", hash = "sha256:cceffc7edecefea1f595541dbd6e990cb1ea3d19bf01b2809f362a03dd7921fd"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ua-parser"
|
||||
version = "1.0.1"
|
||||
requires_python = ">=3.9"
|
||||
summary = "Python port of Browserscope's user agent parser"
|
||||
groups = ["default"]
|
||||
dependencies = [
|
||||
"ua-parser-builtins",
|
||||
]
|
||||
files = [
|
||||
{file = "ua_parser-1.0.1-py3-none-any.whl", hash = "sha256:b059f2cb0935addea7e551251cbbf42e9a8872f86134163bc1a4f79e0945ffea"},
|
||||
{file = "ua_parser-1.0.1.tar.gz", hash = "sha256:f9d92bf19d4329019cef91707aecc23c6d65143ad7e29a233f0580fb0d15547d"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ua-parser-builtins"
|
||||
version = "0.18.0.post1"
|
||||
requires_python = ">=3.9"
|
||||
summary = "Precompiled rules for User Agent Parser"
|
||||
groups = ["default"]
|
||||
files = [
|
||||
{file = "ua_parser_builtins-0.18.0.post1-py3-none-any.whl", hash = "sha256:eb4f93504040c3a990a6b0742a2afd540d87d7f9f05fd66e94c101db1564674d"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "2.4.0"
|
||||
|
||||
@@ -16,7 +16,6 @@ dependencies = [
|
||||
"lxml-stubs>=0.5.1",
|
||||
"fake-useragent>=1.5.1",
|
||||
"requests-html>=0.10.0",
|
||||
"selenium>=4.22.0",
|
||||
"webdriver-manager>=4.0.1",
|
||||
"pydantic[email]>=2.9.2",
|
||||
"pandas>=2.2.2",
|
||||
@@ -40,6 +39,10 @@ dependencies = [
|
||||
"python-multipart>=0.0.1",
|
||||
"bcrypt==4.0.1",
|
||||
"apscheduler>=3.11.0",
|
||||
"playwright>=1.52.0",
|
||||
"camoufox>=0.4.11",
|
||||
"html2text>=2025.4.15",
|
||||
"proxy-py>=2.4.10",
|
||||
]
|
||||
requires-python = ">=3.10"
|
||||
readme = "README.md"
|
||||
@@ -96,9 +99,9 @@ strictSetInference = true
|
||||
|
||||
|
||||
[tool.isort]
|
||||
length_sort = "1"
|
||||
length_sort = true
|
||||
profile = "black"
|
||||
sections = "STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER"
|
||||
sections = ["STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
|
||||
import_heading_stdlib = "STL"
|
||||
import_heading_thirdparty = "PDM"
|
||||
import_heading_firstparty = "LOCAL"
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import React from "react";
|
||||
|
||||
export const Chat = () => {
|
||||
return <h1>Chat</h1>;
|
||||
};
|
||||
@@ -1,133 +0,0 @@
|
||||
import React, { useState, useEffect, Dispatch, useRef } from "react";
|
||||
import { Job } from "../../types";
|
||||
import { fetchJobs } from "../../lib";
|
||||
import Box from "@mui/material/Box";
|
||||
import InputLabel from "@mui/material/InputLabel";
|
||||
import FormControl from "@mui/material/FormControl";
|
||||
import Select from "@mui/material/Select";
|
||||
import Popover from "@mui/material/Popover";
|
||||
import { Typography, MenuItem, useTheme } from "@mui/material";
|
||||
import { SxProps } from "@mui/material";
|
||||
|
||||
interface Props {
|
||||
sxProps: SxProps;
|
||||
setSelectedJob: Dispatch<React.SetStateAction<Job | null>>;
|
||||
selectedJob: Job | null;
|
||||
setJobs: Dispatch<React.SetStateAction<Job[]>>;
|
||||
jobs: Job[];
|
||||
}
|
||||
|
||||
export const JobSelector = ({
|
||||
sxProps,
|
||||
selectedJob,
|
||||
setSelectedJob,
|
||||
setJobs,
|
||||
jobs,
|
||||
}: Props) => {
|
||||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
||||
const [popoverJob, setPopoverJob] = useState<Job | null>(null);
|
||||
const theme = useTheme();
|
||||
|
||||
const handlePopoverOpen = (
|
||||
event: React.MouseEvent<HTMLElement>,
|
||||
job: Job
|
||||
) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
setPopoverJob(job);
|
||||
};
|
||||
|
||||
const handlePopoverClose = () => {
|
||||
setAnchorEl(null);
|
||||
setPopoverJob(null);
|
||||
};
|
||||
|
||||
const open = Boolean(anchorEl);
|
||||
|
||||
return (
|
||||
<Box sx={sxProps}>
|
||||
<FormControl fullWidth>
|
||||
{jobs.length ? (
|
||||
<>
|
||||
<InputLabel id="select-job">Job</InputLabel>
|
||||
<Select
|
||||
labelId="select-job"
|
||||
id="select-job"
|
||||
value={selectedJob?.id || ""}
|
||||
label="Job"
|
||||
onChange={(e) => {
|
||||
setSelectedJob(
|
||||
jobs.find((job) => job.id === e.target.value) || null
|
||||
);
|
||||
}}
|
||||
>
|
||||
{jobs.map((job) => (
|
||||
<MenuItem
|
||||
key={job.id}
|
||||
value={job.id}
|
||||
aria-owns={open ? "mouse-over-popover" : undefined}
|
||||
aria-haspopup="true"
|
||||
onMouseEnter={(e) => handlePopoverOpen(e, job)}
|
||||
onMouseLeave={handlePopoverClose}
|
||||
onClick={handlePopoverClose}
|
||||
>
|
||||
{job.id}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
</>
|
||||
) : null}
|
||||
</FormControl>
|
||||
<Popover
|
||||
id="mouse-over-popover"
|
||||
sx={{
|
||||
pointerEvents: "none",
|
||||
padding: 0,
|
||||
}}
|
||||
open={open}
|
||||
anchorEl={anchorEl}
|
||||
anchorOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "left",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "left",
|
||||
}}
|
||||
onClose={handlePopoverClose}
|
||||
>
|
||||
{popoverJob && (
|
||||
<Box
|
||||
sx={{
|
||||
border:
|
||||
theme.palette.mode === "light"
|
||||
? "2px solid black"
|
||||
: "2px solid white",
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="body1"
|
||||
sx={{ paddingLeft: 1, paddingRight: 1 }}
|
||||
>
|
||||
{popoverJob.url}
|
||||
</Typography>
|
||||
<div className="flex flex-row w-full justify-end mb-1">
|
||||
<Typography
|
||||
variant="body2"
|
||||
sx={{
|
||||
paddingLeft: 1,
|
||||
paddingRight: 1,
|
||||
color: theme.palette.mode === "dark" ? "#d3d7e6" : "#5b5d63",
|
||||
fontStyle: "italic",
|
||||
}}
|
||||
>
|
||||
{popoverJob.time_created
|
||||
? new Date(popoverJob.time_created).toLocaleString()
|
||||
: "Unknown"}
|
||||
</Typography>
|
||||
</div>
|
||||
</Box>
|
||||
)}
|
||||
</Popover>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./Chat";
|
||||
export * from "./JobSelector";
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Box, Link, Typography } from "@mui/material";
|
||||
import { SetStateAction, Dispatch, useState } from "react";
|
||||
import { AdvancedJobOptionsDialog } from "./dialog/advanced-job-options-dialog";
|
||||
import { RawJobOptions } from "@/types";
|
||||
|
||||
export type AdvancedJobOptionsProps = {
|
||||
jobOptions: RawJobOptions;
|
||||
setJobOptions: Dispatch<SetStateAction<RawJobOptions>>;
|
||||
multiPageScrapeEnabled?: boolean;
|
||||
};
|
||||
|
||||
export const AdvancedJobOptions = ({
|
||||
jobOptions,
|
||||
setJobOptions,
|
||||
multiPageScrapeEnabled = true,
|
||||
}: AdvancedJobOptionsProps) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<Box sx={{ mb: 2 }}>
|
||||
<Link
|
||||
component="button"
|
||||
variant="body2"
|
||||
onClick={() => setOpen(true)}
|
||||
sx={{
|
||||
textDecoration: "none",
|
||||
color: "primary.main",
|
||||
"&:hover": {
|
||||
color: "primary.dark",
|
||||
textDecoration: "underline",
|
||||
},
|
||||
paddingLeft: 1,
|
||||
display: "inline-flex",
|
||||
alignItems: "center",
|
||||
gap: 0.5,
|
||||
}}
|
||||
>
|
||||
<Typography variant="body2">Advanced Job Options</Typography>
|
||||
</Link>
|
||||
|
||||
<AdvancedJobOptionsDialog
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
jobOptions={jobOptions}
|
||||
setJobOptions={setJobOptions}
|
||||
multiPageScrapeEnabled={multiPageScrapeEnabled}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,295 @@
|
||||
import { ExpandedTableInput } from "@/components/common/expanded-table-input";
|
||||
import { RawJobOptions } from "@/types";
|
||||
import {
|
||||
Code as CodeIcon,
|
||||
ExpandMore as ExpandMoreIcon,
|
||||
InfoOutlined,
|
||||
Settings,
|
||||
} from "@mui/icons-material";
|
||||
import {
|
||||
Accordion,
|
||||
AccordionDetails,
|
||||
AccordionSummary,
|
||||
Box,
|
||||
Checkbox,
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
Divider,
|
||||
FormControl,
|
||||
FormControlLabel,
|
||||
FormGroup,
|
||||
IconButton,
|
||||
TextField,
|
||||
Tooltip,
|
||||
Typography,
|
||||
useTheme,
|
||||
} from "@mui/material";
|
||||
import { Dispatch, SetStateAction, useEffect, useState } from "react";
|
||||
|
||||
export type AdvancedJobOptionsDialogProps = {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
jobOptions: RawJobOptions;
|
||||
setJobOptions: Dispatch<SetStateAction<RawJobOptions>>;
|
||||
multiPageScrapeEnabled?: boolean;
|
||||
};
|
||||
|
||||
export const AdvancedJobOptionsDialog = ({
|
||||
open,
|
||||
onClose,
|
||||
jobOptions,
|
||||
setJobOptions,
|
||||
multiPageScrapeEnabled = true,
|
||||
}: AdvancedJobOptionsDialogProps) => {
|
||||
const theme = useTheme();
|
||||
const [localJobOptions, setLocalJobOptions] =
|
||||
useState<RawJobOptions>(jobOptions);
|
||||
|
||||
// Update local state when prop changes
|
||||
useEffect(() => {
|
||||
setLocalJobOptions(jobOptions);
|
||||
}, [jobOptions]);
|
||||
|
||||
const handleMultiPageScrapeChange = () => {
|
||||
setLocalJobOptions((prevJobOptions) => ({
|
||||
...prevJobOptions,
|
||||
multi_page_scrape: !prevJobOptions.multi_page_scrape,
|
||||
}));
|
||||
};
|
||||
|
||||
const handleProxiesChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setLocalJobOptions((prevJobOptions) => ({
|
||||
...prevJobOptions,
|
||||
proxies: e.target.value,
|
||||
}));
|
||||
};
|
||||
|
||||
const handleCollectMediaChange = () => {
|
||||
setLocalJobOptions((prevJobOptions) => ({
|
||||
...prevJobOptions,
|
||||
collect_media: !prevJobOptions.collect_media,
|
||||
}));
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
// Save the local state back to the parent before closing
|
||||
setJobOptions(localJobOptions);
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
maxWidth="md"
|
||||
fullWidth
|
||||
PaperProps={{
|
||||
sx: {
|
||||
borderRadius: 2,
|
||||
boxShadow: "0 8px 32px rgba(0, 0, 0, 0.1)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<DialogTitle
|
||||
sx={{
|
||||
borderBottom: `1px solid ${theme.palette.divider}`,
|
||||
backgroundColor: theme.palette.background.default,
|
||||
color: theme.palette.primary.contrastText,
|
||||
borderRadius: 2,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
padding: "1rem 2rem",
|
||||
marginRight: 2,
|
||||
marginLeft: 2,
|
||||
}}
|
||||
>
|
||||
<Typography variant="h6" component="div">
|
||||
Advanced Job Options
|
||||
</Typography>
|
||||
<Settings
|
||||
sx={{
|
||||
color: theme.palette.primary.contrastText,
|
||||
}}
|
||||
/>
|
||||
</DialogTitle>
|
||||
|
||||
<DialogContent
|
||||
sx={{ padding: 3, overflowY: "auto", marginTop: 2, height: "60rem" }}
|
||||
>
|
||||
<FormControl fullWidth>
|
||||
<Box sx={{ mb: 3 }}>
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
sx={{
|
||||
mb: 1,
|
||||
fontWeight: "bold",
|
||||
color: theme.palette.text.primary,
|
||||
}}
|
||||
>
|
||||
Collection Options
|
||||
</Typography>
|
||||
<Divider sx={{ mb: 2, backgroundColor: theme.palette.divider }} />
|
||||
|
||||
<FormGroup row sx={{ gap: 4, mb: 1 }}>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={localJobOptions.multi_page_scrape}
|
||||
onChange={handleMultiPageScrapeChange}
|
||||
disabled={!multiPageScrapeEnabled}
|
||||
/>
|
||||
}
|
||||
label={
|
||||
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||
<Typography>Multi Page Scrape</Typography>
|
||||
<Tooltip
|
||||
title={
|
||||
multiPageScrapeEnabled
|
||||
? "Enable crawling through multiple pages"
|
||||
: "Multi page scrape is disabled"
|
||||
}
|
||||
>
|
||||
<IconButton size="small">
|
||||
<InfoOutlined fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={localJobOptions.collect_media}
|
||||
onChange={handleCollectMediaChange}
|
||||
data-cy="collect-media-checkbox"
|
||||
/>
|
||||
}
|
||||
label={
|
||||
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||
<Typography>Collect Media</Typography>
|
||||
<Tooltip title="Download images and other media">
|
||||
<IconButton size="small">
|
||||
<InfoOutlined fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
}
|
||||
/>
|
||||
</FormGroup>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ mb: 3 }}>
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
sx={{
|
||||
mb: 1,
|
||||
fontWeight: "bold",
|
||||
color: theme.palette.text.primary,
|
||||
}}
|
||||
>
|
||||
Custom Options
|
||||
</Typography>
|
||||
<Divider sx={{ mb: 2, backgroundColor: theme.palette.divider }} />
|
||||
|
||||
{/* Proxies Section */}
|
||||
<Accordion
|
||||
defaultExpanded
|
||||
elevation={0}
|
||||
sx={{
|
||||
mb: 2,
|
||||
border: `1px solid ${theme.palette.divider}`,
|
||||
"&:before": { display: "none" },
|
||||
borderRadius: 1,
|
||||
overflow: "hidden",
|
||||
padding: 1,
|
||||
}}
|
||||
>
|
||||
<AccordionSummary
|
||||
expandIcon={<ExpandMoreIcon />}
|
||||
sx={{
|
||||
backgroundColor: theme.palette.background.paper,
|
||||
borderBottom: `1px solid ${theme.palette.divider}`,
|
||||
"&.Mui-expanded": {
|
||||
borderBottom: `1px solid ${theme.palette.divider}`,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.5rem",
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
sx={{
|
||||
fontWeight: 500,
|
||||
color: theme.palette.text.primary,
|
||||
}}
|
||||
>
|
||||
Proxies
|
||||
</Typography>
|
||||
|
||||
<Tooltip title="Comma separated list of proxies that should follow Playwright proxy format">
|
||||
<InfoOutlined fontSize="small" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
</Box>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails
|
||||
sx={{ p: 2, backgroundColor: theme.palette.background.default }}
|
||||
>
|
||||
<TextField
|
||||
placeholder='Proxies ([{"server": "proxy.example.com:8080", "username": "username", "password": "password"}])'
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={localJobOptions.proxies}
|
||||
onChange={handleProxiesChange}
|
||||
InputProps={{
|
||||
startAdornment: (
|
||||
<CodeIcon
|
||||
sx={{ color: theme.palette.text.secondary, mr: 1 }}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
|
||||
{/* Custom Headers Section */}
|
||||
<ExpandedTableInput
|
||||
label="Custom Headers"
|
||||
placeholder='{"User-Agent": "CustomAgent", "Accept": "*/*"}'
|
||||
urlParam="custom_headers"
|
||||
name="custom_headers"
|
||||
onChange={(value) => {
|
||||
setLocalJobOptions((prevJobOptions) => ({
|
||||
...prevJobOptions,
|
||||
custom_headers: value,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Custom Cookies Section */}
|
||||
<ExpandedTableInput
|
||||
label="Custom Cookies"
|
||||
placeholder='[{"name": "value", "name2": "value2"}]'
|
||||
urlParam="custom_cookies"
|
||||
name="custom_cookies"
|
||||
onChange={(value) => {
|
||||
setLocalJobOptions((prevJobOptions) => ({
|
||||
...prevJobOptions,
|
||||
custom_cookies: value,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
</FormControl>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./advanced-job-options-dialog";
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user