|
| 1 | +#!/usr/bin/python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +# MIT License |
| 5 | +# |
| 6 | +# Copyright (c) 2021 Tahmid Rayat |
| 7 | +# |
| 8 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | +# of this software and associated documentation files (the "Software"), to deal |
| 10 | +# in the Software without restriction, including without limitation the rights |
| 11 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | +# copies of the Software, and to permit persons to whom the Software is |
| 13 | +# furnished to do so, subject to the following conditions: |
| 14 | +# |
| 15 | +# The above copyright notice and this permission notice shall be included in all |
| 16 | +# copies or substantial portions of the Software. |
| 17 | +# |
| 18 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | +# SOFTWARE. |
| 25 | +# |
| 26 | +# Copyright (C) 2021 HTR-TECH (https://github.com/htr-tech) |
| 27 | +# |
| 28 | + |
| 29 | +import os |
| 30 | +import sys |
| 31 | +import json |
| 32 | +import six |
| 33 | +import requests |
| 34 | + |
| 35 | +info = """ |
| 36 | +[-] Username : %s |
| 37 | +
|
| 38 | +[-] Name : %s |
| 39 | +[-] Followers : %s |
| 40 | +[-] Following : %s |
| 41 | +
|
| 42 | +[-] Location : %s |
| 43 | +[-] Email : %s |
| 44 | +[-] Twitter : %s |
| 45 | +[-] Blog : %s |
| 46 | +[-] Company : %s |
| 47 | +[-] Hireable : %s |
| 48 | +
|
| 49 | +[-] Total Repository : %s |
| 50 | +[-] Total Gists : %s |
| 51 | +[-] Joined Github at : %s |
| 52 | +[-] Recent Activity : %s |
| 53 | +
|
| 54 | +[-] Github URL : https://github.com/%s |
| 55 | +[-] Repositories : https://github.com/%s/repositories |
| 56 | +[-] Avatar : %s |
| 57 | +""" |
| 58 | + |
| 59 | +def status(user): |
| 60 | + main = requests.get("https://api.github.com/users/%s" % (user)) |
| 61 | + if main.status_code == 200: |
| 62 | + pass |
| 63 | + elif main.status_code == 404: |
| 64 | + print('No Github Account with that Username !') |
| 65 | + sys.exit() |
| 66 | + else: |
| 67 | + print('Try again After Some Time') |
| 68 | + sys.exit() |
| 69 | + |
| 70 | +def stats(user): |
| 71 | + status(user) |
| 72 | + main = requests.get("https://api.github.com/users/%s" % (user)) |
| 73 | + dump = json.loads(main.text) |
| 74 | + |
| 75 | + h1 = dump['login'] |
| 76 | + h2 = dump['name'] |
| 77 | + h3 = dump['followers'] |
| 78 | + h4 = dump['following'] |
| 79 | + h5 = dump['location'] |
| 80 | + h6 = dump['email'] |
| 81 | + h7 = dump['twitter_username'] |
| 82 | + h8 = dump['blog'] |
| 83 | + h9 = dump['company'] |
| 84 | + h10 = dump['hireable'] |
| 85 | + h11 = dump['public_repos'] |
| 86 | + h12 = dump['public_gists'] |
| 87 | + h13 = dump['created_at'] |
| 88 | + h14 = dump['updated_at'] |
| 89 | + h15 = dump['avatar_url'] |
| 90 | + |
| 91 | + print(info % (h1, h2, h3, h4, h5, h6, h7, h8, |
| 92 | + h9, h10, h11, h12, h13, h14, h1, h1, h15)) |
| 93 | + |
| 94 | + orgs = requests.get("https://api.github.com/users/%s/orgs" % (user)) |
| 95 | + orgs_dump = json.loads(orgs.text) |
| 96 | + for hulu in orgs_dump: |
| 97 | + print('[-] Organization : {} '.format(hulu['login'])) |
| 98 | + |
| 99 | + list_repo = six.moves.input( |
| 100 | + '\n[-] Wanna List repositories [Max 100] [Y/n] : ') |
| 101 | + print('') |
| 102 | + |
| 103 | + if list_repo == "y" or list_repo == "Y": |
| 104 | + repos = requests.get( |
| 105 | + "https://api.github.com/users/%s/repos?per_page=100" % (user)) |
| 106 | + repo_dump = json.loads(repos.text) |
| 107 | + for bagh in repo_dump: |
| 108 | + print('[-] Repo Name :: {} \n[-] Stars :: {} \n[-] Forks :: {} \n[-] Clone URL :: {}\n'.format( |
| 109 | + bagh['name'], bagh['stargazers_count'], bagh['forks_count'], bagh['clone_url'])) |
| 110 | + |
| 111 | + total_star, total_fork = 0, 0 |
| 112 | + for bagh in repo_dump: |
| 113 | + total_star += int(bagh['stargazers_count']) |
| 114 | + total_fork += int(bagh['forks_count']) |
| 115 | + |
| 116 | + print('[-] Total Stars : '+str(total_star)) |
| 117 | + print('[-] Total Forks : '+str(total_fork)) |
| 118 | + print('') |
| 119 | + else: |
| 120 | + pass |
| 121 | + |
| 122 | +note = """ |
| 123 | + GithubStat (c) Tahmid Rayat <https://github.com/htr-tech> |
| 124 | +
|
| 125 | + A Simple Github User Statistics Meter based on Github-API. |
| 126 | +
|
| 127 | + Type GithubStat <your github username> |
| 128 | +
|
| 129 | + Example : GithubStat HTR-TECH |
| 130 | +
|
| 131 | + If you Like this Project then don't Forget to leave a Star :) |
| 132 | +""" |
| 133 | + |
| 134 | +def main(): |
| 135 | + if len(sys.argv) >= 2: |
| 136 | + try: |
| 137 | + stats(sys.argv[1]) |
| 138 | + except Exception as exceptions: |
| 139 | + sys.exit(exceptions) |
| 140 | + else: |
| 141 | + sys.exit(note) |
| 142 | + |
| 143 | +if __name__ == '__main__': |
| 144 | + main() |
0 commit comments