diff --git a/github_searcher.py b/github_searcher.py index 71d7d61..7fbdd4e 100644 --- a/github_searcher.py +++ b/github_searcher.py @@ -1,6 +1,6 @@ import os -from github import Github -from github import Auth +import argparse +from github import Github, Auth def auth(): access_token = os.getenv("GITHUB_ACCESS_TOKEN") @@ -16,33 +16,37 @@ class GithubSearcher(): def search_repo(self): self.result = self.g.search_repositories(self.query) - + def search_users(self): self.result = self.g.search_users(self.query) + def search_in_name(self): + self.result = self.g.search_repositories('in:name ' + self.query) + def get_result(self): return self.result def main(): - # search using search_repo endpoint example - """ - query = "python" - searcher = GithubSearcher(query) - searcher.search_repo() - result = searcher.get_result() - for repo in result: - print(repo.full_name) - """ + parser = argparse.ArgumentParser(description="Search GitHub repositories and users.") + parser.add_argument("--query", type=str, help="The search query.") + parser.add_argument("--search_type", type=str, choices=["repo", "users", "name"], help="The type of search to perform: 'repo', 'users', or 'name'.") + args = parser.parse_args() - # search using search_users endpoint example - query = "bpmcdevitt" - searcher = GithubSearcher(query) - searcher.search_users() - result = searcher.get_result() - for user in result: - print(user.login) - + searcher = GithubSearcher(args.query) + + if args.search_type == "repo": + searcher.search_repo() + elif args.search_type == "users": + searcher.search_users() + elif args.search_type == "name": + searcher.search_in_name() + + result = searcher.get_result() + for item in result: + if args.search_type == "users": + print(item.login) + else: + print(item.full_name) - if __name__ == "__main__": main() \ No newline at end of file