├── requirements.txt ├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── templates ├── languages.svg └── overview.svg ├── generate_images.py ├── README.md ├── github_stats.py └── LICENSE /requirements.txt: -------------------------------------------------------------------------------- 1 | requests 2 | aiohttp -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | data export-ignore 2 | generated export-ignore 3 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Generate Stats Images 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | schedule: 7 | - cron: "5 0 * * *" 8 | workflow_dispatch: 9 | 10 | permissions: 11 | contents: write 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | # Check out repository under $GITHUB_WORKSPACE, so the job can access it 19 | - uses: actions/checkout@v3 20 | 21 | # Run using Python 3.8 for consistency and aiohttp 22 | - name: Set up Python 3.8 23 | uses: actions/setup-python@v4 24 | with: 25 | python-version: '3.8' 26 | architecture: 'x64' 27 | cache: 'pip' 28 | 29 | # Install dependencies with `pip` 30 | - name: Install requirements 31 | run: | 32 | python3 -m pip install --upgrade pip setuptools wheel 33 | python3 -m pip install -r requirements.txt 34 | 35 | # Generate all statistics images 36 | - name: Generate images 37 | run: | 38 | python3 --version 39 | python3 generate_images.py 40 | env: 41 | ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | EXCLUDED: ${{ secrets.EXCLUDED }} 44 | EXCLUDED_LANGS: ${{ secrets.EXCLUDED_LANGS }} 45 | EXCLUDE_FORKED_REPOS: true 46 | 47 | # Commit all changed files to the repository 48 | - name: Commit to the repo 49 | run: | 50 | git config --global user.name "jstrieb/github-stats" 51 | git config --global user.email "github-stats[bot]@jstrieb.github.io" 52 | git add . 53 | # Force the build to succeed, even if no files were changed 54 | git commit -m 'Update generated files' || true 55 | git push 56 | -------------------------------------------------------------------------------- /.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 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | # Vim swap files 132 | *.swp 133 | *.swo 134 | 135 | # PyCharm project files 136 | .idea 137 | -------------------------------------------------------------------------------- /templates/languages.svg: -------------------------------------------------------------------------------- 1 | 2 | 125 | 126 | 127 | 128 | 129 |
130 | 131 |

Languages Used (By File Size)

132 | 133 |
134 | 135 | {{ progress }} 136 | 137 |
138 | 139 |
    140 | 141 | {{ lang_list }} 142 | 143 |
144 | 145 |
146 |
147 |
148 |
149 |
150 | -------------------------------------------------------------------------------- /generate_images.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import asyncio 4 | import os 5 | import re 6 | 7 | import aiohttp 8 | 9 | from github_stats import Stats 10 | 11 | 12 | ################################################################################ 13 | # Helper Functions 14 | ################################################################################ 15 | 16 | 17 | def generate_output_folder() -> None: 18 | """ 19 | Create the output folder if it does not already exist 20 | """ 21 | if not os.path.isdir("generated"): 22 | os.mkdir("generated") 23 | 24 | 25 | ################################################################################ 26 | # Individual Image Generation Functions 27 | ################################################################################ 28 | 29 | 30 | async def generate_overview(s: Stats) -> None: 31 | """ 32 | Generate an SVG badge with summary statistics 33 | :param s: Represents user's GitHub statistics 34 | """ 35 | with open("templates/overview.svg", "r") as f: 36 | output = f.read() 37 | 38 | output = re.sub("{{ name }}", await s.name, output) 39 | output = re.sub("{{ stars }}", f"{await s.stargazers:,}", output) 40 | output = re.sub("{{ forks }}", f"{await s.forks:,}", output) 41 | output = re.sub("{{ contributions }}", f"{await s.total_contributions:,}", output) 42 | changed = (await s.lines_changed)[0] + (await s.lines_changed)[1] 43 | output = re.sub("{{ lines_changed }}", f"{changed:,}", output) 44 | output = re.sub("{{ views }}", f"{await s.views:,}", output) 45 | output = re.sub("{{ repos }}", f"{len(await s.repos):,}", output) 46 | 47 | generate_output_folder() 48 | with open("generated/overview.svg", "w") as f: 49 | f.write(output) 50 | 51 | 52 | async def generate_languages(s: Stats) -> None: 53 | """ 54 | Generate an SVG badge with summary languages used 55 | :param s: Represents user's GitHub statistics 56 | """ 57 | with open("templates/languages.svg", "r") as f: 58 | output = f.read() 59 | 60 | progress = "" 61 | lang_list = "" 62 | sorted_languages = sorted( 63 | (await s.languages).items(), reverse=True, key=lambda t: t[1].get("size") 64 | ) 65 | delay_between = 150 66 | for i, (lang, data) in enumerate(sorted_languages): 67 | color = data.get("color") 68 | color = color if color is not None else "#000000" 69 | progress += ( 70 | f'' 73 | ) 74 | lang_list += f""" 75 |
  • 76 | 79 | {lang} 80 | {data.get("prop", 0):0.2f}% 81 |
  • 82 | 83 | """ 84 | 85 | output = re.sub(r"{{ progress }}", progress, output) 86 | output = re.sub(r"{{ lang_list }}", lang_list, output) 87 | 88 | generate_output_folder() 89 | with open("generated/languages.svg", "w") as f: 90 | f.write(output) 91 | 92 | 93 | ################################################################################ 94 | # Main Function 95 | ################################################################################ 96 | 97 | 98 | async def main() -> None: 99 | """ 100 | Generate all badges 101 | """ 102 | access_token = os.getenv("ACCESS_TOKEN") 103 | if not access_token: 104 | # access_token = os.getenv("GITHUB_TOKEN") 105 | raise Exception("A personal access token is required to proceed!") 106 | user = os.getenv("GITHUB_ACTOR") 107 | if user is None: 108 | raise RuntimeError("Environment variable GITHUB_ACTOR must be set.") 109 | exclude_repos = os.getenv("EXCLUDED") 110 | excluded_repos = ( 111 | {x.strip() for x in exclude_repos.split(",")} if exclude_repos else None 112 | ) 113 | exclude_langs = os.getenv("EXCLUDED_LANGS") 114 | excluded_langs = ( 115 | {x.strip() for x in exclude_langs.split(",")} if exclude_langs else None 116 | ) 117 | # Convert a truthy value to a Boolean 118 | raw_ignore_forked_repos = os.getenv("EXCLUDE_FORKED_REPOS") 119 | ignore_forked_repos = ( 120 | not not raw_ignore_forked_repos 121 | and raw_ignore_forked_repos.strip().lower() != "false" 122 | ) 123 | async with aiohttp.ClientSession() as session: 124 | s = Stats( 125 | user, 126 | access_token, 127 | session, 128 | exclude_repos=excluded_repos, 129 | exclude_langs=excluded_langs, 130 | ignore_forked_repos=ignore_forked_repos, 131 | ) 132 | await asyncio.gather(generate_languages(s), generate_overview(s)) 133 | 134 | 135 | if __name__ == "__main__": 136 | asyncio.run(main()) 137 | -------------------------------------------------------------------------------- /templates/overview.svg: -------------------------------------------------------------------------------- 1 | 2 | 82 | 83 | 84 | 85 | 86 |
    87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
    {{ name }}'s GitHub Statistics
    Stars{{ stars }}
    Forks{{ forks }}
    All-time contributions{{ contributions }}
    Lines of code changed{{ lines_changed }}
    Repository views (past two weeks){{ views }}
    Repositories with contributions{{ repos }}
    108 | 109 |
    110 |
    111 |
    112 |
    113 |
    114 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [GitHub Stats Visualization](https://github.com/jstrieb/github-stats) 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Generate visualizations of GitHub user and repository statistics with GitHub 14 | Actions. Visualizations can include data for both private repositories, and for 15 | repositories you have contributed to, but do not own. 16 | 17 | Generated images automatically switch between GitHub light theme and GitHub 18 | dark theme. 19 | 20 | ## Background 21 | 22 | When someone views a profile on GitHub, it is often because they are curious 23 | about a user's open source projects and contributions. Unfortunately, that 24 | user's stars, forks, and pinned repositories do not necessarily reflect the 25 | contributions they make to private repositories. The data likewise does not 26 | present a complete picture of the user's total contributions beyond the current 27 | year. 28 | 29 | This project aims to collect a variety of profile and repository statistics 30 | using the GitHub API. It then generates images that can be displayed in 31 | repository READMEs, or in a user's [Profile 32 | README](https://docs.github.com/en/github/setting-up-and-managing-your-github-profile/managing-your-profile-readme). 33 | 34 | Since the project runs on GitHub Actions, no server is required to regularly 35 | regenerate the images with updated statistics. Likewise, since the user runs 36 | the analysis code themselves via GitHub Actions, they can use their GitHub 37 | access token to collect statistics on private repositories that an external 38 | service would be unable to access. 39 | 40 | ## Disclaimer 41 | 42 | If the project is used with an access token that has sufficient permissions to 43 | read private repositories, it may leak details about those repositories in 44 | error messages. For example, the `aiohttp` library—used for asynchronous API 45 | requests—may include the requested URL in exceptions, which can leak the name 46 | of private repositories. If there is an exception caused by `aiohttp`, this 47 | exception will be viewable in the Actions tab of the repository fork, and 48 | anyone may be able to see the name of one or more private repositories. 49 | 50 | Due to some issues with the GitHub statistics API, there are some situations 51 | where it returns inaccurate results. Specifically, the repository view count 52 | statistics and total lines of code modified are probably somewhat inaccurate. 53 | Unexpectedly, these values will become more accurate over time as GitHub 54 | caches statistics for your repositories. Additionally, repositories that were 55 | last contributed to more than a year ago may not be included in the statistics 56 | due to limitations in the results returned by the API. 57 | 58 | For more information on inaccuracies, see issue 59 | [#2](https://github.com/jstrieb/github-stats/issues/2), 60 | [#3](https://github.com/jstrieb/github-stats/issues/3), and 61 | [#13](https://github.com/jstrieb/github-stats/issues/13). 62 | 63 | # Installation 64 | 65 | 66 | 67 | 1. Create a personal access token (not the default GitHub Actions token) using 68 | the instructions 69 | [here](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). 70 | Personal access token must have permissions: `read:user` and `repo`. Copy 71 | the access token when it is generated – if you lose it, you will have to 72 | regenerate the token. 73 | - Some users are reporting that it can take a few minutes for the personal 74 | access token to work. For more, see 75 | [#30](https://github.com/jstrieb/github-stats/issues/30). 76 | 2. Create a copy of this repository by clicking 77 | [here](https://github.com/jstrieb/github-stats/generate). Note: this is 78 | **not** the same as forking a copy because it copies everything fresh, 79 | without the huge commit history. 80 | 3. Go to the "Secrets" page of your copy of the repository. If this is the 81 | README of your copy, click [this link](../../settings/secrets/actions) to go 82 | to the "Secrets" page. Otherwise, go to the "Settings" tab of the 83 | newly-created repository and go to the "Secrets" page (bottom left). 84 | 4. Create a new secret with the name `ACCESS_TOKEN` and paste the copied 85 | personal access token as the value. 86 | 5. It is possible to change the type of statistics reported by adding other 87 | repository secrets. 88 | - To ignore certain repos, add them (in owner/name format e.g., 89 | `jstrieb/github-stats`) separated by commas to a new secret—created as 90 | before—called `EXCLUDED`. 91 | - To ignore certain languages, add them (separated by commas) to a new 92 | secret called `EXCLUDED_LANGS`. For example, to exclude HTML and TeX you 93 | could set the value to `html,tex`. 94 | - To show statistics only for "owned" repositories and not forks with 95 | contributions, add an environment variable (under the `env` header in the 96 | [main 97 | workflow](https://github.com/jstrieb/github-stats/blob/master/.github/workflows/main.yml)) 98 | called `EXCLUDE_FORKED_REPOS` with a value of `true`. 99 | - These other values are added as secrets by default to prevent leaking 100 | information about private repositories. If you're not worried about that, 101 | you can change the values directly [in the Actions workflow 102 | itself](https://github.com/jstrieb/github-stats/blob/05de1314b870febd44d19ad2f55d5e59d83f5857/.github/workflows/main.yml#L48-L53). 103 | 6. Go to the [Actions 104 | Page](../../actions?query=workflow%3A"Generate+Stats+Images") and press "Run 105 | Workflow" on the right side of the screen to generate images for the first 106 | time. 107 | - The images will be automatically regenerated every 24 hours, but they can 108 | be regenerated manually by running the workflow this way. 109 | 7. Take a look at the images that have been created in the 110 | [`generated`](generated) folder. 111 | 8. To add your statistics to your GitHub Profile README, copy and paste the 112 | following lines of code into your markdown content. Change the `username` 113 | value to your GitHub username. 114 | ```md 115 | ![](https://raw.githubusercontent.com/username/github-stats/master/generated/overview.svg#gh-dark-mode-only) 116 | ![](https://raw.githubusercontent.com/username/github-stats/master/generated/overview.svg#gh-light-mode-only) 117 | ``` 118 | ```md 119 | ![](https://raw.githubusercontent.com/username/github-stats/master/generated/languages.svg#gh-dark-mode-only) 120 | ![](https://raw.githubusercontent.com/username/github-stats/master/generated/languages.svg#gh-light-mode-only) 121 | ``` 122 | 9. Link back to this repository so that others can generate their own 123 | statistics images. 124 | 10. Star this repo if you like it! 125 | 126 | 127 | # Support the Project 128 | 129 | There are a few things you can do to support the project: 130 | 131 | - Star the repository (and follow me on GitHub for more) 132 | - Share and upvote on sites like Twitter, Reddit, and Hacker News 133 | - Report any bugs, glitches, or errors that you find 134 | 135 | These things motivate me to to keep sharing what I build, and they provide 136 | validation that my work is appreciated! They also help me improve the 137 | project. Thanks in advance! 138 | 139 | If you are insistent on spending money to show your support, I encourage you to 140 | instead make a generous donation to one of the following organizations. By advocating 141 | for Internet freedoms, organizations like these help me to feel comfortable 142 | releasing work publicly on the Web. 143 | 144 | - [Electronic Frontier Foundation](https://supporters.eff.org/donate/) 145 | - [Signal Foundation](https://signal.org/donate/) 146 | - [Mozilla](https://donate.mozilla.org/en-US/) 147 | - [The Internet Archive](https://archive.org/donate/index.php) 148 | 149 | 150 | # Related Projects 151 | 152 | - Inspired by a desire to improve upon 153 | [anuraghazra/github-readme-stats](https://github.com/anuraghazra/github-readme-stats) 154 | - Makes use of [GitHub Octicons](https://primer.style/octicons/) to precisely 155 | match the GitHub UI 156 | -------------------------------------------------------------------------------- /github_stats.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import asyncio 4 | import os 5 | from typing import Dict, List, Optional, Set, Tuple, Any, cast 6 | 7 | import aiohttp 8 | import requests 9 | 10 | 11 | ############################################################################### 12 | # Main Classes 13 | ############################################################################### 14 | 15 | 16 | class Queries(object): 17 | """ 18 | Class with functions to query the GitHub GraphQL (v4) API and the REST (v3) 19 | API. Also includes functions to dynamically generate GraphQL queries. 20 | """ 21 | 22 | def __init__( 23 | self, 24 | username: str, 25 | access_token: str, 26 | session: aiohttp.ClientSession, 27 | max_connections: int = 10, 28 | ): 29 | self.username = username 30 | self.access_token = access_token 31 | self.session = session 32 | self.semaphore = asyncio.Semaphore(max_connections) 33 | 34 | async def query(self, generated_query: str) -> Dict: 35 | """ 36 | Make a request to the GraphQL API using the authentication token from 37 | the environment 38 | :param generated_query: string query to be sent to the API 39 | :return: decoded GraphQL JSON output 40 | """ 41 | headers = { 42 | "Authorization": f"Bearer {self.access_token}", 43 | } 44 | try: 45 | async with self.semaphore: 46 | r_async = await self.session.post( 47 | "https://api.github.com/graphql", 48 | headers=headers, 49 | json={"query": generated_query}, 50 | ) 51 | result = await r_async.json() 52 | if result is not None: 53 | return result 54 | except: 55 | print("aiohttp failed for GraphQL query") 56 | # Fall back on non-async requests 57 | async with self.semaphore: 58 | r_requests = requests.post( 59 | "https://api.github.com/graphql", 60 | headers=headers, 61 | json={"query": generated_query}, 62 | ) 63 | result = r_requests.json() 64 | if result is not None: 65 | return result 66 | return dict() 67 | 68 | async def query_rest(self, path: str, params: Optional[Dict] = None) -> Dict: 69 | """ 70 | Make a request to the REST API 71 | :param path: API path to query 72 | :param params: Query parameters to be passed to the API 73 | :return: deserialized REST JSON output 74 | """ 75 | 76 | for _ in range(60): 77 | headers = { 78 | "Authorization": f"token {self.access_token}", 79 | } 80 | if params is None: 81 | params = dict() 82 | if path.startswith("/"): 83 | path = path[1:] 84 | try: 85 | async with self.semaphore: 86 | r_async = await self.session.get( 87 | f"https://api.github.com/{path}", 88 | headers=headers, 89 | params=tuple(params.items()), 90 | ) 91 | if r_async.status == 202: 92 | # print(f"{path} returned 202. Retrying...") 93 | print(f"A path returned 202. Retrying...") 94 | await asyncio.sleep(2) 95 | continue 96 | 97 | result = await r_async.json() 98 | if result is not None: 99 | return result 100 | except: 101 | print("aiohttp failed for rest query") 102 | # Fall back on non-async requests 103 | async with self.semaphore: 104 | r_requests = requests.get( 105 | f"https://api.github.com/{path}", 106 | headers=headers, 107 | params=tuple(params.items()), 108 | ) 109 | if r_requests.status_code == 202: 110 | print(f"A path returned 202. Retrying...") 111 | await asyncio.sleep(2) 112 | continue 113 | elif r_requests.status_code == 200: 114 | return r_requests.json() 115 | # print(f"There were too many 202s. Data for {path} will be incomplete.") 116 | print("There were too many 202s. Data for this repository will be incomplete.") 117 | return dict() 118 | 119 | @staticmethod 120 | def repos_overview( 121 | contrib_cursor: Optional[str] = None, owned_cursor: Optional[str] = None 122 | ) -> str: 123 | """ 124 | :return: GraphQL query with overview of user repositories 125 | """ 126 | return f"""{{ 127 | viewer {{ 128 | login, 129 | name, 130 | repositories( 131 | first: 100, 132 | orderBy: {{ 133 | field: UPDATED_AT, 134 | direction: DESC 135 | }}, 136 | isFork: false, 137 | after: {"null" if owned_cursor is None else '"'+ owned_cursor +'"'} 138 | ) {{ 139 | pageInfo {{ 140 | hasNextPage 141 | endCursor 142 | }} 143 | nodes {{ 144 | nameWithOwner 145 | stargazers {{ 146 | totalCount 147 | }} 148 | forkCount 149 | languages(first: 10, orderBy: {{field: SIZE, direction: DESC}}) {{ 150 | edges {{ 151 | size 152 | node {{ 153 | name 154 | color 155 | }} 156 | }} 157 | }} 158 | }} 159 | }} 160 | repositoriesContributedTo( 161 | first: 100, 162 | includeUserRepositories: false, 163 | orderBy: {{ 164 | field: UPDATED_AT, 165 | direction: DESC 166 | }}, 167 | contributionTypes: [ 168 | COMMIT, 169 | PULL_REQUEST, 170 | REPOSITORY, 171 | PULL_REQUEST_REVIEW 172 | ] 173 | after: {"null" if contrib_cursor is None else '"'+ contrib_cursor +'"'} 174 | ) {{ 175 | pageInfo {{ 176 | hasNextPage 177 | endCursor 178 | }} 179 | nodes {{ 180 | nameWithOwner 181 | stargazers {{ 182 | totalCount 183 | }} 184 | forkCount 185 | languages(first: 10, orderBy: {{field: SIZE, direction: DESC}}) {{ 186 | edges {{ 187 | size 188 | node {{ 189 | name 190 | color 191 | }} 192 | }} 193 | }} 194 | }} 195 | }} 196 | }} 197 | }} 198 | """ 199 | 200 | @staticmethod 201 | def contrib_years() -> str: 202 | """ 203 | :return: GraphQL query to get all years the user has been a contributor 204 | """ 205 | return """ 206 | query { 207 | viewer { 208 | contributionsCollection { 209 | contributionYears 210 | } 211 | } 212 | } 213 | """ 214 | 215 | @staticmethod 216 | def contribs_by_year(year: str) -> str: 217 | """ 218 | :param year: year to query for 219 | :return: portion of a GraphQL query with desired info for a given year 220 | """ 221 | return f""" 222 | year{year}: contributionsCollection( 223 | from: "{year}-01-01T00:00:00Z", 224 | to: "{int(year) + 1}-01-01T00:00:00Z" 225 | ) {{ 226 | contributionCalendar {{ 227 | totalContributions 228 | }} 229 | }} 230 | """ 231 | 232 | @classmethod 233 | def all_contribs(cls, years: List[str]) -> str: 234 | """ 235 | :param years: list of years to get contributions for 236 | :return: query to retrieve contribution information for all user years 237 | """ 238 | by_years = "\n".join(map(cls.contribs_by_year, years)) 239 | return f""" 240 | query {{ 241 | viewer {{ 242 | {by_years} 243 | }} 244 | }} 245 | """ 246 | 247 | 248 | class Stats(object): 249 | """ 250 | Retrieve and store statistics about GitHub usage. 251 | """ 252 | 253 | def __init__( 254 | self, 255 | username: str, 256 | access_token: str, 257 | session: aiohttp.ClientSession, 258 | exclude_repos: Optional[Set] = None, 259 | exclude_langs: Optional[Set] = None, 260 | ignore_forked_repos: bool = False, 261 | ): 262 | self.username = username 263 | self._ignore_forked_repos = ignore_forked_repos 264 | self._exclude_repos = set() if exclude_repos is None else exclude_repos 265 | self._exclude_langs = set() if exclude_langs is None else exclude_langs 266 | self.queries = Queries(username, access_token, session) 267 | 268 | self._name: Optional[str] = None 269 | self._stargazers: Optional[int] = None 270 | self._forks: Optional[int] = None 271 | self._total_contributions: Optional[int] = None 272 | self._languages: Optional[Dict[str, Any]] = None 273 | self._repos: Optional[Set[str]] = None 274 | self._lines_changed: Optional[Tuple[int, int]] = None 275 | self._views: Optional[int] = None 276 | 277 | async def to_str(self) -> str: 278 | """ 279 | :return: summary of all available statistics 280 | """ 281 | languages = await self.languages_proportional 282 | formatted_languages = "\n - ".join( 283 | [f"{k}: {v:0.4f}%" for k, v in languages.items()] 284 | ) 285 | lines_changed = await self.lines_changed 286 | return f"""Name: {await self.name} 287 | Stargazers: {await self.stargazers:,} 288 | Forks: {await self.forks:,} 289 | All-time contributions: {await self.total_contributions:,} 290 | Repositories with contributions: {len(await self.repos)} 291 | Lines of code added: {lines_changed[0]:,} 292 | Lines of code deleted: {lines_changed[1]:,} 293 | Lines of code changed: {lines_changed[0] + lines_changed[1]:,} 294 | Project page views: {await self.views:,} 295 | Languages: 296 | - {formatted_languages}""" 297 | 298 | async def get_stats(self) -> None: 299 | """ 300 | Get lots of summary statistics using one big query. Sets many attributes 301 | """ 302 | self._stargazers = 0 303 | self._forks = 0 304 | self._languages = dict() 305 | self._repos = set() 306 | 307 | exclude_langs_lower = {x.lower() for x in self._exclude_langs} 308 | 309 | next_owned = None 310 | next_contrib = None 311 | while True: 312 | raw_results = await self.queries.query( 313 | Queries.repos_overview( 314 | owned_cursor=next_owned, contrib_cursor=next_contrib 315 | ) 316 | ) 317 | raw_results = raw_results if raw_results is not None else {} 318 | 319 | self._name = raw_results.get("data", {}).get("viewer", {}).get("name", None) 320 | if self._name is None: 321 | self._name = ( 322 | raw_results.get("data", {}) 323 | .get("viewer", {}) 324 | .get("login", "No Name") 325 | ) 326 | 327 | contrib_repos = ( 328 | raw_results.get("data", {}) 329 | .get("viewer", {}) 330 | .get("repositoriesContributedTo", {}) 331 | ) 332 | owned_repos = ( 333 | raw_results.get("data", {}).get("viewer", {}).get("repositories", {}) 334 | ) 335 | 336 | repos = owned_repos.get("nodes", []) 337 | if not self._ignore_forked_repos: 338 | repos += contrib_repos.get("nodes", []) 339 | 340 | for repo in repos: 341 | if repo is None: 342 | continue 343 | name = repo.get("nameWithOwner") 344 | if name in self._repos or name in self._exclude_repos: 345 | continue 346 | self._repos.add(name) 347 | self._stargazers += repo.get("stargazers").get("totalCount", 0) 348 | self._forks += repo.get("forkCount", 0) 349 | 350 | for lang in repo.get("languages", {}).get("edges", []): 351 | name = lang.get("node", {}).get("name", "Other") 352 | languages = await self.languages 353 | if name.lower() in exclude_langs_lower: 354 | continue 355 | if name in languages: 356 | languages[name]["size"] += lang.get("size", 0) 357 | languages[name]["occurrences"] += 1 358 | else: 359 | languages[name] = { 360 | "size": lang.get("size", 0), 361 | "occurrences": 1, 362 | "color": lang.get("node", {}).get("color"), 363 | } 364 | 365 | if owned_repos.get("pageInfo", {}).get( 366 | "hasNextPage", False 367 | ) or contrib_repos.get("pageInfo", {}).get("hasNextPage", False): 368 | next_owned = owned_repos.get("pageInfo", {}).get( 369 | "endCursor", next_owned 370 | ) 371 | next_contrib = contrib_repos.get("pageInfo", {}).get( 372 | "endCursor", next_contrib 373 | ) 374 | else: 375 | break 376 | 377 | # TODO: Improve languages to scale by number of contributions to 378 | # specific filetypes 379 | langs_total = sum([v.get("size", 0) for v in self._languages.values()]) 380 | for k, v in self._languages.items(): 381 | v["prop"] = 100 * (v.get("size", 0) / langs_total) 382 | 383 | @property 384 | async def name(self) -> str: 385 | """ 386 | :return: GitHub user's name (e.g., Jacob Strieb) 387 | """ 388 | if self._name is not None: 389 | return self._name 390 | await self.get_stats() 391 | assert self._name is not None 392 | return self._name 393 | 394 | @property 395 | async def stargazers(self) -> int: 396 | """ 397 | :return: total number of stargazers on user's repos 398 | """ 399 | if self._stargazers is not None: 400 | return self._stargazers 401 | await self.get_stats() 402 | assert self._stargazers is not None 403 | return self._stargazers 404 | 405 | @property 406 | async def forks(self) -> int: 407 | """ 408 | :return: total number of forks on user's repos 409 | """ 410 | if self._forks is not None: 411 | return self._forks 412 | await self.get_stats() 413 | assert self._forks is not None 414 | return self._forks 415 | 416 | @property 417 | async def languages(self) -> Dict: 418 | """ 419 | :return: summary of languages used by the user 420 | """ 421 | if self._languages is not None: 422 | return self._languages 423 | await self.get_stats() 424 | assert self._languages is not None 425 | return self._languages 426 | 427 | @property 428 | async def languages_proportional(self) -> Dict: 429 | """ 430 | :return: summary of languages used by the user, with proportional usage 431 | """ 432 | if self._languages is None: 433 | await self.get_stats() 434 | assert self._languages is not None 435 | 436 | return {k: v.get("prop", 0) for (k, v) in self._languages.items()} 437 | 438 | @property 439 | async def repos(self) -> Set[str]: 440 | """ 441 | :return: list of names of user's repos 442 | """ 443 | if self._repos is not None: 444 | return self._repos 445 | await self.get_stats() 446 | assert self._repos is not None 447 | return self._repos 448 | 449 | @property 450 | async def total_contributions(self) -> int: 451 | """ 452 | :return: count of user's total contributions as defined by GitHub 453 | """ 454 | if self._total_contributions is not None: 455 | return self._total_contributions 456 | 457 | self._total_contributions = 0 458 | years = ( 459 | (await self.queries.query(Queries.contrib_years())) 460 | .get("data", {}) 461 | .get("viewer", {}) 462 | .get("contributionsCollection", {}) 463 | .get("contributionYears", []) 464 | ) 465 | by_year = ( 466 | (await self.queries.query(Queries.all_contribs(years))) 467 | .get("data", {}) 468 | .get("viewer", {}) 469 | .values() 470 | ) 471 | for year in by_year: 472 | self._total_contributions += year.get("contributionCalendar", {}).get( 473 | "totalContributions", 0 474 | ) 475 | return cast(int, self._total_contributions) 476 | 477 | @property 478 | async def lines_changed(self) -> Tuple[int, int]: 479 | """ 480 | :return: count of total lines added, removed, or modified by the user 481 | """ 482 | if self._lines_changed is not None: 483 | return self._lines_changed 484 | additions = 0 485 | deletions = 0 486 | for repo in await self.repos: 487 | r = await self.queries.query_rest(f"/repos/{repo}/stats/contributors") 488 | for author_obj in r: 489 | # Handle malformed response from the API by skipping this repo 490 | if not isinstance(author_obj, dict) or not isinstance( 491 | author_obj.get("author", {}), dict 492 | ): 493 | continue 494 | author = author_obj.get("author", {}).get("login", "") 495 | if author != self.username: 496 | continue 497 | 498 | for week in author_obj.get("weeks", []): 499 | additions += week.get("a", 0) 500 | deletions += week.get("d", 0) 501 | 502 | self._lines_changed = (additions, deletions) 503 | return self._lines_changed 504 | 505 | @property 506 | async def views(self) -> int: 507 | """ 508 | Note: only returns views for the last 14 days (as-per GitHub API) 509 | :return: total number of page views the user's projects have received 510 | """ 511 | if self._views is not None: 512 | return self._views 513 | 514 | total = 0 515 | for repo in await self.repos: 516 | r = await self.queries.query_rest(f"/repos/{repo}/traffic/views") 517 | for view in r.get("views", []): 518 | total += view.get("count", 0) 519 | 520 | self._views = total 521 | return total 522 | 523 | 524 | ############################################################################### 525 | # Main Function 526 | ############################################################################### 527 | 528 | 529 | async def main() -> None: 530 | """ 531 | Used mostly for testing; this module is not usually run standalone 532 | """ 533 | access_token = os.getenv("ACCESS_TOKEN") 534 | user = os.getenv("GITHUB_ACTOR") 535 | if access_token is None or user is None: 536 | raise RuntimeError( 537 | "ACCESS_TOKEN and GITHUB_ACTOR environment variables cannot be None!" 538 | ) 539 | async with aiohttp.ClientSession() as session: 540 | s = Stats(user, access_token, session) 541 | print(await s.to_str()) 542 | 543 | 544 | if __name__ == "__main__": 545 | asyncio.run(main()) 546 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------