I am working on a project that relies on data from someone else's file on github. I have a python script that reads the file and extracts exactly what I need, and puts it into a file. Then my main program (in C++) reads from that file to get the information. However, I need a nice way of knowing when the github file updates, and when it does, I need the python script to run. I am willing to work with other languages but would prefer if I could stay with python. Thanks.
-
1You can use one of the ways mentioned here - https://stackoverflow.com/questions/19169787/github-file-change-notification to get notified of a change in the repo and use this as a trigger for your script. – gaganso Jul 12 '18 at 02:52
-
What do you mean by "when the Github file updates"? If you have a submodule and you are pulling in someone else's repo, you may be able to use [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) to execute your script when a pull succeeds. – Bailey Parker Jul 12 '18 at 02:53
1 Answers
For getting notifications on a repo in GitHub you can setup Git Hooks. If you don't have admin privileges you can use GitHub File Watcher which will send you an e-mail.
The solution I would use:
Create a job that would run lets say once in every hour. This will look at your specific file (find the file i the repo and click "raw" so you get a link like this: https://raw.githubusercontent.com/XXX/YYY/ZZZ/somefile.json
The job will fetch this file and create a hash for it - then check the hash from the previous run of the job - when the hash changes, your file has been changed.
Another solution could be that you crawl the file in the Github repo and find the latest commit id and check this against the commit id from the previous run...
Example:
https://github.com/Netflix/.../CassAstyanaxPlugin.java
This link has an unique class name commit-tease-sha
which you can use regex to find.
The whole element is:
<a class="commit-tease-sha" href="/Netflix/ndbench/commit/453697d62b1bb94f9f46299a931d04b3f77761a9" data-pjax="">453697d</a>
453697d62b1bb94f9f46299a931d04b3f77761a9
being what you check for is changed.
Hope this helps. Good luck :-)

- 365
- 1
- 4
- 8