LoginSignup
0
0

More than 3 years have passed since last update.

MacでGithubAPIを使用してリポジトリ一覧を出力する

Last updated at Posted at 2019-12-15

目的

MacでGithubAPIを使用してリポジトリ一覧を出力した際の備忘録です

準備

PyGithubをインストール

$ pip install PyGithub

加えて、GitHubアカウントのアクセストークンを取得(Settingsから取得できる)

コード

リポジトリ一覧を出力する

#!/usr/bin/env python
from github import Github
 
token = 'xxxxxxxxxxxxxxx' # your access token
 
# or using an access token
g = Github(token)
 
for repo in g.get_user().get_repos():
    print(repo.name)

実行

(リポジトリ一覧が出力される)

Error対策

$ python github.py
Traceback (most recent call last):
  File "github.py", line 2, in <module>
    from github import Github
  File "/Users/seigo/Desktop/python/burger/github.py", line 2, in <module>
    from github import Github
ImportError: cannot import name 'Github' from 'github' (/Users/seigo/Desktop/python/burger/github.py)

サンプルコードをgitHub.pyという名前にすると上記エラーが出る。
sample.pyにリネームして解決。

参考

PyGithub
GithubAPIについて色々とまとめてみた
PyGithubを使って、GitHubの情報を取得してみた
Python 2.7 Error - ImportError: cannot import name Github

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0