Skip to content

Commit de32fc1

Browse files
authored
Merge branch 'main' into error-management-js
2 parents 55d1bb6 + ae6b9a6 commit de32fc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4786
-1005
lines changed

.github/workflows/pylint.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
12-
- name: Install the latest version of rye
13-
uses: eifinger/setup-rye@v3
11+
- uses: actions/checkout@v4
12+
- name: Install uv
13+
uses: astral-sh/setup-uv@v3
1414
- name: Install dependencies
15-
run: rye sync --no-lock
15+
run: |
16+
cd scrapegraph-py
17+
uv sync --frozen
1618
- name: Analysing the code with pylint
17-
run: rye run pylint-ci
19+
run: |
20+
cd scrapegraph-py
21+
uv run poe pylint-ci
1822
- name: Check Pylint score
1923
run: |
2024
cd scrapegraph-py
21-
pylint_score=$(rye run pylint-score-ci | grep 'Raw metrics' | awk '{print $4}')
25+
pylint_score=$(uv run poe pylint-score-ci | grep 'Raw metrics' | awk '{print $4}')
2226
if (( $(echo "$pylint_score < 8" | bc -l) )); then
2327
echo "Pylint score is below 8. Blocking commit."
2428
exit 1

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
- name: Set up Python
1818
uses: actions/setup-python@v5
1919
with:

.github/workflows/release.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
run: |
1515
sudo apt update
1616
sudo apt install -y git
17-
- name: Install the latest version of rye
18-
uses: eifinger/setup-rye@v3
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v3
1919
- name: Install Node Env
2020
uses: actions/setup-node@v4
2121
with:
@@ -28,12 +28,12 @@ jobs:
2828
- name: Build app
2929
run: |
3030
cd scrapegraph-py
31-
rye sync --no-lock
32-
rye build
31+
uv sync --frozen
32+
uv build
3333
id: build_cache
3434
if: success()
3535
- name: Cache build
36-
uses: actions/cache@v2
36+
uses: actions/cache@v4
3737
with:
3838
path: scrapegraph-py/dist
3939
key: ${{ runner.os }}-build-${{ hashFiles('scrapegraph-py/dist/**') }}
@@ -60,18 +60,14 @@ jobs:
6060
with:
6161
fetch-depth: 0
6262
persist-credentials: false
63-
- name: Go to scrapegraph-py folder
64-
run: |
65-
ls
66-
cd ./scrapegraph-py
67-
- name: Install the latest version of rye
68-
uses: eifinger/setup-rye@v3
63+
- name: Install uv
64+
uses: astral-sh/setup-uv@v3
6965
- name: Setup Python environment
7066
run: |
7167
cd ./scrapegraph-py
72-
rye sync
68+
uv sync
7369
- name: Restore build artifacts
74-
uses: actions/cache@v2
70+
uses: actions/cache@v4
7571
with:
7672
path: ./scrapegraph-py/dist
7773
key: ${{ runner.os }}-build-${{ hashFiles('./scrapegraph-py/dist/**') }}

scrapegraph-js/CODE_OF_CONDUCT.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, religion, or sexual identity
10+
and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the
26+
overall community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies when
54+
an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official e-mail address,
56+
posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement at
63+
64+
All complaints will be reviewed and investigated promptly and fairly.
65+
66+
All community leaders are obligated to respect the privacy and security of the
67+
reporter of any incident.
68+
69+
## Enforcement Guidelines
70+
71+
Community leaders will follow these Community Impact Guidelines in determining
72+
the consequences for any action they deem in violation of this Code of Conduct:
73+
74+
### 1. Correction
75+
76+
**Community Impact**: Use of inappropriate language or other behavior deemed
77+
unprofessional or unwelcome in the community.
78+
79+
**Consequence**: A private, written warning from community leaders, providing
80+
clarity around the nature of the violation and an explanation of why the
81+
behavior was inappropriate. A public apology may be requested.
82+
83+
### 2. Warning
84+
85+
**Community Impact**: A violation through a single incident or series
86+
of actions.
87+
88+
**Consequence**: A warning with consequences for continued behavior. No
89+
interaction with the people involved, including unsolicited interaction with
90+
those enforcing the Code of Conduct, for a specified period of time. This
91+
includes avoiding interactions in community spaces as well as external channels
92+
like social media. Violating these terms may lead to a temporary or
93+
permanent ban.
94+
95+
### 3. Temporary Ban
96+
97+
**Community Impact**: A serious violation of community standards, including
98+
sustained inappropriate behavior.
99+
100+
**Consequence**: A temporary ban from any sort of interaction or public
101+
communication with the community for a specified period of time. No public or
102+
private interaction with the people involved, including unsolicited interaction
103+
with those enforcing the Code of Conduct, is allowed during this period.
104+
Violating these terms may lead to a permanent ban.
105+
106+
### 4. Permanent Ban
107+
108+
**Community Impact**: Demonstrating a pattern of violation of community
109+
standards, including sustained inappropriate behavior, harassment of an
110+
individual, or aggression toward or disparagement of classes of individuals.
111+
112+
**Consequence**: A permanent ban from any sort of public interaction within
113+
the community.
114+
115+
## Attribution
116+
117+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118+
version 2.0, available at
119+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120+
121+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122+
enforcement ladder](https://github.com/mozilla/diversity).
123+
124+
[homepage]: https://www.contributor-covenant.org
125+
126+
For answers to common questions about this code of conduct, see the FAQ at
127+
https://www.contributor-covenant.org/faq. Translations are available at
128+
https://www.contributor-covenant.org/translations.
File renamed without changes.
File renamed without changes.

scrapegraph-js/examples/getCredits_example.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { getCredits } from 'scrapegraph-sdk';
22
import 'dotenv/config';
33

44
try {
5-
const apiKey = process.env.SGAI_APIKEY;
5+
const apiKey = process.env.SGAI_APIKEY;
66

7-
const myCredit = await getCredits(apiKey);
7+
const myCredit = await getCredits(apiKey);
88

9-
console.log(myCredit)
9+
console.log(myCredit)
1010
} catch (error) {
11-
console.error(error)
11+
console.error(error)
1212
}

scrapegraph-js/examples/getSmartScraperRequest_example.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { getSmartScraperRequest } from 'scrapegraph-sdk';
22
import 'dotenv/config';
33

44
try {
5-
const apiKey = process.env.SGAI_APIKEY;
6-
const requestId = '3fa85f64-5717-4562-b3fc-2c963f66afa6'
5+
const apiKey = process.env.SGAI_APIKEY;
6+
const requestId = '3fa85f64-5717-4562-b3fc-2c963f66afa6'
77

8-
const requestInfo = await getSmartScraperRequest(apiKey, requestId);
8+
const requestInfo = await getSmartScraperRequest(apiKey, requestId);
99

10-
console.log(requestInfo);
10+
console.log(requestInfo);
1111
} catch (error) {
12-
console.error(error);
12+
console.error(error);
1313
}

scrapegraph-js/readme.md

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,77 @@ npm install scrapegraph-js
1818
First, import the required functions:
1919

2020
```javascript
21-
import { scrape, credits, feedback } from 'scrapegraph-js';
21+
import { smartScraper, getSmartScraperRequest, getCredits, sendFeedback } from 'scrapegraph-sdk';
2222
```
2323

2424
### Scraping Websites
2525

26+
#### Basic scraping
27+
2628
```javascript
27-
const apiKey = 'your_api_key';
28-
const url = 'https://example.com';
29+
import { smartScraper } from 'scrapegraph-sdk';
2930

30-
// Basic scraping
31-
const result = await scrape(apiKey, url);
32-
console.log(JSON.parse(result));
31+
const apiKey = process.env.SGAI_APIKEY;
32+
const url = 'https://scrapegraphai.com';
33+
const prompt = 'What does the company do?';
3334

34-
// Scraping with custom options
35-
const options = {
36-
elements: ['h1', '.product-price'],
37-
wait_for: '.specific-element',
38-
javascript: true
39-
};
35+
try {
36+
const response = await smartScraper(apiKey, url, prompt);
37+
console.log(response);
38+
} catch (error) {
39+
console.error(error);
40+
}
41+
```
42+
43+
#### Scraping with custom output schema
44+
45+
```javascript
46+
import { smartScraper } from 'scrapegraph-sdk';
4047

41-
const customResult = await scrape(apiKey, url, options);
42-
console.log(JSON.parse(customResult));
48+
const apiKey = 'your_api_key';
49+
const url = 'https://scrapegraphai.com';
50+
const prompt = 'What does the company do?';
51+
const schema = //TODO
52+
53+
try {
54+
const response = await smartScraper(apiKey, url, prompt, schema);
55+
console.log(response);
56+
} catch (error) {
57+
console.error(error);
58+
}
4359
```
4460

4561
### Checking Credits
4662

4763
```javascript
64+
import { getCredist } from 'scrapegraph-sdk';
65+
4866
const apiKey = 'your_api_key';
4967

50-
const creditsInfo = await credits(apiKey);
51-
console.log(JSON.parse(creditsInfo));
68+
try {
69+
const myCredit = await getCredits(apiKey);
70+
console.log(myCredit)
71+
} catch (error) {
72+
console.error(error)
73+
}
5274
```
5375

5476
### Submitting Feedback
5577

5678
```javascript
79+
import { sendFeedback } from 'scrapegraph-sdk';
80+
5781
const apiKey = 'your_api_key';
58-
const requestId = 'request_id_from_scrape_response';
82+
const requestId = '16a63a80-c87f-4cde-b005-e6c3ecda278b';
5983
const rating = 5;
60-
const feedbackText = 'Great results!';
84+
const feedbackMessage = 'This is a test feedback message.';
6185

62-
const feedbackResponse = await feedback(apiKey, requestId, rating, feedbackText);
63-
console.log(JSON.parse(feedbackResponse));
86+
try {
87+
const feedback_response = await sendFeedback(apiKey, requestId, rating, feedbackMessage);
88+
console.log(feedback_response);
89+
} catch (error) {
90+
console.error(error)
91+
}
6492
```
6593

6694
## API Reference
@@ -92,17 +120,20 @@ Parameters:
92120
- `apiKey` (string): Your ScrapeGraph AI API key
93121
- `requestId` (string): The request ID from the scrape response
94122
- `rating` (number): Rating score
95-
- `feedbackText` (string): Feedback message
123+
- `feedbackText` (string) (optional): Feedback message
96124

97125
## Error Handling
98126

99-
All functions return JSON strings that you should parse. In case of errors, the response will include error details:
127+
All functions return javascript `Error` object with imformation. In case of errors, the response will include error details:
128+
129+
// TODO error list
100130

101131
```javascript
102132
{
103-
"error": "HTTP error occurred",
104-
"message": "Error details",
105-
"status_code": 400
133+
"statusCode": 400,
134+
"title": "HTTP error occurred"
135+
"details": "Error details",
136+
106137
}
107138
```
108139

0 commit comments

Comments
 (0)