-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextract_local.py
More file actions
122 lines (97 loc) · 3.67 KB
/
Copy pathextract_local.py
File metadata and controls
122 lines (97 loc) · 3.67 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
"""
Fast local extraction - extracts all GitHub awesome list links from local repos.
"""
import re
import json
from pathlib import Path
from collections import Counter
GITHUB_LINK_PATTERN = re.compile(
r'\[([^\]]*)\]\s*\(\s*https?://(?:www\.)?github\.com/([^/\s]+)/([^/\s#\)]+)',
re.IGNORECASE
)
def extract_from_file(filepath: Path) -> list[tuple[str, str, str]]:
"""Extract GitHub links from a markdown file."""
try:
content = filepath.read_text()
except:
return []
links = []
for match in GITHUB_LINK_PATTERN.finditer(content):
title, owner, repo = match.groups()
repo = repo.split('#')[0].split('?')[0].rstrip('/')
if repo and owner:
links.append((title.strip(), owner, repo))
return links
def is_awesome_name(name: str) -> bool:
"""Check if name suggests an awesome list."""
name_lower = name.lower()
indicators = ['awesome', 'curated', 'list', 'resources', 'bookmarks', 'collection']
return any(ind in name_lower for ind in indicators)
def main():
base = Path("/Users/joe/gitea/awesome-meta")
# Find all markdown files in cloned repos
all_links = []
# Original seeds
seed_dirs = [
base / "sindresorhus-awesome",
base / "bayandin-awesome",
]
# Additional seeds
seeds_dir = base / "seeds"
if seeds_dir.exists():
seed_dirs.extend(seeds_dir.iterdir())
for repo_dir in seed_dirs:
for md_file in repo_dir.rglob("*.md"):
links = extract_from_file(md_file)
source = f"{repo_dir.name}/{md_file.relative_to(repo_dir)}"
for title, owner, repo in links:
all_links.append({
"title": title,
"owner": owner,
"repo": repo,
"url": f"https://github.com/{owner}/{repo}",
"source": source,
"is_awesome": is_awesome_name(repo) or is_awesome_name(title)
})
# Dedupe by URL
seen = set()
unique_links = []
for link in all_links:
key = link["url"].lower()
if key not in seen:
seen.add(key)
unique_links.append(link)
# Separate awesome lists from other links
awesome_links = [l for l in unique_links if l["is_awesome"]]
other_links = [l for l in unique_links if not l["is_awesome"]]
print(f"Total unique links found: {len(unique_links)}")
print(f" - Likely awesome lists: {len(awesome_links)}")
print(f" - Other links: {len(other_links)}")
# Save results
output = base / "output"
output.mkdir(exist_ok=True)
# All awesome lists
with open(output / "awesome_from_seeds.json", "w") as f:
json.dump({
"total": len(awesome_links),
"links": sorted(awesome_links, key=lambda x: x["url"].lower())
}, f, indent=2)
# Just URLs
with open(output / "awesome_urls_from_seeds.txt", "w") as f:
for link in sorted(awesome_links, key=lambda x: x["url"].lower()):
f.write(f"{link['url']}\n")
# Markdown list
with open(output / "awesome_from_seeds.md", "w") as f:
f.write("# Awesome Lists Discovered from Seeds\n\n")
f.write(f"Total: {len(awesome_links)} awesome lists\n\n")
for link in sorted(awesome_links, key=lambda x: x["title"].lower()):
f.write(f"- [{link['title']}]({link['url']})\n")
# Stats
owner_counts = Counter(l["owner"].lower() for l in awesome_links)
print(f"\nTop owners:")
for owner, count in owner_counts.most_common(10):
print(f" {owner}: {count}")
print(f"\nResults saved to {output}/")
if __name__ == "__main__":
main()