diff --git a/scrapegraph-js/CODE_OF_CONDUCT.md b/scrapegraph-js/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..237eaed --- /dev/null +++ b/scrapegraph-js/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +mvincig11@gmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/scrapegraph-js/CONTRIBUTING.MD b/scrapegraph-js/CONTRIBUTING.MD new file mode 100644 index 0000000..aab0da0 --- /dev/null +++ b/scrapegraph-js/CONTRIBUTING.MD @@ -0,0 +1,83 @@ +# Contributing to ScrapeGraphAI + +Thank you for your interest in contributing to **ScrapeGraphAI**! We welcome contributions from the community to help improve and grow the project. This document outlines the guidelines and steps for contributing. + +## Table of Contents + +- [Getting Started](#getting-started) +- [Contributing Guidelines](#contributing-guidelines) +- [Code Style](#code-style) +- [Submitting a Pull Request](#submitting-a-pull-request) +- [Reporting Issues](#reporting-issues) +- [License](#license) + +## Getting Started + +To get started with contributing, follow these steps: + +1. Fork the repository on GitHub **(FROM pre/beta branch)**. +2. Clone your forked repository to your local machine. +3. Install the necessary dependencies from requirements.txt or via pyproject.toml as you prefere :). +4. Make your changes or additions. +5. Test your changes thoroughly. +6. Commit your changes with descriptive commit messages. +7. Push your changes to your forked repository. +8. Submit a pull request to the pre/beta branch. + +N.B All the pull request to the main branch will be rejected! + +## Contributing Guidelines + +Please adhere to the following guidelines when contributing to ScrapeGraphAI: + +- Follow the code style and formatting guidelines specified in the [Code Style](#code-style) section. +- Make sure your changes are well-documented and include any necessary updates to the project's documentation and requirements if needed. +- Write clear and concise commit messages that describe the purpose of your changes and the last commit before the pull request has to follow the following format: + - `feat: Add new feature` + - `fix: Correct issue with existing feature` + - `docs: Update documentation` + - `style: Improve formatting and style` + - `refactor: Restructure code` + - `test: Add or update tests` + - `perf: Improve performance` +- Be respectful and considerate towards other contributors and maintainers. + +## Code Style + +Please make sure to format your code accordingly before submitting a pull request. + +### Python + +- [Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/) +- [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html) +- [The Hitchhiker's Guide to Python](https://docs.python-guide.org/writing/style/) +- [Pylint style of code for the documentation](https://pylint.pycqa.org/en/1.6.0/tutorial.html) + +## Submitting a Pull Request + +To submit your changes for review, please follow these steps: + +1. Ensure that your changes are pushed to your forked repository. +2. Go to the main repository on GitHub and navigate to the "Pull Requests" tab. +3. Click on the "New Pull Request" button. +4. Select your forked repository and the branch containing your changes. +5. Provide a descriptive title and detailed description for your pull request. +6. Reviewers will provide feedback and discuss any necessary changes. +7. Once your pull request is approved, it will be merged into the pre/beta branch. + +## Reporting Issues + +If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository. Provide a clear and detailed description of the problem or suggestion, along with any relevant information or steps to reproduce the issue. + +## License + +ScrapeGraphAI is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for more information. +By contributing to this project, you agree to license your contributions under the same license. + +ScrapeGraphAI uses code from the Langchain +frameworks. You find their original licenses below. + +LANGCHAIN LICENSE +https://github.com/langchain-ai/langchain/blob/master/LICENSE + +Can't wait to see your contributions! :smile: diff --git a/scrapegraph-js/LICENSE b/scrapegraph-js/LICENSE new file mode 100644 index 0000000..70e3834 --- /dev/null +++ b/scrapegraph-js/LICENSE @@ -0,0 +1,7 @@ +Copyright 2024 Scrapgraph-ai team + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/scrapegraph-js/examples/getCredits_example.js b/scrapegraph-js/examples/getCredits_example.js index b4bf470..0a85fdb 100644 --- a/scrapegraph-js/examples/getCredits_example.js +++ b/scrapegraph-js/examples/getCredits_example.js @@ -2,11 +2,11 @@ import { getCredits } from "scrapegraph-sdk"; import 'dotenv/config'; try { - const apiKey = process.env.SGAI_APIKEY; + const apiKey = process.env.SGAI_APIKEY; - const myCredit = await getCredits(apiKey); + const myCredit = await getCredits(apiKey); - console.log(myCredit) + console.log(myCredit) } catch (error) { - console.error(error) + console.error(error) } \ No newline at end of file diff --git a/scrapegraph-js/examples/getSmartScraperRequest_example.js b/scrapegraph-js/examples/getSmartScraperRequest_example.js index e0f362c..6321971 100644 --- a/scrapegraph-js/examples/getSmartScraperRequest_example.js +++ b/scrapegraph-js/examples/getSmartScraperRequest_example.js @@ -2,12 +2,12 @@ import { getSmartScraperRequest } from "scrapegraph-sdk"; import 'dotenv/config'; try { - const apiKey = process.env.SGAI_APIKEY; - const requestId = "3fa85f64-5717-4562-b3fc-2c963f66afa6" + const apiKey = process.env.SGAI_APIKEY; + const requestId = '3fa85f64-5717-4562-b3fc-2c963f66afa6' - const requestInfo = await getSmartScraperRequest(apiKey, requestId); + const requestInfo = await getSmartScraperRequest(apiKey, requestId); - console.log(requestInfo); + console.log(requestInfo); } catch (error) { - console.error(error); + console.error(error); } \ No newline at end of file diff --git a/scrapegraph-js/readme.md b/scrapegraph-js/readme.md index d0931be..f4db6b6 100644 --- a/scrapegraph-js/readme.md +++ b/scrapegraph-js/readme.md @@ -18,49 +18,77 @@ npm install scrapegraph-js First, import the required functions: ```javascript -import { scrape, credits, feedback } from 'scrapegraph-js'; +import { smartScraper, getSmartScraperRequest, getCredits, sendFeedback } from 'scrapegraph-sdk'; ``` ### Scraping Websites +#### Basic scraping + ```javascript -const apiKey = 'your_api_key'; -const url = 'https://example.com'; +import { smartScraper } from 'scrapegraph-sdk'; -// Basic scraping -const result = await scrape(apiKey, url); -console.log(JSON.parse(result)); +const apiKey = process.env.SGAI_APIKEY; +const url = 'https://scrapegraphai.com'; +const prompt = 'What does the company do?'; -// Scraping with custom options -const options = { - elements: ['h1', '.product-price'], - wait_for: '.specific-element', - javascript: true -}; +try { + const response = await smartScraper(apiKey, url, prompt); + console.log(response); +} catch (error) { + console.error(error); +} +``` + +#### Scraping with custom output schema + +```javascript +import { smartScraper } from 'scrapegraph-sdk'; -const customResult = await scrape(apiKey, url, options); -console.log(JSON.parse(customResult)); +const apiKey = 'your_api_key'; +const url = 'https://scrapegraphai.com'; +const prompt = 'What does the company do?'; +const schema = //TODO + +try { + const response = await smartScraper(apiKey, url, prompt, schema); + console.log(response); +} catch (error) { + console.error(error); +} ``` ### Checking Credits ```javascript +import { getCredist } from 'scrapegraph-sdk'; + const apiKey = 'your_api_key'; -const creditsInfo = await credits(apiKey); -console.log(JSON.parse(creditsInfo)); +try { + const myCredit = await getCredits(apiKey); + console.log(myCredit) +} catch (error) { + console.error(error) +} ``` ### Submitting Feedback ```javascript +import { sendFeedback } from 'scrapegraph-sdk'; + const apiKey = 'your_api_key'; -const requestId = 'request_id_from_scrape_response'; +const requestId = '16a63a80-c87f-4cde-b005-e6c3ecda278b'; const rating = 5; -const feedbackText = 'Great results!'; +const feedbackMessage = 'This is a test feedback message.'; -const feedbackResponse = await feedback(apiKey, requestId, rating, feedbackText); -console.log(JSON.parse(feedbackResponse)); +try { + const feedback_response = await sendFeedback(apiKey, requestId, rating, feedbackMessage); + console.log(feedback_response); +} catch (error) { + console.error(error) +} ``` ## API Reference @@ -92,17 +120,20 @@ Parameters: - `apiKey` (string): Your ScrapeGraph AI API key - `requestId` (string): The request ID from the scrape response - `rating` (number): Rating score -- `feedbackText` (string): Feedback message +- `feedbackText` (string) (optional): Feedback message ## Error Handling -All functions return JSON strings that you should parse. In case of errors, the response will include error details: +All functions return javascript `Error` object with imformation. In case of errors, the response will include error details: + +// TODO error list ```javascript { - "error": "HTTP error occurred", - "message": "Error details", - "status_code": 400 + "statusCode": 400, + "title": "HTTP error occurred" + "details": "Error details", + } ```