├── .gitignore ├── LICENSE ├── README.md ├── github_email ├── __init__.py └── main.py ├── screenshots └── Screenshot from 2016-06-26 06:41:23.png ├── setup.cfg └── setup.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 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Prabhakar Gupta 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 | # github_email 2 | 3 | [![PyPI version](https://badge.fury.io/py/github_email.svg)](https://badge.fury.io/py/github_email) 4 | [![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org) 5 | 6 | Get a list of email IDs of any valid GitHub user from one function call **even if there are no public emails** for that user 7 | 8 | It checks for all the public commits of the user and if the name of the author of commit is same as the name of user, it fetches that email ID. 9 | 10 | ## Installation 11 | ### Using pip 12 | ```pip 13 | pip install github_email 14 | ``` 15 | ### Using Git 16 | ``` 17 | git clone https://github.com/prabhakar267/github_email.git 18 | cd github_email 19 | python setup.py install 20 | ``` 21 | 22 | ## Usage 23 | 24 | ```python 25 | import github_email 26 | 27 | # get JSON response for user 28 | response = github_email.get(, ) 29 | 30 | if response['success']: 31 | # prints a list of emails retrieved from public commits of user 32 | print response['email'] 33 | else: 34 | # prints the error message related to any error that occured 35 | print response['message'] 36 | 37 | ``` 38 | 39 | ## Example 40 | ![github_email](screenshots/Screenshot from 2016-06-26 06:41:23.png?raw=true) 41 | 42 | ## Inspiration 43 | [**github-email**](https://github.com/paulirish/github-email) by `paulirish` 44 | I wanted to write a module, so as to use this in other projects 45 | -------------------------------------------------------------------------------- /github_email/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: prabhakar 3 | # @Date: 2016-06-25 22:32:49 4 | # @Last Modified by: Prabhakar Gupta 5 | # @Last Modified time: 2016-06-26 06:16:48 6 | 7 | from main import get 8 | -------------------------------------------------------------------------------- /github_email/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: prabhakar 3 | # @Date: 2016-06-23 00:22:41 4 | # @Last Modified by: Prabhakar Gupta 5 | # @Last Modified time: 2016-12-25 20:36:29 6 | 7 | import requests 8 | import json 9 | 10 | GITHUB_URL = "https://api.github.com/" 11 | 12 | """ 13 | Function to get JSON response from a URL 14 | :params: 15 | url string 16 | :return: 17 | JSON 18 | """ 19 | def __get_json_response(url): 20 | response = requests.get(url) 21 | return json.loads(response.text) 22 | 23 | """ 24 | Function to add email to a set of emails and set a loop break flag 25 | 26 | :params: 27 | email_set set set of all the emails for the user 28 | email string new email to be added 29 | max_len integer maximum number of emails to be extracted 30 | :return: 31 | email_set set set of all the emails for the user 32 | break_flag boolean if max_limit is reached, break_flag is set to True 33 | """ 34 | def __add_email(email_set, email, max_len): 35 | email_set = email_set | set([email]) 36 | break_flag = (len(email_set) >= max_len) 37 | 38 | return email_set, break_flag 39 | 40 | """ 41 | Function to get user emails using GitHub APIs 42 | 43 | :params: 44 | user string a valid GitHub username 45 | max_limit integer maximum number of email ID to be fetched 46 | :return: 47 | user_email set a set of all emails extracted 48 | message string if any error occurs, this holds the respective error message 49 | """ 50 | def __get_github_emails(user, max_limit): 51 | user_email = set([]) 52 | break_flag = False 53 | try: 54 | users_profile_url = GITHUB_URL + "users/{0}".format(user) 55 | response = __get_json_response(users_profile_url) 56 | 57 | # some error encountered 58 | if 'message' in response: 59 | if response['message'] == 'Not Found': 60 | return u'You need to enter a valid GitHub Username' 61 | else: 62 | return response['message'] 63 | 64 | 65 | user_name = response['name'] 66 | 67 | # if user has a public email, add that to the set of emails 68 | if response['email']: 69 | user_email, break_flag = __add_email(user_email, response['email'], max_limit) 70 | 71 | if not break_flag: 72 | users_repository_url = GITHUB_URL + "users/{0}/repos?type=owner&sort=updated".format(user) 73 | response = __get_json_response(users_repository_url) 74 | 75 | for repo in response: 76 | if not repo['fork']: 77 | users_repository_name = repo['full_name'] 78 | repos_commit_url = GITHUB_URL + "repos/{0}/commits".format(users_repository_name) 79 | commit_reponse = __get_json_response(repos_commit_url) 80 | 81 | possible_positions = ['committer', 'author'] 82 | 83 | for commit in commit_reponse: 84 | for i in possible_positions: 85 | if commit['commit'][i]['name'] == user_name: 86 | email_string = commit['commit'][i]['email'] 87 | if "noreply" not in email_string: 88 | user_email, break_flag = __add_email(user_email, email_string, max_limit) 89 | 90 | if break_flag: 91 | break 92 | 93 | if break_flag: 94 | break 95 | 96 | if len(user_email) > 0: 97 | return user_email 98 | else: 99 | return u'No emails found' 100 | 101 | except requests.exceptions.ConnectionError: 102 | return u'Proper internet connection not found' 103 | 104 | """ 105 | Function to get the emails associated to a username on GitHub 106 | 107 | :params: 108 | username string a valid GitHub username 109 | num integer maximum number of email ID to be fetched, default 1 110 | :return: 111 | response JSON response 112 | success boolean flag to determine other key in JSON 113 | email list if 'success' is True, list of all the emails fetched 114 | message string if 'success' is False, returns the error message 115 | """ 116 | def get(username, num=1): 117 | github_email_response = __get_github_emails(username, num) 118 | 119 | if type(github_email_response) == set: 120 | response = { 121 | 'success' : True, 122 | 'email': list(github_email_response) 123 | } 124 | else: 125 | response = { 126 | 'success' : False, 127 | 'message' : github_email_response, 128 | } 129 | 130 | return response 131 | -------------------------------------------------------------------------------- /screenshots/Screenshot from 2016-06-26 06:41:23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhakar267/github_email/eacede94633b1633552153251a386d38d41a6fd1/screenshots/Screenshot from 2016-06-26 06:41:23.png -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: prabhakar 3 | # @Date: 2016-06-25 20:13:13 4 | # @Last Modified by: Prabhakar Gupta 5 | # @Last Modified time: 2016-12-25 20:53:28 6 | 7 | from setuptools import setup, find_packages 8 | 9 | setup( 10 | name='github_email', 11 | packages=find_packages(), 12 | version='0.0.5', 13 | description='Get email ID of any GitHub user', 14 | long_description='Get a list of email IDs of any valid GitHub user from one function call even if there are no public email for that user', 15 | author='Prabhakar Gupta', 16 | author_email='prabhakargupta267@gmail.com', 17 | url='https://github.com/prabhakar267/github_email', 18 | download_url='https://github.com/prabhakar267/github_email/tarball/0.0.5', 19 | keywords=['github', 'email', 'user', 'public', 'commit', 'get'], 20 | license='MIT', 21 | include_package_data = True, 22 | install_requires=['requests'], 23 | ) 24 | --------------------------------------------------------------------------------