This Python script allows you to download a public GitHub repository extremely quickly.
This function is the function that will download the repository.
This is required parameter.
It is basically the repository main zip URL, which can be obtained through the get_zip_link()
function (see below).
A required parameter.
This is the folder you want the repository to be placed in. It is just a string.
This is a non-required argument, which defines the files to delete after the download. By default, it will delete the ".gitattributes" file and the "README.md" file.
A non-required boolean (set to True
by default) which controls whether or not you want to enable the logging.
If True
, the notify_function()
(see below) will be called every time a log is required.
A non-required callback function. By default, the print method.
This argument is the name of the function to call when logging is wanted.
When called, the function will receive as first argument the logging string, followed by the other given positional arguments, and the other given keyword arguments.
This function is used to get the link of a repository main ZIP file, which will be returned as a string.
A required string. This is the username of the repository owner.
Another required string. This is the repository name.
A non-required string. This is the branch you want to download, by default the main
branch.
Simple repository download : The repository is megat69
's ACPL
, and we download the master
branch.
The downloaded repository will be stored in the ACPL
folder.
download_repo(get_zip_link("megat69", "ACPL", branch="master"), "ACPL")
The repository is megat69
's ACPL
, and we download the master
branch.
The downloaded repository will be stored in the ACPL
folder.
But in this case, we want the user to be capable to see the ".gitattributes" and "README.md" file, so we pass in an empty tuple to the files_to_delete
argument.
download_repo(get_zip_link("megat69", "ACPL", branch="master"), "ACPL", files_to_delete=tuple())
Background download : We don't want the user to see that we are downloading. Therefore, the log
parameter is set to False
.
The repository is megat69
's ACPL
, and we download the master
branch.
The downloaded repository will be stored in the ACPL
folder.
download_repo(get_zip_link("megat69", "ACPL", branch="master"), "ACPL", log=False)
GUI popup (tkinter) : We want the user to be notified through the GUI of our app.
The repository is megat69
's ACPL
, and we download the master
branch.
The downloaded repository will be stored in the ACPL
folder.
from repository_downloader import *
import tkinter as tk
window = tk.Tk()
window.geometry("500x500")
def notify(log_string:str):
"""
Notifies the user through the app GUI.
"""
notification = tk.Label(window, text=log_string).pack()
def download():
download_repo(get_zip_link("megat69", "ACPL", branch="master"), "ACPL", notify_function=notify)
window.after(16, download)
window.mainloop()