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
|
import os
|
||||||
from github import Github
|
import argparse
|
||||||
from github import Auth
|
from github import Github, Auth
|
||||||
|
|
||||||
def auth():
|
def auth():
|
||||||
access_token = os.getenv("GITHUB_ACCESS_TOKEN")
|
access_token = os.getenv("GITHUB_ACCESS_TOKEN")
|
||||||
|
@ -16,33 +16,37 @@ class GithubSearcher():
|
||||||
|
|
||||||
def search_repo(self):
|
def search_repo(self):
|
||||||
self.result = self.g.search_repositories(self.query)
|
self.result = self.g.search_repositories(self.query)
|
||||||
|
|
||||||
def search_users(self):
|
def search_users(self):
|
||||||
self.result = self.g.search_users(self.query)
|
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):
|
def get_result(self):
|
||||||
return self.result
|
return self.result
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# search using search_repo endpoint example
|
parser = argparse.ArgumentParser(description="Search GitHub repositories and users.")
|
||||||
"""
|
parser.add_argument("--query", type=str, help="The search query.")
|
||||||
query = "python"
|
parser.add_argument("--search_type", type=str, choices=["repo", "users", "name"], help="The type of search to perform: 'repo', 'users', or 'name'.")
|
||||||
searcher = GithubSearcher(query)
|
args = parser.parse_args()
|
||||||
searcher.search_repo()
|
|
||||||
result = searcher.get_result()
|
|
||||||
for repo in result:
|
|
||||||
print(repo.full_name)
|
|
||||||
"""
|
|
||||||
|
|
||||||
# search using search_users endpoint example
|
searcher = GithubSearcher(args.query)
|
||||||
query = "bpmcdevitt"
|
|
||||||
searcher = GithubSearcher(query)
|
if args.search_type == "repo":
|
||||||
searcher.search_users()
|
searcher.search_repo()
|
||||||
result = searcher.get_result()
|
elif args.search_type == "users":
|
||||||
for user in result:
|
searcher.search_users()
|
||||||
print(user.login)
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Add table
Reference in a new issue