Github CLI tool added. (#198)

* GithubBot added

* add new project

* Update README.md

* Update README.md
This commit is contained in:
Abhilasha Sinha 2020-10-27 09:48:22 +05:30 committed by GitHub
parent e3db5f71f2
commit aeb8537b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 1 deletions

9
Github_Bot/README.md Normal file
View File

@ -0,0 +1,9 @@
# Github_Bot
A CLI tool to get github user and repository details.
```
>python main.py -f user -l username
>python main.py -f repo -l username reponame
```
![](readme_assets/img.png)

49
Github_Bot/main.py Normal file
View File

@ -0,0 +1,49 @@
import requests
import json
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("-f", "--function", required=True, help="user details or repo details")
ap.add_argument("-l", "--list", required=True, metavar="", nargs='+', default=[], help="handle and repo")
args = vars(ap.parse_args())
class GithubBot():
def __init__(self):
print('******************* GITHUB CLI TOOL *********************')
self.base_url = "https://api.github.com/"
def get_user_details(self, args):
url = self.base_url + "users/" + args[0]
res = requests.get(url)
print('*********** USER:', args[0], '***************')
if res.status_code == 200:
data = json.loads(res.text)
print("NAME: ", data["name"])
print("BIO: ", data["bio"])
print("LOCATION: ", data["location"])
print("FOLLOWERS COUNT: ", data["followers"])
print("FOLLOWING COUNT: ", data["following"])
else:
print("Error getting details")
def get_repo_details(self, args):
url = self.base_url + "repos/" + args[0] + "/" + args[1]
res = requests.get(url)
print('********* USER:', args[0], '| REPO:', args[1], '*********')
if res.status_code == 200:
data = json.loads(res.text)
print("URL: ", data["svn_url"])
print("STARS: ", data["stargazers_count"])
print("FORKS: ", data["forks"])
print("LANGUAGE: ", data["language"])
else:
print("Error getting details")
if __name__ == "__main__":
obj = GithubBot()
function_map = {
'user': obj.get_user_details,
'repo': obj.get_repo_details,
}
function_map[args['function']](args['list'])

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -0,0 +1,5 @@
certifi==2020.6.20
chardet==3.0.4
idna==2.10
requests==2.24.0
urllib3==1.25.11

View File

@ -167,7 +167,7 @@ So far, the following projects have been integrated to this repo:
|[2048](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/2048)|[Krunal](https://github.com/gitkp11)
|[Spotify Downloader](spotify_downloader)|[Sagar Patel](https://github.com/sagar627)|
|[Download Page as PDF](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Download-page-as-pdf)|[Jeremias Gomes](https://github.com/j3r3mias)
|[GithubBot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/GithubBot)|[Abhilasha](https://github.com/Abhilasha06)|
## How to use :