Spaces:
Runtime error
Runtime error
Commit
·
1d05a4d
1
Parent(s):
46b9153
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,8 @@ access_token = os.environ["GitHub"]
|
|
13 |
def get_repositories_with_file(filename):
|
14 |
# Search for the file on GitHub using the PyGitHub library
|
15 |
g = Github(access_token)
|
16 |
-
|
|
|
17 |
|
18 |
# Initialize a list to store the repository information
|
19 |
repo_info = []
|
@@ -22,8 +23,7 @@ def get_repositories_with_file(filename):
|
|
22 |
for repo in repositories:
|
23 |
try:
|
24 |
# Get all the files in the repository
|
25 |
-
contents = repo.get_contents(
|
26 |
-
|
27 |
# Check if the repository contains a file with the given name
|
28 |
for content in contents:
|
29 |
if content.name == filename:
|
@@ -33,7 +33,6 @@ def get_repositories_with_file(filename):
|
|
33 |
"url": repo.html_url
|
34 |
})
|
35 |
break
|
36 |
-
|
37 |
except GithubException as e:
|
38 |
# Catch the exception if the file is not found in the repository
|
39 |
if e.status == 404:
|
@@ -44,13 +43,14 @@ def get_repositories_with_file(filename):
|
|
44 |
# Return the repository information
|
45 |
return repo_info
|
46 |
|
47 |
-
|
48 |
# Define the Streamlit app
|
49 |
def app():
|
50 |
# Set up the user interface
|
51 |
st.title("GitHub File Search")
|
52 |
st.write("Enter a file name to search for on GitHub:")
|
53 |
-
|
|
|
|
|
54 |
# Get the repositories with the file
|
55 |
repo_info = get_repositories_with_file(filename)
|
56 |
|
@@ -63,7 +63,6 @@ def app():
|
|
63 |
else:
|
64 |
st.warning(f"No repositories found with the file '{filename}'.")
|
65 |
|
66 |
-
|
67 |
# Run the Streamlit app
|
68 |
if __name__ == "__main__":
|
69 |
app()
|
|
|
13 |
def get_repositories_with_file(filename):
|
14 |
# Search for the file on GitHub using the PyGitHub library
|
15 |
g = Github(access_token)
|
16 |
+
query = f"filename:{filename}"
|
17 |
+
repositories = g.search_repositories(query=query, sort="stars", order="desc")
|
18 |
|
19 |
# Initialize a list to store the repository information
|
20 |
repo_info = []
|
|
|
23 |
for repo in repositories:
|
24 |
try:
|
25 |
# Get all the files in the repository
|
26 |
+
contents = repo.get_contents("")
|
|
|
27 |
# Check if the repository contains a file with the given name
|
28 |
for content in contents:
|
29 |
if content.name == filename:
|
|
|
33 |
"url": repo.html_url
|
34 |
})
|
35 |
break
|
|
|
36 |
except GithubException as e:
|
37 |
# Catch the exception if the file is not found in the repository
|
38 |
if e.status == 404:
|
|
|
43 |
# Return the repository information
|
44 |
return repo_info
|
45 |
|
|
|
46 |
# Define the Streamlit app
|
47 |
def app():
|
48 |
# Set up the user interface
|
49 |
st.title("GitHub File Search")
|
50 |
st.write("Enter a file name to search for on GitHub:")
|
51 |
+
filename = st.text_input("File name")
|
52 |
+
|
53 |
+
if filename:
|
54 |
# Get the repositories with the file
|
55 |
repo_info = get_repositories_with_file(filename)
|
56 |
|
|
|
63 |
else:
|
64 |
st.warning(f"No repositories found with the file '{filename}'.")
|
65 |
|
|
|
66 |
# Run the Streamlit app
|
67 |
if __name__ == "__main__":
|
68 |
app()
|