本文整理汇总了Python中github3.login方法的典型用法代码示例。如果您正苦于以下问题:Python github3.login方法的具体用法?Python github3.login怎么用?Python github3.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github3
的用法示例。
在下文中一共展示了github3.login方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_authorization
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def check_authorization(self, access_token):
"""OAuth applications can use this method to check token validity
without hitting normal rate limits because of failed login attempts.
If the token is valid, it will return True, otherwise it will return
False.
:returns: bool
"""
p = self._session.params
auth = (p.get('client_id'), p.get('client_secret'))
if access_token and auth:
url = self._build_url('applications', str(auth[0]), 'tokens',
str(access_token))
resp = self._get(url, auth=auth, params={
'client_id': None, 'client_secret': None
})
return self._boolean(resp, 200, 404)
return False
示例2: create_gist
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def create_gist(self, description, files, public=True):
"""Create a new gist.
If no login was provided, it will be anonymous.
:param str description: (required), description of gist
:param dict files: (required), file names with associated dictionaries
for content, e.g. ``{'spam.txt': {'content': 'File contents
...'}}``
:param bool public: (optional), make the gist public if True
:returns: :class:`Gist <github3.gists.Gist>`
"""
new_gist = {'description': description, 'public': public,
'files': files}
url = self._build_url('gists')
json = self._json(self._post(url, data=new_gist), 201)
return Gist(json, self) if json else None
示例3: iter_orgs
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def iter_orgs(self, login=None, number=-1, etag=None):
"""Iterate over public organizations for login if provided; otherwise
iterate over public and private organizations for the authenticated
user.
:param str login: (optional), user whose orgs you wish to list
:param int number: (optional), number of organizations to return.
Default: -1 returns all available organizations
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of
:class:`Organization <github3.orgs.Organization>`\ s
"""
if login:
url = self._build_url('users', login, 'orgs')
else:
url = self._build_url('user', 'orgs')
return self._iter(int(number), url, Organization, etag=etag)
示例4: iter_subscriptions
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def iter_subscriptions(self, login=None, number=-1, etag=None):
"""Iterate over repositories subscribed to by ``login`` or the
authenticated user.
:param str login: (optional), name of user whose subscriptions you want
to see
:param int number: (optional), number of repositories to return.
Default: -1 returns all repositories
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Repository <github3.repos.Repository>`
"""
if login:
return self.user(login).iter_subscriptions()
url = self._build_url('user', 'subscriptions')
return self._iter(int(number), url, Repository, etag=etag)
示例5: login
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def login(self, username=None, password=None, token=None,
two_factor_callback=None):
"""Logs the user into GitHub for protected API calls.
:param str username: login name
:param str password: password for the login
:param str token: OAuth token
:param func two_factor_callback: (optional), function you implement to
provide the Two Factor Authentication code to GitHub when necessary
"""
if username and password:
self._session.basic_auth(username, password)
elif token:
self._session.token_auth(token)
# The Session method handles None for free.
self._session.two_factor_auth_callback(two_factor_callback)
示例6: update_user
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def update_user(self, name=None, email=None, blog=None,
company=None, location=None, hireable=False, bio=None):
"""If authenticated as this user, update the information with
the information provided in the parameters. All parameters are
optional.
:param str name: e.g., 'John Smith', not login name
:param str email: e.g., 'john.smith@example.com'
:param str blog: e.g., 'http://www.example.com/jsmith/blog'
:param str company: company name
:param str location: where you are located
:param bool hireable: defaults to False
:param str bio: GitHub flavored markdown
:returns: bool
"""
user = self.user()
return user.update(name, email, blog, company, location, hireable,
bio)
示例7: __init__
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def __init__(self, user, token, owner, repo):
self.is_authed = False
# Auth stuff
self.user = user
self.token = token
self.gh = self.login()
if self.gh is None:
raise Exception("Failed to login")
# Remote repo stuff
if not owner:
self.owner = self.get_owner().rstrip()
else:
self.owner = owner
if not repo:
self.repo = self.get_repo().rstrip()
else:
self.repo = repo
self.curr_repo = self.gh.repository(str(self.owner), str(self.repo))
示例8: get_github
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def get_github():
config_path = os.path.expanduser('~/.lbry-release-tool.json')
if os.path.exists(config_path):
with open(config_path, 'r') as config_file:
config = json.load(config_file)
return github3.login(token=config['token'])
token = os.environ.get("GH_TOKEN")
if not token:
print('GitHub Credentials')
username = input('username: ')
password = getpass('password: ')
gh = github3.authorize(
username, password, ['repo'], 'lbry release tool',
two_factor_callback=lambda: input('Enter 2FA: ')
)
with open(config_path, 'w') as config_file:
json.dump({'token': gh.token}, config_file)
token = gh.token
return github3.login(token=token)
示例9: create_session
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def create_session(token=None):
"""
Create a github3.py session connected to GitHub.com
If token is not provided, will attempt to use the GITHUB_API_TOKEN
environment variable if present.
"""
if token is None:
token = os.environ.get("GITHUB_API_TOKEN", None)
gh_session = github3.login(token=token)
if gh_session is None:
raise RuntimeError("Invalid or missing GITHUB_API_TOKEN")
return gh_session
示例10: get_stats
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def get_stats(self, username="", password="", organization="llnl", force=True):
"""
Retrieves the emails for the users of the given organization.
"""
file_path = "../github_stats_output/users_emails.csv"
if force or not os.path.isfile(file_path):
my_github.login(username, password)
calls_beginning = self.logged_in_gh.ratelimit_remaining + 1
print("Rate Limit: " + str(calls_beginning))
my_github.get_org(organization)
count_members = my_github.get_mems_of_org()
my_github.write_to_file(file_path)
calls_remaining = self.logged_in_gh.ratelimit_remaining
calls_used = calls_beginning - calls_remaining
print(
"Rate Limit Remaining: "
+ str(calls_remaining)
+ "\nUsed "
+ str(calls_used)
+ " API calls."
)
示例11: get_stats
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def get_stats(self, username="", password="", organization="llnl", force=True):
"""
Retrieves the traffic for the users of the given organization.
Requires organization admin credentials token to access the data.
"""
stargazers_file_path = "../github_stats_output/stargazers.csv"
if force or not os.path.isfile(file_path):
my_github.login(username, password)
calls_beginning = self.logged_in_gh.ratelimit_remaining + 1
print("Rate Limit: " + str(calls_beginning))
my_github.get_org(organization)
my_github.get_repos()
my_github.write_to_file(file_path=stargazers_file_path)
# my_github.write_to_file(file_path=stargazers_file_path)
calls_remaining = self.logged_in_gh.ratelimit_remaining
calls_used = calls_beginning - calls_remaining
print(
"Rate Limit Remaining: "
+ str(calls_remaining)
+ "\nUsed "
+ str(calls_used)
+ " API calls."
)
示例12: _create_gh_release
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def _create_gh_release():
version = _get_stable_version()
name = 'Version {}'.format(version)
path = _path('dist/phy-{}.zip'.format(version))
assert op.exists(path)
with open(_path('.github_credentials'), 'r') as f:
user, pwd = f.read().strip().split(':')
gh = login(user, pwd)
phy = gh.repository('kwikteam', 'phy')
if input("About to create a GitHub release: are you sure?") != 'yes':
return
release = phy.create_release('v' + version,
name=name,
# draft=False,
# prerelease=False,
)
release.upload_asset('application/zip', op.basename(path), path)
示例13: fetch_organization_pulls
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def fetch_organization_pulls(organization_name):
"""
Returns a formatted string list of open pull request messages.
"""
client = login(token=GITHUB_API_TOKEN)
organization = client.organization(organization_name)
lines = []
for repository in organization.repositories():
if REPOSITORIES and repository.name.lower() not in REPOSITORIES:
continue
unchecked_pulls = fetch_repository_pulls(repository)
lines += format_pull_requests(unchecked_pulls, organization_name,
repository.name)
return lines
示例14: __init__
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def __init__(self, login='', password='', token=''):
super(GitHub, self).__init__({})
if token:
self.login(login, token=token)
elif login and password:
self.login(login, password)
示例15: authorize
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import login [as 别名]
def authorize(self, login, password, scopes=None, note='', note_url='',
client_id='', client_secret=''):
"""Obtain an authorization token from the GitHub API for the GitHub
API.
:param str login: (required)
:param str password: (required)
:param list scopes: (optional), areas you want this token to apply to,
i.e., 'gist', 'user'
:param str note: (optional), note about the authorization
:param str note_url: (optional), url for the application
:param str client_id: (optional), 20 character OAuth client key for
which to create a token
:param str client_secret: (optional), 40 character OAuth client secret
for which to create the token
:returns: :class:`Authorization <Authorization>`
"""
json = None
# TODO: Break this behaviour in 1.0 (Don't rely on self._session.auth)
auth = None
if self._session.auth:
auth = self._session.auth
elif login and password:
auth = (login, password)
if auth:
url = self._build_url('authorizations')
data = {'note': note, 'note_url': note_url,
'client_id': client_id, 'client_secret': client_secret}
if scopes:
data['scopes'] = scopes
with self._session.temporary_basic_auth(*auth):
json = self._json(self._post(url, data=data), 201)
return Authorization(json, self) if json else None