0

I have two csv files that update on a regular basis that supply data to Render for a dashboard. The entire process is automated except for pushing the new information to github, which I've been doing in the terminal. I need a script that automates this part too.

Using PyGithub documentation and several posts on this site, I've composed the following:

from github import Github

g = Github('token')
repo = g.get_user('name').get_repo('repo')

contents_h = repo.get_contents('src/history.csv')

his = '{full path}/src/history.csv'

with open(his, "r") as file:
    new_h = file.read()

repo.update_file(his, "updating file", new_h, contents_h.sha, branch='main')

It runs without errors, but the repository does not update. I suspect that I misunderstand some attribute, but changes haven't worked either.

What do I need to change?

AFTER EDIT (added , "r"): okay, now I am getting a file "does not match" error from the last line. So, I'm not sure what one of those parameters should be.

2
  • should '{full path}/src/history.csv' be an fstring? Commented Oct 2, 2023 at 16:43
  • @kojiro if it is an fstring, what format? Commented Oct 2, 2023 at 16:50

1 Answer 1

0

Okay, so it was simple once I had an error message. Changed the last line:

from github import Github

g = Github('token')
repo = g.get_user('name').get_repo('repo')

contents_h = repo.get_contents('src/history.csv')

his = '{full path}/src/history.csv'

with open(his, "r") as file:
    new_h = file.read()

repo.update_file(contents_h.path, "updating file", new_h, contents_h.sha)
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.