PyGitHub

Let's look at using the PyGitHub package, http://pygithub.readthedocs.io/en/latest/, to interact with GitHub repositories. The package is a wrapper around GitHub APIv3, https://developer.github.com/v3/

$ sudo pip install pygithub
$ sudo pip3 install pygithub

Let's use the Python shell to print out the user's current repository: 

$ python3
>>> from github import Github
>>> g = Github("ericchou1", "<password>")
>>> for repo in g.get_user().get_repos():
... print(repo.name)
...
ansible
...
-Hands-on-Network-Programming-with-Python
Mastering-Python-Networking
Mastering-Python-Networking-Second-Edition
>>>

For more programmatic access, we can also create more granular control using an access token. Github allows a token to be associated with the selected rights: 

GitHub token generation

The output is a bit different if you use the access token as the authentication mechanism: 

>>> from github import Github
>>> g = Github("<token>")
>>> for repo in g.get_user().get_repos():
... print(repo)
...
Repository(full_name="oreillymedia/distributed_denial_of_service_ddos")
Repository(full_name="PacktPublishing/-Hands-on-Network-Programming-with-Python")
Repository(full_name="PacktPublishing/Mastering-Python-Networking")
Repository(full_name="PacktPublishing/Mastering-Python-Networking-Second-Edition")
...

Now that we are familiar with Git, GitHub, and some of the Python packages, we can use them to work with the technology. We will take a look at some practical examples in the coming section. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.222.175