Skip to content

Commit 14a585c

Browse files
Merge pull request #2751 from avinashkranjan/deepsource-transform-b366d7b1
format code with autopep8
2 parents 49d9a7e + fe49229 commit 14a585c

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Search-Amazing-Python-Scripts/search-scripts.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,53 @@
11
import requests
22

3+
34
def get_repository_contents(repo_owner, repo_name):
45
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/contents"
56
response = requests.get(url)
6-
7+
78
if response.status_code == 200:
89
return response.json()
910
else:
10-
print(f"Failed to fetch repository contents. Status code: {response.status_code}")
11+
print(
12+
f"Failed to fetch repository contents. Status code: {response.status_code}")
1113
return None
1214

15+
1316
def extract_parent_folder(script_path):
1417
return script_path.rsplit("/", 1)[0]
1518

19+
1620
def filter_items_by_keyword(contents, keyword, repo_owner, repo_name):
1721
filtered_items = []
1822
repo_url = f"https://github.com/{repo_owner}/{repo_name}"
19-
23+
2024
for item in contents:
2125
item_name = item["name"].lower()
2226
item_type = item["type"]
23-
27+
2428
if keyword.lower() in item_name:
2529
if item_type == "file":
2630
filtered_items.append((item_name, item["html_url"]))
2731
elif item_type == "dir":
2832
filtered_items.append((item_name, item["html_url"]))
29-
33+
3034
return filtered_items
3135

36+
3237
if __name__ == "__main__":
3338
# Replace with your GitHub repository details
3439
owner = "avinashkranjan"
3540
repo = "Amazing-Python-Scripts"
36-
41+
3742
# Get repository contents
3843
contents = get_repository_contents(owner, repo)
39-
44+
4045
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-
46+
search_keyword = input(
47+
"\nEnter the keyword to search for in the scripts: ")
48+
found_items = filter_items_by_keyword(
49+
contents, search_keyword, owner, repo)
50+
4451
if found_items:
4552
print("\nFound items matching the keyword:\n")
4653
for idx, (item_name, item_url) in enumerate(found_items, start=1):

0 commit comments

Comments
 (0)