added argparse
This commit is contained in:
parent
651228b5b8
commit
76c012f32d
1 changed files with 25 additions and 21 deletions
|
@ -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")
|
||||
|
@ -20,29 +20,33 @@ class GithubSearcher():
|
|||
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)
|
||||
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()
|
||||
|
||||
searcher = GithubSearcher(args.query)
|
||||
|
||||
if args.search_type == "repo":
|
||||
searcher.search_repo()
|
||||
result = searcher.get_result()
|
||||
for repo in result:
|
||||
print(repo.full_name)
|
||||
"""
|
||||
|
||||
# search using search_users endpoint example
|
||||
query = "bpmcdevitt"
|
||||
searcher = GithubSearcher(query)
|
||||
elif args.search_type == "users":
|
||||
searcher.search_users()
|
||||
elif args.search_type == "name":
|
||||
searcher.search_in_name()
|
||||
|
||||
result = searcher.get_result()
|
||||
for user in result:
|
||||
print(user.login)
|
||||
|
||||
|
||||
for item in result:
|
||||
if args.search_type == "users":
|
||||
print(item.login)
|
||||
else:
|
||||
print(item.full_name)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Reference in a new issue