Not-Grim-Refer commited on
Commit
e5ed1bd
·
1 Parent(s): 80241b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -9,18 +9,23 @@ logger = logging.getLogger(__name__)
9
  st.set_page_config(page_title="GitHub File Search", page_icon=":mag_right:")
10
  access_token = "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"
11
 
12
-
13
  def find_file(repo, path, filename):
14
- contents = repo.get_contents(path)
15
- for content in contents:
16
- if content.type == "dir":
17
- result = find_file(repo, content.path, filename)
18
- if result:
19
- return result
20
- elif content.name == filename:
21
- return content
22
- return None
23
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  def get_repositories_with_file(filename):
26
  g = Github(access_token)
@@ -41,7 +46,6 @@ def get_repositories_with_file(filename):
41
  st.warning(f"File '{filename}' not found in repository '{repo.full_name}'.")
42
  return repo_info
43
 
44
-
45
  def app():
46
  st.title("GitHub File Search")
47
  st.write("Enter a file name to search for on GitHub:")
@@ -65,6 +69,5 @@ def app():
65
  logs = log_file.read()
66
  st.sidebar.text(logs)
67
 
68
-
69
  if __name__ == "__main__":
70
  app()
 
9
  st.set_page_config(page_title="GitHub File Search", page_icon=":mag_right:")
10
  access_token = "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"
11
 
 
12
  def find_file(repo, path, filename):
13
+ try:
14
+ contents = repo.get_contents(path)
15
+ if contents is None:
16
+ return None
 
 
 
 
 
17
 
18
+ for content in contents:
19
+ if content.type == "dir":
20
+ result = find_file(repo, content.path, filename)
21
+ if result:
22
+ return result
23
+ elif content.name == filename:
24
+ return content
25
+ except Exception as e:
26
+ logger.warning(f"Error while searching for '{filename}' in repository '{repo.full_name}': {str(e)}")
27
+ st.warning(f"Error while searching for '{filename}' in repository '{repo.full_name}': {str(e)}")
28
+ return None
29
 
30
  def get_repositories_with_file(filename):
31
  g = Github(access_token)
 
46
  st.warning(f"File '{filename}' not found in repository '{repo.full_name}'.")
47
  return repo_info
48
 
 
49
  def app():
50
  st.title("GitHub File Search")
51
  st.write("Enter a file name to search for on GitHub:")
 
69
  logs = log_file.read()
70
  st.sidebar.text(logs)
71
 
 
72
  if __name__ == "__main__":
73
  app()