├── .gitignore ├── LICENSE ├── README.md └── github_star_sum_of_user.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Developer.Lx 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LxGitHubStarCounter 2 | Calculate user's total star. 3 | 4 | ## Usage 5 | Run command as follows: 6 | 7 | ``` 8 | # python3 ./github_star_sum_of_user.py YOUR_GITHUB_ID 9 | ``` 10 | -------------------------------------------------------------------------------- /github_star_sum_of_user.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | __author__ = 'DeveloperLx' 5 | 6 | import sys, json, os 7 | from urllib import request 8 | 9 | if (len(sys.argv) < 2): 10 | print('请给出您的 GitHub ID 作为参数') 11 | exit() 12 | 13 | github_id = sys.argv[1] 14 | if (len(github_id) <= 0): 15 | print('请给出您的 GitHub ID 作为参数') 16 | exit() 17 | 18 | print('(查询中...)') 19 | 20 | PER_PAGE_REPO_MAX_COUNT = 30 21 | cur_page = 1 22 | total_repo = 0 23 | total_star = 0 24 | 25 | while True: 26 | 27 | url = 'https://api.github.com/users/%s/repos?page=%s' % (github_id, cur_page) 28 | 29 | with request.urlopen(url) as f: 30 | data = f.read() 31 | 32 | repo_json = data.decode('utf-8') 33 | repo_array = json.loads(repo_json) 34 | if (type(repo_array) != list): 35 | break 36 | 37 | for repo in repo_array: 38 | if (type(repo) != dict): 39 | continue 40 | total_repo += 1 41 | star = repo['stargazers_count'] 42 | total_star += star 43 | 44 | if (len(repo_array) < PER_PAGE_REPO_MAX_COUNT): 45 | break 46 | 47 | cur_page += 1 48 | 49 | prompt = '' 50 | 51 | if (total_repo == 0 and total_star == 0): 52 | prompt = '%s,您的 GitHub 共有 0 个repo,0 个star(您的GitHub ID 敲错了??)' % github_id 53 | else: 54 | prompt = '%s,您的 GitHub 共有 %s 个repo,%s 个star' % (github_id, total_repo, total_star) 55 | 56 | print('=== %s ===' % prompt) 57 | sayPromptCommand = 'say %s' % prompt 58 | os.system(sayPromptCommand) 59 | --------------------------------------------------------------------------------