4

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)
5
  • Simply check if a GET request returns a 404 or not? On GitHub the URL would be https://github.com/USER/PROJECT/blob/master/path/to/the/file Commented Apr 16, 2018 at 14:31
  • Well, and if not, it will download the file of course. :/ Commented Apr 16, 2018 at 14:32
  • 1
    Maybe look at GitHub's API. And if the file is very large, GitHub does not display it. Depends on what your size threshold is. Commented Apr 16, 2018 at 14:33
  • Ok. So I downloaded PyGithub but I can't found anywhere anything about even a directory. Commented Apr 16, 2018 at 14:56
  • 2
    In PyGitHub docs: pygithub.readthedocs.io/en/latest/github_objects/… and pygithub.readthedocs.io/en/latest/github_objects/…. Commented Apr 16, 2018 at 15:03

1 Answer 1

6

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("")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.