-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.py
More file actions
37 lines (26 loc) · 947 Bytes
/
search.py
File metadata and controls
37 lines (26 loc) · 947 Bytes
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
import requests
print("GitHub Search Simulator Started. Type 'exit' to quit.\n")
while True:
query = input("Enter search term: ").strip()
if query.lower() == "exit":
print("Exiting simulator...")
break
if not query:
print("Please type something.\n")
continue
url = f"https://api.github.com/search/repositories?q={query}&sort=stars&order=desc"
print(f"\nSearching GitHub for: '{query}' ...\n")
try:
response = requests.get(url).json()
items = response.get("items", [])
if not items:
print("No results.\n")
continue
for repo in items[:5]:
print(f"📌 {repo['name']}")
print(f"⭐ Stars: {repo['stargazers_count']}")
print(f"🔗 URL: {repo['html_url']}")
print(f"📝 Description: {repo['description']}\n")
except Exception as e:
print("Error:", e)
print()