本文整理汇总了Python中github3.GitHub.authorize方法的典型用法代码示例。如果您正苦于以下问题:Python GitHub.authorize方法的具体用法?Python GitHub.authorize怎么用?Python GitHub.authorize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github3.GitHub
的用法示例。
在下文中一共展示了GitHub.authorize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ServiceGithub
# 需要导入模块: from github3 import GitHub [as 别名]
# 或者: from github3.GitHub import authorize [as 别名]
class ServiceGithub(ServicesMgr):
def __init__(self, token=None):
self.scope = ['public_repo']
self.REQ_TOKEN = 'https://github.com/login/oauth/authorize'
self.AUTH_URL = 'https://github.com/login/oauth/authorize'
self.ACC_TOKEN = 'https://github.com/login/oauth/access_token'
self.username = settings.TH_GITHUB['username']
self.password = settings.TH_GITHUB['password']
self.consumer_key = settings.TH_GITHUB['consumer_key']
self.consumer_secret = settings.TH_GITHUB['consumer_secret']
self.token = token
if self.token:
token_key, token_secret = self.token.split('#TH#')
self.gh = GitHub(token=token_key)
else:
self.gh = GitHub(username=self.username, password=self.password)
def read_data(self, **kwargs):
"""
get the data from the service
:param kwargs: contain keyword args : trigger_id at least
:type kwargs: dict
:rtype: list
"""
# date_triggered = kwargs['date_triggered']
trigger_id = kwargs['trigger_id']
data = list()
cache.set('th_github_' + str(trigger_id), data)
def process_data(self, **kwargs):
"""
get the data from the cache
:param kwargs: contain keyword args : trigger_id at least
:type kwargs: dict
"""
kw = {'cache_stack': 'th_github', 'trigger_id': str(kwargs['trigger_id'])}
return super(ServiceGithub, self).process_data(**kw)
def save_data(self, trigger_id, **data):
"""
let's save the data
:param trigger_id: trigger ID from which to save data
:param data: the data to check to be used and save
:type trigger_id: int
:type data: dict
:return: the status of the save statement
:rtype: boolean
"""
from th_github.models import Github
status = False
if self.token:
title = self.set_title(data)
body = self.set_content(data)
# get the details of this trigger
trigger = Github.objects.get(trigger_id=trigger_id)
# check if it remains more than 1 access
# then we can create an issue
limit = self.gh.ratelimit_remaining
if limit > 1:
# repo goes to "owner"
# project goes to "repository"
r = self.gh.create_issue(trigger.repo,
trigger.project,
title,
body)
else:
# rate limite reach
logger.warn("Rate limit reached")
# put again in cache the data that could not be
# published in Github yet
cache.set('th_github_' + str(trigger_id), data, version=2)
return True
sentance = str('github {} created').format(r)
logger.debug(sentance)
status = True
else:
logger.critical(
"no token or link provided for trigger ID {} ".format(trigger_id))
status = False
return status
def auth(self, request):
"""
let's auth the user to the Service
"""
callback_url = 'http://%s%s' % (
request.get_host(), reverse('github_callback'))
auth = self.gh.authorize(self.username,
self.password,
self.scope,
'',
'',
self.consumer_key,
#.........这里部分代码省略.........
示例2: Command
# 需要导入模块: from github3 import GitHub [as 别名]
# 或者: from github3.GitHub import authorize [as 别名]
class Command(object):
__metaclass__ = ABCMeta
name = None
usage = None
repository = ()
user = ''
subcommands = {}
SUCCESS = 0
FAILURE = 1
COMMAND_UNKNOWN = 127
def __init__(self):
super(Command, self).__init__()
assert self.name
commands[self.name] = self
self.gh = GitHub()
self.gh.set_user_agent('github-cli/{0} (http://git.io/MEmEmw)'.format(
__version__
))
self.parser = CustomOptionParser(usage=self.usage)
@abstractmethod
def run(self, options, args):
return self.FAILURE
def get_repo(self, options):
self.repo = None
if self.repository:
self.repo = self.gh.repository(*self.repository)
if not (self.repo or options.loc_aware):
self.parser.error('A repository is required.')
def get_user(self):
if not self.user:
self.login()
self.user = self.gh.user()
def login(self):
# Get the full path to the configuration file
config = github_config()
parser = ConfigParser()
# Check to make sure the file exists and we are allowed to read it
if os.path.isfile(config) and os.access(config, os.R_OK | os.W_OK):
parser.readfp(open(config))
self.gh.login(token=parser.get('github', 'token'))
else:
# Either the file didn't exist or we didn't have the correct
# permissions
user = ''
while not user:
# We will not stop until we are given a username
user = input('Username: ')
self.user = user
pw = ''
while not pw:
# Nor will we stop until we're given a password
pw = getpass('Password: ')
# Get an authorization for this
auth = self.gh.authorize(
user, pw, ['user', 'repo', 'gist'], 'github-cli',
'http://git.io/MEmEmw'
)
parser.add_section('github')
parser.set('github', 'token', auth.token)
self.gh.login(token=auth.token)
# Create the file if it doesn't exist. Otherwise completely blank
# out what was there before. Kind of dangerous and destructive but
# somewhat necessary
parser.write(open(config, 'w+'))
def help(self):
self.parser.print_help()
if self.subcommands:
print('\nSubcommands:')
for command in sorted(self.subcommands.keys()):
print(' {0}:\n\t{1}'.format(
command, self.subcommands[command]
))
sys.exit(0)
示例3: ServiceGithub
# 需要导入模块: from github3 import GitHub [as 别名]
# 或者: from github3.GitHub import authorize [as 别名]
class ServiceGithub(ServicesMgr):
def __init__(self, token=None, **kwargs):
super(ServiceGithub, self).__init__(token, **kwargs)
self.scope = ['public_repo']
self.REQ_TOKEN = 'https://github.com/login/oauth/authorize'
self.AUTH_URL = 'https://github.com/login/oauth/authorize'
self.ACC_TOKEN = 'https://github.com/login/oauth/access_token'
self.username = settings.TH_GITHUB['username']
self.password = settings.TH_GITHUB['password']
self.consumer_key = settings.TH_GITHUB['consumer_key']
self.consumer_secret = settings.TH_GITHUB['consumer_secret']
self.token = token
self.oauth = 'oauth1'
self.service = 'ServiceGithub'
if self.token:
token_key, token_secret = self.token.split('#TH#')
self.gh = GitHub(token=token_key)
else:
self.gh = GitHub(username=self.username, password=self.password)
def gh_footer(self, trigger, issue):
link = 'https://github.com/{0}/{1}/issues/{2}'.format(
trigger.repo, trigger.project, issue.id)
provided_by = _('Provided by')
provided_from = _('from')
footer_from = "<br/><br/>{} <em>{}</em> {} <a href='{}'>{}</a>"
return footer_from.format(provided_by, trigger.trigger.description,
provided_from, link, link)
def read_data(self, **kwargs):
"""
get the data from the service
:param kwargs: contain keyword args : trigger_id at least
:type kwargs: dict
:rtype: list
"""
trigger_id = kwargs.get('trigger_id')
date_triggered = str(kwargs.get('date_triggered')).replace(' ', 'T')
data = list()
if self.token:
# check if it remains more than 1 access
# then we can create an issue
if self.gh.ratelimit_remaining > 1:
import pypandoc
trigger = Github.objects.get(trigger_id=trigger_id)
issues = self.gh.issues_on(trigger.repo,
trigger.project,
since=date_triggered)
for issue in issues:
content = pypandoc.convert(issue.body, 'md', format='html')
content += self.gh_footer(trigger, issue)
data.append({'title': issue.title, 'content': content})
cache.set('th_github_' + str(trigger_id), data)
else:
# rate limit reach, do nothing right now
logger.warn("Rate limit reached")
else:
logger.critical("no token provided")
return data
def save_data(self, trigger_id, **data):
"""
let's save the data
:param trigger_id: trigger ID from which to save data
:param data: the data to check to be used and save
:type trigger_id: int
:type data: dict
:return: the status of the save statement
:rtype: boolean
"""
if self.token:
title = self.set_title(data)
body = self.set_content(data)
# get the details of this trigger
trigger = Github.objects.get(trigger_id=trigger_id)
# check if it remains more than 1 access
# then we can create an issue
limit = self.gh.ratelimit_remaining
if limit > 1:
# repo goes to "owner"
# project goes to "repository"
r = self.gh.create_issue(trigger.repo,
trigger.project,
title,
body)
else:
# rate limit reach
logger.warn("Rate limit reached")
# put again in cache the data that could not be
#.........这里部分代码省略.........