In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Python how to monitor Github project updates and automatically download, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
If you have your own local maintenance of an open source code base, you will know how troublesome it is to detect whether these libraries have been updated. With the increase of the library, the cost of manual maintenance becomes larger and larger. Hence the idea of this project: use Python to monitor the Github project for updates and, if so, download the update automatically!
1. Uniform file name format
To be able to get the update time of the project on github, we need to call an API of github:
Https://api.github.com/repos/ user name / library name
As you can see, this API consists of a user name / library name, so our file name should be based on it to facilitate the call of API. Since the file name cannot have a special symbol such as'/', we change it to underscore division. For example, when a FastText project calls API, it is:
Https://api.github.com/repos/facebookresearch/fastText
The file we saved is called facebookresearch_fastText.zip
In this way, it will be much more convenient to call API and download files.
two。 Get all the file names and the last modification time in the folder
In order to determine whether items on github are updated relative to local, we need to get the last modification time of each local file, so this is a dictionary relationship. The code is as follows:
3. Compare the update time with Githubs online project
First we need to get the time of the Githubs online project by calling the API we mentioned earlier. Second, be sure to format it as a 10-bit timestamp, because the time we get in the second step is also a 10-bit timestamp, which is very convenient to compare. Finally, when you return, you only need to return whether it needs to be updated. As shown in the figure.
The code is as follows:
4. If there is a project that needs to be updated, let it download automatically.
Since many github project file packages are quite large, we use streaming downloads here. If you have a lot of projects and you need to download them faster, please download them asynchronously in bulk. It's all in our previous article, and you can click to read it.
5. The whole process
We put the downloaded project files in the libs folder, and the automatically downloaded files in the new folder. The file structure is as follows:
F:\ pythondict\ pythondict-downloads\
│ superviser.py
│
├─ libs
│ facebookresearch_fastText.zip
│ facebookresearch_MUSE.zip
│
└─ new
The whole set of code is as follows, in order to prevent the guy who stole the article, forgive me for this is the format of the picture, if you need to copy the following link or click to read the original text to see this section:
Https://pythondict.com/download/python-watch-github-update-download/
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.