Skip to content

Commit 1617a40

Browse files
committed
Added Search Feature for Scripts
1 parent c0b68a7 commit 1617a40

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Search Amazing-Python-Scripts
2+
3+
## 📝 Description
4+
* This script allows you to search for a particular script in the vast collection of scripts present in <a href="https://github.com/avinashkranjan/Amazing-Python-Scripts">Amazing-Python-Scripts</a> Repository
5+
* The script uses <a href="https://api.github.com/repos/avinashkranjan/Amazing-Python-Scripts/contents">Github's publically available API</a> for this purpose
6+
7+
<br>
8+
9+
## ⚙️ How To Use
10+
11+
Navigate to the project directory and run the following commands :
12+
```bash
13+
pip install -r requirements.txt
14+
```
15+
```bash
16+
python search-scripts.py
17+
```
18+
You will be prompted to enter the keyword to be searched
19+
20+
## Output
21+
22+
23+
## Author
24+
25+
26+
* <a href="https://github.com/singhchanmeet"> Chanmeet Singh </a>
2.41 MB
Binary file not shown.
34 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import requests
2+
3+
def get_repository_contents(repo_owner, repo_name):
4+
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/contents"
5+
response = requests.get(url)
6+
7+
if response.status_code == 200:
8+
return response.json()
9+
else:
10+
print(f"Failed to fetch repository contents. Status code: {response.status_code}")
11+
return None
12+
13+
def extract_parent_folder(script_path):
14+
return script_path.rsplit("/", 1)[0]
15+
16+
def filter_items_by_keyword(contents, keyword, repo_owner, repo_name):
17+
filtered_items = []
18+
repo_url = f"https://github.com/{repo_owner}/{repo_name}"
19+
20+
for item in contents:
21+
item_name = item["name"].lower()
22+
item_type = item["type"]
23+
24+
if keyword.lower() in item_name:
25+
if item_type == "file":
26+
filtered_items.append((item_name, item["html_url"]))
27+
elif item_type == "dir":
28+
filtered_items.append((item_name, item["html_url"]))
29+
30+
return filtered_items
31+
32+
if __name__ == "__main__":
33+
# Replace with your GitHub repository details
34+
owner = "avinashkranjan"
35+
repo = "Amazing-Python-Scripts"
36+
37+
# Get repository contents
38+
contents = get_repository_contents(owner, repo)
39+
40+
if contents:
41+
search_keyword = input("\nEnter the keyword to search for in the scripts: ")
42+
found_items = filter_items_by_keyword(contents, search_keyword, owner, repo)
43+
44+
if found_items:
45+
print("\nFound items matching the keyword:\n")
46+
for idx, (item_name, item_url) in enumerate(found_items, start=1):
47+
print(f"{idx}) {item_name} ({item_url})")
48+
print("\n")
49+
else:
50+
print("No items found matching the keyword.")

0 commit comments

Comments
 (0)