Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing github directory with python

Is there some kind of a web-request or something like that so I can list a directory in my github repository in python? I have to check for few files if they are there and they are pretty large so I don´t want to try to download them in my app. I have to just check if they are there.

The only way to do this that I found is to download the html file and then checking right in that file using BeautifulSoup. But this is not very elegant way to do so. In addition I have some troubles with installing BeautifulSoup package for python.

Right now I am using a txt file in which there are all the dlls listed. I run simple script before each commit that generates this text file.

EDIT: I found a solution with the help of PyGithub

from github import Github

g = Github("token")
for repo in g.search_repositories("XtremeUpdater"):
     for file in repo.get_contents("dir"):
          print(file.name)
like image 329
Jakub Bláha Avatar asked Oct 20 '25 21:10

Jakub Bláha


1 Answers

Using the get_dir_contents method worked for me:

import github
g = github.Github("USERNAME", "PASSWORD")
repo = g.get_user().get_repo( "REPO_NAME" )
print repo.get_dir_contents("")
like image 141
Iron Pillow Avatar answered Oct 22 '25 12:10

Iron Pillow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!