Repository navigation
Expand file tree
/
Copy pathsdk_example.py
More file actions
74 lines (59 loc) · 2.8 KB
/
Copy pathsdk_example.py
File metadata and controls
74 lines (59 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""GitHub scraper API: DataGuru Python SDK example.
Runs DataGuru's GitHub APIs and prints the JSON they return:
- GitHub AI Dataset & Documentation Collection: $0.0022 per successful request ($2.20 per 1,000)
- GitHub Repository Details & Metrics: $0.0022 per successful request ($2.20 per 1,000)
- GitHub Developer Talent Sourcing & Profiles: $0.0022 per successful request ($2.20 per 1,000)
Setup:
pip install -r requirements.txt
export DATAGURU_API_KEY="your key" # free credit at https://dashboard.dataguru.cc
Run:
python examples/sdk_example.py # every API below
python examples/sdk_example.py github-dataset-collection
"""
import json
import sys
from pathlib import Path
from dataguru import DataGuru, DataGuruError
def github_dataset_collection(dg):
"""GitHub AI Dataset & Documentation Collection: Extract structured documentation sections, code snippets, file trees, and issue QA instruction-tuning pairs from GitHub repositories and issues for training AI models."""
return dg.call(
"github-dataset-collection",
target="psf/requests",
)
def github_repo_details(dg):
"""GitHub Repository Details & Metrics: Scrape comprehensive GitHub repository details including stars, forks, watchers, open issues, PR counts, topics, license, default branch, creation date, and description."""
return dg.call(
"github-repo-details",
target="tiangolo/fastapi",
)
def github_talent_sourcing(dg):
"""GitHub Developer Talent Sourcing & Profiles: Scrape GitHub developer profile information for technical recruiting and talent sourcing, including contact links, company, location, followers, and pinned repositories with stars."""
# Replace the placeholder with a real value before running.
return dg.call(
"github-talent-sourcing",
target="<github-username>",
)
EXAMPLES = {
"github-dataset-collection": github_dataset_collection,
"github-repo-details": github_repo_details,
"github-talent-sourcing": github_talent_sourcing,
}
DEFAULT = ['github-dataset-collection', 'github-repo-details']
def main(names):
out = Path("output")
out.mkdir(exist_ok=True)
with DataGuru() as dg: # reads DATAGURU_API_KEY
for name in names:
data = EXAMPLES[name](dg)
(out / f"{name}.json").write_text(json.dumps(data, indent=2, ensure_ascii=False))
print(f"{name}: saved output/{name}.json")
print(json.dumps(data, indent=2, ensure_ascii=False)[:1500])
if __name__ == "__main__":
names = sys.argv[1:] or DEFAULT
unknown = [n for n in names if n not in EXAMPLES]
if unknown:
sys.exit(f"Unknown API {unknown}. Choose from: {', '.join(EXAMPLES)}")
try:
main(names)
except DataGuruError as error:
sys.exit(f"DataGuru error: {error}")