当前位置: 首页>>代码示例>>Python>>正文


Python GitHub.login方法代码示例

本文整理汇总了Python中github3.GitHub.login方法的典型用法代码示例。如果您正苦于以下问题:Python GitHub.login方法的具体用法?Python GitHub.login怎么用?Python GitHub.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github3.GitHub的用法示例。


在下文中一共展示了GitHub.login方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GitHub

# 需要导入模块: from github3 import GitHub [as 别名]
# 或者: from github3.GitHub import login [as 别名]
#!/usr/bin/env python

import os
from github3 import GitHub
from flask.json import jsonify
from requests_oauthlib import OAuth2Session
from diggit import Digger
from flask import Flask, request, redirect, session, url_for

GH = GitHub()
GH.login(token=os.environ.get('GITHUB_ACCESS_TOKEN'))
user_gh_profile = GH.me()
gh_scraper = Digger(GH)
# GH.ratelimit_remaining
app = Flask(__name__)

@app.route("/")
def home():
    return redirect(url_for('profile'))

@app.route("/profile", methods=["GET"])
def profile():
    """
    """
    return jsonify(user_gh_profile.as_dict())

@app.route("/search/", methods=["GET"])
@app.route("/search/<type>", methods=["GET"])
def scanner(type="user"):
    return jsonify(gh_scraper.get_class())
开发者ID:arcolife,项目名称:digGit,代码行数:32,代码来源:git_digger.py

示例2: Command

# 需要导入模块: from github3 import GitHub [as 别名]
# 或者: from github3.GitHub import login [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)
开发者ID:lyddonb,项目名称:github-cli,代码行数:86,代码来源:base.py

示例3: GitHub

# 需要导入模块: from github3 import GitHub [as 别名]
# 或者: from github3.GitHub import login [as 别名]
    B. Personal name if different
    C. Link to user profile on GitHub

"""

from __future__ import print_function

from os import environ

from github3 import GitHub


gh = GitHub()
token = environ.get('GITHUB_API_SECRET')
if token:
    gh.login(token=token)


def get_markdown_output(contributors):
    links = ""
    output = []
    for contributor in contributors:
        print('.', end='', flush=True)
        user = gh.user(contributor)
        if user.name.strip():
            output.append("* {name} ([@{username}])".format(
                name=user.name,
                username=user.login
            )
            )
        else:
开发者ID:jonafato,项目名称:contributors,代码行数:33,代码来源:contributors.py


注:本文中的github3.GitHub.login方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。